|
浮游
发表于 2015-8-25 11:30:57
|阅读模式
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:0 Z$ h% w: {8 c8 N3 H
; I" Z* U+ a$ h+ z+ avoid Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools); d7 {7 Z: Y# X: ^
{
: F! ~4 |9 z9 e: N* c- ~* B if (m_pTextBuilder == NULL)
% a# c9 G: d* m( K m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts);: }" Z) D6 b! ^
int i = 0;0 C+ r/ J3 l }" X* ~, _
6 B2 r2 s/ Y3 _1 n
m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);
8 o* ~% S( [8 D; A3 w5 J" l1 u# U m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);3 e" A( T7 ^' C* D7 P: J/ u- P4 E
NXOpen::Features::TextBuilder::ScriptOptions characterSet;5 y1 D" T0 r6 z, h
if (fontType[1] >= 'A'&&fontType[1] <= 'z') z# A, b. n9 Z# W; x" n
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;" }6 u! W4 {$ ^) u" B$ [8 f
else
- x* ]+ R& p7 [% G/ ^5 J characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;
4 | Y) F. c9 s. X5 a" ~$ { i = 0;
+ z' C# t# u* i; Z while (1)1 i7 l+ g' e5 o3 P
{
' L" X8 l7 d f2 @" y if (fontContent == 0) break;9 _* O; r1 o7 S& D- h# y
if (fontContent & 0x80)9 @2 n$ }4 G2 s' [
if (fontContent[i + 1] & 0x80) v9 `5 X8 J+ t& R( M% C
if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312)
3 D) F* q, W; y- {4 k3 a4 W# ~, | {% ]1 J K6 q. Q% K
uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1);
( I4 \: y5 }" d& P- t3 `: \, O break;
& \5 n7 W( D4 p( j9 e" r5 R- Y3 }. z }
/ @, u w0 }# r% w( K$ @" p3 }' A i++;
& i5 J- p' s/ T; L8 R0 P }5 t6 l( }( D& I7 O7 z+ `. u
m_pTextBuilder->SetTextString(fontContent);6 m: O" q" [9 M L' J
m_pTextBuilder->SelectFont(fontType, characterSet);
' v2 e: X5 A% N m_pTextBuilder->SetCanUseKerningSpaces(true);& O+ Q6 H8 K1 D+ q! w/ O
m_pTextBuilder->SetCanReverseIntersectionCurve(true);7 [& _: L+ z, t, m; c
0 Q: F+ ]) z3 N; R f- Y" o NXOpen: irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),/ G, G- i, J* }6 f9 e5 A7 @
Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8])),9 H3 V( c# @. D$ u5 f4 ]/ a& n
SmartObject::UpdateOption::UpdateOptionWithinModeling);; B" t' k6 l( c) I. z! I3 w! N& z
m_pTextBuilder->SetOrientationVector(orientationVector);
9 ^$ s/ i) p4 }0 u+ z, D. }, U" G# m! M9 |
m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);& [+ N& R9 o4 O5 B
m_pTextBuilder-> lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);
' R0 r1 A: q2 Z1 s6 Z; w2 m) ~" Y3 Y" H
i = strlen(fontContent);( `; ]6 N0 a5 E. S/ X, V/ A) Z( n
char buf[256] = { 0 };
& U/ j- c5 V8 e: B) ]$ g; ~ sprintf(buf, "%f", i * 10 * (wScale / 50.0));
- Z" u3 z: w, [ {( t m_pTextBuilder-> lanarFrame()->Length()->SetRightHandSide(buf);
) I* @& Z }/ w8 K/ c" N5 W sprintf(buf, "%f", 10 * (wScale / 50.0));
( p C& T. L' a% A m_pTextBuilder-> lanarFrame()->Height()->SetRightHandSide(buf);
# s8 F' k- h& h m_pTextBuilder-> lanarFrame()->Shear()->SetRightHandSide("0");
" y- b5 M; Z4 A' q) \
- S9 F$ ^5 I( @: r( N/ J m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);
( D8 `) y4 j4 G m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");
1 ~9 `% y Q% a# v y, i+ t! i m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");9 Y, f& L2 K G0 A5 m
m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");& ?# Y7 K8 C: A1 p( T* V% }; F
m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");! Z! [* M, c/ L) w
, r3 e0 }" o" C7 W% ~3 A' | std::vector<NXOpen::Face *> boundaryFaces2(0);1 K [2 c9 I9 w+ R) v; x- B* a
NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);
O+ n e( y2 @+ `* p% Q5 f! [2 n std::vector<NXOpen::SelectionIntentRule *> rules2(1);4 [. l8 U5 k5 L
rules2[0] = faceTangentRule2;* M6 f7 }. k# z& z1 |7 O' z7 @: e
m_pTextBuilder-> lacementFaces()->ReplaceRules(rules2, false);
0 {& v) L6 }, w9 W+ K0 @; R/ j; D* S8 T, S: I: l
m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);
; n0 h1 r& b6 F s* l5 q0 {2 J* x std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);
4 V$ ~7 j- O: ~5 q" E5 K CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);; j% e: U- p! K3 I3 \
NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1"));( W6 h! H, @1 y C6 y8 j% G
NXOpen::Curve *nullNXOpen_Curve(NULL);5 b1 J V& U- ^, ^
std::vector<NXOpen::SelectionIntentRule *> rules(1);) X& h f( s& r/ n4 x3 |- i0 C
rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);2 q! F+ w/ a; ~6 a! \
m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);
; c/ o: g# P/ Z: |' H NXOpen::NXObject *nullNXOpen_NXObject(NULL);
5 Y4 m. @" l$ M' F: Z) u NXOpen: oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);
6 G, j3 k j# J5 S A m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,0 U+ f1 A( R% y6 G
NXOpen::Section::ModeCreate, false);
* H, g8 Y7 M# w4 I$ K* C- a- ~% K l& I0 [' {1 \, I' s3 X
if (bools)+ U$ l& U/ l( |. V2 ~
{( M& M! v9 `' e8 l
) f/ Y: C7 J/ n8 R if (m_pTextBuilder->Validate())4 ], J" e* a# ]' ^# D
{" k* b' r% g+ o# _( {- f
m_pTextObject = m_pTextBuilder->Commit();
8 m' q: m3 m7 u: u9 N6 S m_pTextBuilder->Destroy();9 z+ @2 K! z! E7 y* {
m_pTextBuilder = NULL;" M3 }2 a4 j; V, D
changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);
! X( \ B' y4 w: ^2 d# l7 ~ changeStringContent->SetSensitivity(false);
' O, r1 a5 F+ J% V changeRealScale->SetSensitivity(false);
2 d7 } I7 S5 g+ w9 v6 v$ g }/ d- `" I2 s) S: o1 Q8 ]( n) s
' I( \/ b* G) |* c! c( Y0 y
}5 a! p9 p( h9 {! L8 d
else v. B# ~# c q2 r! P: ^, Z8 m5 T" j
{
' V4 g! l! ^6 w t4 ]% D% n //
8 V, H' r( V+ ` g if (m_pTextBuilder->Validate())2 S7 k6 Z l3 S9 R
{; L0 _- ?' L4 A+ K" l3 ~ g
m_pTextBuilder->Commit();
9 N, R& W2 \4 z8 Q7 A* W UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible);4 S1 ^2 ^3 J' n# ~* I
m_pTextBuilder->Destroy();
+ C0 T9 L9 c* T7 ~- y5 W m_pTextBuilder = NULL;
0 H5 d& F1 s2 X" g8 z/ V) {5 v }$ X j7 z, \" Q# _" Z4 V) S% p
}
1 l' h% ~3 d# u+ F6 Z ) ~+ X8 d9 G4 v
}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!
2 N7 n: I& w+ M2 Z8 G) B7 w | |
|