|
浮游
发表于 2015-8-25 11:30:57
|阅读模式
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:% |3 W* \% f: N! ]& R5 p# h
& e9 {4 s1 N$ Z# |, f# {
void Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools)) a7 S+ }4 f8 Q- P0 s! e& k9 r+ I
{
8 v" D2 U9 G1 A+ u* C. I0 T if (m_pTextBuilder == NULL)
u0 Y8 k% S2 W5 M' C. Q m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts);/ k7 _7 V( q+ [- I; k# A& s
int i = 0;
* h4 s, L$ j: F& Z
% w$ ^, H* `. w# X m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);# }2 x. k3 R$ }# `5 i$ e
m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);
: r0 R! O, Q) H3 \0 U NXOpen::Features::TextBuilder::ScriptOptions characterSet;) |- W- m# x: x7 ~; {
if (fontType[1] >= 'A'&&fontType[1] <= 'z')
" R T( C3 K& D( w1 k; x+ E characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;
# _! ]0 o0 |! F* H% T% j else9 ]" }* u: F/ i, F
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;5 O: I/ f$ e7 H( n5 Z
i = 0;' j: }! L9 m1 P7 R( p; U* {' z0 V! C
while (1)( Y) X3 W) Y: s. |( ]
{/ s# b1 K4 U8 M- {6 y% a
if (fontContent == 0) break;3 D: a" a, T% Q7 Q! x$ s
if (fontContent & 0x80)
0 X- ?2 y, a3 |' \3 x4 C8 ] } if (fontContent[i + 1] & 0x80)# l& s) d* o- f1 ?* Y7 Y
if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312)
" s" m, g1 A0 C9 p {7 w2 s. P' V' A. S& ^( E
uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1);. {! h2 ?& D4 x
break;6 A# J7 Y, W7 U+ `
}& N+ K5 ~/ @! C p$ S# g
i++;0 r# X' K3 K' V' d; p B
}/ p; O, i" q& T! ?
m_pTextBuilder->SetTextString(fontContent);6 F$ M3 Y% d. u- D# j
m_pTextBuilder->SelectFont(fontType, characterSet);
8 B1 @% T9 D' {/ o9 b m_pTextBuilder->SetCanUseKerningSpaces(true);4 z7 h6 J1 D3 U6 s" Q2 Q, y
m_pTextBuilder->SetCanReverseIntersectionCurve(true);/ Q$ B0 U+ d- _2 c- W8 `2 E3 y
" {" H0 Q% A: L, G3 Q NXOpen:irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),* B7 v Q1 n& r# \2 ?. @
Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8])),# Q7 H7 v* k' Y
SmartObject::UpdateOption::UpdateOptionWithinModeling);
5 x% S1 c$ Y& n, _. `# ] m_pTextBuilder->SetOrientationVector(orientationVector);' y2 P, ]( o9 s$ |# C( l9 w
* j/ I4 q: i2 ]/ j7 P m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);
6 {3 o/ q0 `% d1 e1 k m_pTextBuilder->lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);3 G; K8 H3 b8 O* ^- O* j) B
: w# b) l- y) ^& d9 Q/ q; n ] i = strlen(fontContent);/ h* A. Z9 L% A$ D! ~8 R0 b1 I' u
char buf[256] = { 0 };3 Q3 {3 J0 @% t. n0 W2 I2 k x
sprintf(buf, "%f", i * 10 * (wScale / 50.0));$ n' G3 c0 w4 I+ s
m_pTextBuilder->lanarFrame()->Length()->SetRightHandSide(buf);) m" Y* p7 O' y/ s7 h* d3 o
sprintf(buf, "%f", 10 * (wScale / 50.0));) K! w8 p0 y) M$ ~2 T1 s M9 b
m_pTextBuilder->lanarFrame()->Height()->SetRightHandSide(buf);9 [2 R% i Q$ J0 b6 g& i: m- m) y
m_pTextBuilder->lanarFrame()->Shear()->SetRightHandSide("0");9 u; ?: A5 k: k5 x6 } {
- O7 X3 X5 V. } m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);
( f. H, p& ]. B m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");) G' L5 \' z+ m4 X( y3 x
m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");
+ l+ q1 z* }2 H, U m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");
% R' n# i' i" b- _6 S2 n8 R. R. o: S m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");7 ]0 t. Z7 Y# U8 N5 o
1 c6 l1 j1 [+ C5 S) A! Q4 T std::vector<NXOpen::Face *> boundaryFaces2(0);0 s8 e9 I$ A" N% f: `: \6 F4 w
NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);
$ o6 F$ B) h4 z$ ?8 C- N6 z std::vector<NXOpen::SelectionIntentRule *> rules2(1);
7 y! e! q, U0 x, ~: p rules2[0] = faceTangentRule2;- @) K6 ~. ~+ h' b0 Z
m_pTextBuilder->lacementFaces()->ReplaceRules(rules2, false);
; j T: |0 n( b) D) I
3 J" M* w5 M: w* w l- M m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);
7 S$ C8 {" d0 R" o std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);8 k, ^6 c( v9 }7 T& `
CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);
" c2 ]0 \0 U/ Q- z: t NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1"));
! F- g0 N0 g8 ?% N$ Q3 N NXOpen::Curve *nullNXOpen_Curve(NULL);
) o2 z {' |' t1 d/ O: d std::vector<NXOpen::SelectionIntentRule *> rules(1);/ T- L1 I8 S* v/ S$ g
rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);
2 L/ t( H# o3 w7 `- E( P" M2 b m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);/ x/ @' ?8 y4 e T1 a
NXOpen::NXObject *nullNXOpen_NXObject(NULL);% u7 L6 p( U3 L* { q: D0 Z
NXOpen:oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);2 E) g4 n# i! j8 |3 w; t/ ]8 Q9 S
m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,
% R- }6 K- t' Y+ a: X: m0 n NXOpen::Section::ModeCreate, false);
8 L1 d% l8 [- b4 V+ i. r. U! O& B& Q4 l# L5 C+ p) o I
if (bools)
7 f: d+ k g9 ]. h+ A- s {* A W. @& i" @: D7 Y
5 |, A) c+ Y } if (m_pTextBuilder->Validate())
7 \ p" e4 e' k+ M& t, ~+ { {; R; W1 j; @4 U
m_pTextObject = m_pTextBuilder->Commit();
9 O8 o6 i' g* f0 L) T& c7 F( o m_pTextBuilder->Destroy();+ ]& n6 `$ w# a+ ]- q0 p: x7 L
m_pTextBuilder = NULL;
3 } `% u. P+ q- k, ?7 `4 k) G changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);
# ^/ b$ Z6 E* l. T. B changeStringContent->SetSensitivity(false);
q. q+ F0 C8 ?# T7 U' s changeRealScale->SetSensitivity(false);( |4 ?% G# }" b
}* H* n8 L" ~0 U# ?8 P
6 z( a) n2 l9 Q1 Q
}
" j0 u& [! ]. R else& ~; x2 H6 g$ A# S
{
/ {8 b8 ?0 W/ K7 k1 M7 y. k //
& y3 }7 ~- o! s% A& l) C if (m_pTextBuilder->Validate())
# y+ e( f4 P0 w( @" L {5 U5 f. j. A: [
m_pTextBuilder->Commit();
8 D8 V8 L+ \, b UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible);8 B2 A1 u* V" \$ o8 r# P
m_pTextBuilder->Destroy();
: @ r; B" e; X" r m_pTextBuilder = NULL;' x8 Y' j+ i3 ]; @9 b" b0 L* j3 [
}. E$ m4 L. W( N6 @6 n
} 2 T% j4 X' \4 n9 m& B
( b7 {9 x' x1 {4 ~$ k( Z}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!2 }+ i) n9 g& m% T
|
|