|
浮游
发表于 2015-8-25 11:30:57
|阅读模式
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:
4 _+ A, n0 k/ |9 f0 a# Z- I# { V
5 D0 i% F4 w, J( c. yvoid Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools); W% v; b# v* e2 ]* K. s; Y
{) Z1 u2 q- ?% w* d0 m
if (m_pTextBuilder == NULL)
9 P, ] A# y* B- u* w m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts);: |; }% e& N8 J6 \0 z( H# g Y
int i = 0;
$ B. T {0 \; R6 e2 d% p1 Y" k/ O; U6 L* U& \6 e
m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);- K2 K3 U* y; c3 f8 T* h
m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);
6 [, |. A4 p( C; I) }5 A3 s5 s NXOpen::Features::TextBuilder::ScriptOptions characterSet;
' `! \: y/ m* M) V* G0 R' t if (fontType[1] >= 'A'&&fontType[1] <= 'z')
2 r1 K1 G+ l) I( [ characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;
# E2 P0 [2 h; |* ?8 ?) L. H else
+ @" W J$ v0 c6 T0 b characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;2 f d7 v: u/ [! I' ~; h0 T q
i = 0;4 X( }1 K4 z, {" y7 V
while (1)
, q5 \' m6 |1 J) e* Z9 P; u {2 h2 w9 r5 l# V: N
if (fontContent == 0) break;- K3 d" ~& p' V
if (fontContent & 0x80)0 x7 _/ f0 a) U/ a
if (fontContent[i + 1] & 0x80)
: f8 |/ x7 b" H1 d# @1 D- \: Q if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312)4 s1 c2 N/ a( ?
{7 v4 Y+ x+ O, R3 @8 U
uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1);7 V* ~) D, B' n6 A3 v3 L9 e
break;
' N0 f+ |& h' y: `0 @: B& s! h" { }/ b5 I* G; m: ^2 j* J
i++;) \. o( L8 m$ L! G" y
}
0 ~, E; G3 p3 U4 j, d) s m_pTextBuilder->SetTextString(fontContent);8 u* b$ ]- s2 |2 ?; w9 i
m_pTextBuilder->SelectFont(fontType, characterSet);- h3 s; n/ G3 @; y. R( T* O
m_pTextBuilder->SetCanUseKerningSpaces(true);
' n5 D1 I# |/ Q m_pTextBuilder->SetCanReverseIntersectionCurve(true);
5 Q1 ]" t5 U8 f' S3 t
8 ~& |$ A1 I, @( M& K- h NXOpen: irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),& d% X0 U5 s3 Y
Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8])),
; I7 W0 ^6 _$ k SmartObject::UpdateOption::UpdateOptionWithinModeling);
9 O7 ?* @- c% B6 f2 [ m_pTextBuilder->SetOrientationVector(orientationVector);
% I9 S6 U: t9 p+ Z* O# s5 u" @7 w
" b$ [9 j& L% q# X6 R% D; C m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);
" i, Y' w' L4 o" w6 B m_pTextBuilder-> lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);
& u6 y$ ]4 Q; {8 r- I6 q% s+ p+ C% ^8 o# I* S' D) V- r
i = strlen(fontContent);" d7 \1 K* u" J0 q
char buf[256] = { 0 };* }, M2 R1 R& p- g9 C6 U) T
sprintf(buf, "%f", i * 10 * (wScale / 50.0));
' K+ q4 c. ]$ k m_pTextBuilder-> lanarFrame()->Length()->SetRightHandSide(buf);
4 y( H$ [' k d. e; Z; G sprintf(buf, "%f", 10 * (wScale / 50.0));' `1 I8 B* T" ^- |# F# U
m_pTextBuilder-> lanarFrame()->Height()->SetRightHandSide(buf);
# k8 n5 e% o1 ^5 ? m_pTextBuilder-> lanarFrame()->Shear()->SetRightHandSide("0");
' |# ~8 q) r9 I0 h. L& A, ^$ h& `, q) Q( r
m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);
. C' ?7 p+ ?+ @& J9 d5 H m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");
* Q, p% i1 `# \1 b4 o) o& o- D m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");& n2 F, f$ J* A& c$ `* P
m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");
; h |# ~: c* P" N; R m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");9 b* `( K, K3 l, d
3 L" h$ b6 `# s: @2 i0 _, n std::vector<NXOpen::Face *> boundaryFaces2(0);. j* a9 O5 B0 a5 l4 R
NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);
8 D. ?3 m8 _2 r2 H/ q! L std::vector<NXOpen::SelectionIntentRule *> rules2(1);- ^5 U8 u( f f2 \, ~& h
rules2[0] = faceTangentRule2;8 k0 [) {* k; S* n& M
m_pTextBuilder-> lacementFaces()->ReplaceRules(rules2, false);
& v' H1 T8 e+ f
: G6 S! S' w) M& `6 L* c: Z m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);
( m# T, f) X8 t, P& l; y std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);
* ^, ]8 p' a, V* d CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);% x, c. X! n" B) c4 h6 r
NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1")); p7 e0 H; P$ `5 S$ L; i* g1 H
NXOpen::Curve *nullNXOpen_Curve(NULL);5 o% x, @3 ~/ L) ~: t
std::vector<NXOpen::SelectionIntentRule *> rules(1);
& {8 x8 x2 m0 w- c rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);: }1 v: l. l9 _) w. t. k J
m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);
4 M4 `% K5 I: o8 l NXOpen::NXObject *nullNXOpen_NXObject(NULL);3 |' V8 @, F+ s8 S! p ^! L/ K
NXOpen: oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);* K7 D# c# f) O- ^4 {( \3 U! z# K
m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,5 S! K6 i0 c$ E( ?4 }6 D0 f5 b
NXOpen::Section::ModeCreate, false);1 p' T! l) n/ R# l1 |
3 s) d7 D: @, `' N+ k) C
if (bools)# l+ h! q6 l% v6 z
{+ D$ W3 b1 X) ?
* n+ w' d, o) @. r1 y& B
if (m_pTextBuilder->Validate())
# l0 f! @0 v$ K! l3 x8 H {5 Y* h0 v/ h2 o# V: j+ X4 m% u
m_pTextObject = m_pTextBuilder->Commit();
% ~8 ?1 Z1 K7 U. @" b* z m_pTextBuilder->Destroy();7 r- ?8 ^( Y7 g9 Q9 M& y& `) f
m_pTextBuilder = NULL;+ o. h% G, [5 v% o, D7 ~( q
changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);
, k, a, B1 Q/ }" T$ W changeStringContent->SetSensitivity(false);& F1 t/ ~, N( h, q7 p! d$ @
changeRealScale->SetSensitivity(false);, e! O+ ^, \2 F8 R1 z; j! k+ ?
} G/ O' u4 p4 S& G% O+ X+ d# ?
; M& o- U# f8 N9 e6 S }
& B( h9 ?1 O" ~7 H else" f$ J9 Q/ Y- X* R9 Q. }( d4 z
{
$ S2 _4 n* u: s% H //
& h: l, I: W% j w if (m_pTextBuilder->Validate())
0 X% x; j7 T% y8 ^1 X {% d8 g4 [2 d) Z g# i+ G& U$ f, `# T
m_pTextBuilder->Commit();
! o8 s) m J# _. F+ n UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible);
4 D0 e4 H3 L- j. x5 O m_pTextBuilder->Destroy();
& n' i" Q% ^$ i1 p m_pTextBuilder = NULL;' x9 \( A( e5 S2 z P+ M
}
/ \: o( H3 w Q7 _3 s }
- N3 k5 h: F* }) d " D# G0 F0 a/ V! Z. ~/ N: b% E4 Y9 h
}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!
- E- X/ s- e+ F9 q- _ |
|