|
浮游
发表于 2015-8-25 11:30:57
|阅读模式
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:
' |' p- @1 c! m) L5 n3 ?4 |, [0 w' m
void Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools)
5 h5 N% G1 J/ G{1 w1 }1 Q4 E) }: G6 v- i0 K
if (m_pTextBuilder == NULL)
7 [* Z; j- }) N) l1 ? m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts);
7 O0 z% h4 ]6 V2 R int i = 0;
. s5 x# E8 t+ D# x4 U/ S) R* Y7 v! f! E+ m! }& j5 [
m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);
& U0 ^, e% X1 |! b/ ^# o" L9 o m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);. k/ J- z( R+ t! ` m) I
NXOpen::Features::TextBuilder::ScriptOptions characterSet;
4 j, M: o0 O, P v3 H if (fontType[1] >= 'A'&&fontType[1] <= 'z')
+ o, f* }) b3 {7 U+ _' u. c characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;* L1 F5 ]% u, e: D+ t' p
else) J+ S$ i' A/ w H+ x8 x: _; V0 O
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;$ c) [3 X, x2 j+ r# x
i = 0;3 I! G. n. ?/ ^
while (1)
( J3 q9 Y3 W: q i l" i. _3 u {
* M8 E; I" m0 M' p/ Q$ h if (fontContent == 0) break;
2 ~* t* t8 ] O" ^$ m1 ? if (fontContent & 0x80)
% J" M! w+ K5 W' U: H) x if (fontContent[i + 1] & 0x80)
9 I. {- z" _& n if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312)7 L* O$ `/ z! G, B$ n
{3 W$ v3 E' o- s; [( ?
uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1);
; m1 ^ j- F) D/ b break;, y* b5 r# F8 V& o8 J g8 \8 Z
}1 F$ N: @( q! f$ ^
i++;3 }% A. {2 ?. J3 L* y j
}
- Z! D( x/ h I m_pTextBuilder->SetTextString(fontContent);1 ?& ?6 w3 M) Q( I" Y5 i
m_pTextBuilder->SelectFont(fontType, characterSet);
% b+ C# N& {4 @; ?! N0 X m_pTextBuilder->SetCanUseKerningSpaces(true);1 Q2 A* M/ l5 m5 r# }) x/ |
m_pTextBuilder->SetCanReverseIntersectionCurve(true);, @% K8 x$ w% X3 x' o2 H/ q( o. V: z8 z. Z
- M: D# ^- G' z NXOpen: irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),/ m' ]6 J7 {7 K( J3 h2 q2 t
Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8])),. F: D$ ^& N- N+ P/ Z
SmartObject::UpdateOption::UpdateOptionWithinModeling);& W/ P& r' M, }- p. v4 V3 t
m_pTextBuilder->SetOrientationVector(orientationVector);1 c0 }$ Y5 t8 j# `& C
" V. N. U9 Q, s m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);
, w% z. Q3 v- S7 t2 r! h m_pTextBuilder-> lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);
1 I& @* z5 r4 ?* }8 q; a2 }% y6 l [6 l- V$ c! k2 }
i = strlen(fontContent);
* p% P- F) `9 a' f3 S1 `8 E char buf[256] = { 0 }; a7 B/ X7 d( r! |8 c2 P- ~3 z
sprintf(buf, "%f", i * 10 * (wScale / 50.0));
, a/ g. ]4 S4 j+ K6 x m_pTextBuilder-> lanarFrame()->Length()->SetRightHandSide(buf);$ K' u8 {3 Z% ?# O$ K
sprintf(buf, "%f", 10 * (wScale / 50.0));7 y% M4 \5 o0 B: n+ k
m_pTextBuilder-> lanarFrame()->Height()->SetRightHandSide(buf);0 S3 U* n+ S2 c" s z- [! D% b
m_pTextBuilder-> lanarFrame()->Shear()->SetRightHandSide("0");
* {( u9 z) Y- H! E: T& W# e
' q. m3 G2 I3 o, M m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);, ^5 {* \; i/ S* t+ \$ g
m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");
, e3 Q4 y* H# t; e m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");
7 W7 F8 N9 `, _, a* ^, O- x6 |1 S m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");
8 ^0 Y+ @0 q" r. A5 \( C2 u- { m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");
8 b+ A2 w( J1 ? u$ Z+ y; ?. V; ^+ n( ~
std::vector<NXOpen::Face *> boundaryFaces2(0);
+ s! T E, R, I# m: R/ ? Q, C3 e NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);0 ~/ s7 `: U% n* ?' ~
std::vector<NXOpen::SelectionIntentRule *> rules2(1);5 Z2 o3 U- Y$ ]2 c
rules2[0] = faceTangentRule2;$ m) ?4 J/ {6 ~2 E! } ^
m_pTextBuilder-> lacementFaces()->ReplaceRules(rules2, false);
9 J4 a* G F2 j I' k$ g- T' ^: E c
m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);: L2 P" k5 V/ Y/ A5 S6 g" h% b
std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);
, Z2 _4 e, v$ i, b: X8 ?0 V CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);" [% }) t$ }6 m& ]% \, I' A. ^6 F
NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1"));
8 Q4 F3 r( c1 Y8 \* }4 m) }$ C NXOpen::Curve *nullNXOpen_Curve(NULL);+ k0 N! K$ C- m% r/ Q; [' ^
std::vector<NXOpen::SelectionIntentRule *> rules(1);% m- f$ S3 ?2 r0 D% w' ~3 ^9 Z
rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);3 O$ y% g8 o9 o' M. N9 O* V# V
m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);5 k- r+ C& n6 G" o8 N" C& L$ j
NXOpen::NXObject *nullNXOpen_NXObject(NULL);5 U$ G8 q! r$ @3 n5 |! u3 S& s
NXOpen: oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);
P# l, f6 J' F* [+ Z j6 r- W m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,
) V. h4 u* d+ h; P- \1 B NXOpen::Section::ModeCreate, false);
/ p" ?) A; Z: v' {- B
3 ^5 L- _4 Q' C if (bools)
0 O& v4 z( k0 ?! Y/ L: Q) @ {- B' ~! ]3 o l, w0 r, V% L& n
3 j% _! p8 C* u, E/ F/ ~
if (m_pTextBuilder->Validate()). i& l3 ~/ ?3 L+ x1 X- l. A
{% ?: u# l' Q7 u$ q' y2 V
m_pTextObject = m_pTextBuilder->Commit();$ ]+ i, |' v2 f( [! D! B
m_pTextBuilder->Destroy();: c% E* r2 K( O6 @" ?+ d
m_pTextBuilder = NULL;( ~) i. l: ~3 @( q: _. C
changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);
+ F1 v# I2 p; D; E6 I/ q0 Y changeStringContent->SetSensitivity(false);
# z$ o& d% B( R4 i changeRealScale->SetSensitivity(false);
3 d7 Z. T( f( g }
2 Y, f, L% A- K2 L+ c" W8 m3 x % h5 c8 K" R; w/ E
}
) L" b$ r* L' L8 ?9 x5 s& o else
' |5 ]4 Q4 b8 D ?$ l { * n P9 j2 z$ U8 A, _% S
// & h' A1 ?7 Z1 i: ~4 g+ g
if (m_pTextBuilder->Validate())7 J0 O+ f) O4 q, t( m: d
{
5 o c9 V) L; L* i3 J m_pTextBuilder->Commit();
: z1 \0 z/ ?0 s s: l5 |- o) ^# g/ v UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible);2 p( v# l: x s
m_pTextBuilder->Destroy();
R P& b; t6 v/ f8 n6 u" j4 t m_pTextBuilder = NULL;3 q! k- U b: G7 A$ S3 G" x' {
}
$ Z$ a& O% O6 K2 V$ z* z/ y* o } 0 D8 `, m+ T' s# I5 Y, x
0 `9 p: X+ I, k
}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!
( w$ @6 G0 f; M9 C8 {" t* T |
|