|
|
浮游
发表于 2015-8-25 11:30:57
|阅读模式
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:
6 ]; e' Z' j% s" ^& l' y- m
9 s. c6 v5 x0 S; v/ Vvoid Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools)1 y2 g9 p- Q( p% e
{6 Z/ P' t/ \8 t4 k, Y9 e- d
if (m_pTextBuilder == NULL)
7 E9 y$ ^. m5 i `2 z) u m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts);( P2 ]! v% G2 m9 s
int i = 0;8 X* ^' w; E5 b3 H
8 d* @% z: E: _% b) m3 |, e
m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);; t/ z8 n/ ~4 n% V+ o
m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);
6 n2 a1 q& P' `# I7 m7 q5 `2 @4 G, } NXOpen::Features::TextBuilder::ScriptOptions characterSet;% u- J; A0 A" O3 q+ x
if (fontType[1] >= 'A'&&fontType[1] <= 'z')9 `+ n7 B2 B. B) u+ z) [
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;
& f s5 L- ~/ p0 B9 K: T else0 e7 W/ {; F: u
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;
& J' G2 C/ v/ E i = 0;' y1 [- a) Q6 c/ O0 j$ ]+ T/ k
while (1)
8 u7 [, V3 c% w0 L {
( X! x2 i0 k& K# E% z4 F% q, g if (fontContent == 0) break;# T% U( r3 s+ y' Q
if (fontContent & 0x80)
$ O, |! _: W) T, s Q% Q: m if (fontContent[i + 1] & 0x80)
" Q% O8 B/ K/ K& {5 [) B3 _* ?0 [) G if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312)
( c- G% O* q4 w. Y$ M& W4 Q {! F3 P" I6 n( G% C
uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1);
5 C* X, D, G0 o2 s" F2 I break;4 G4 n- r+ n. Z) s* L" h
}
9 j( w5 t f3 [# Q4 a; Q i++;
9 b& H' e6 Q+ M/ N. b; `2 r5 @; m. v }
3 l! A3 v% W* d* b) B m_pTextBuilder->SetTextString(fontContent);
/ i4 x3 |) r7 s. q& A; ] m_pTextBuilder->SelectFont(fontType, characterSet);
# |# g7 |3 `& N9 o+ B3 K0 I4 R. _ m_pTextBuilder->SetCanUseKerningSpaces(true);: j8 L# e; Q2 w# N4 P- Y
m_pTextBuilder->SetCanReverseIntersectionCurve(true);
, `* Q6 @/ d3 X0 J- I
9 r0 G* R) H3 h1 d: s: p" T ]1 ?2 `/ x NXOpen: irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),
) w* {6 h1 y1 ^4 l Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8])),
5 E1 Q% w7 ^2 u- W5 r* Z SmartObject::UpdateOption::UpdateOptionWithinModeling);; o' R1 i9 ]6 O$ K4 N
m_pTextBuilder->SetOrientationVector(orientationVector);6 q8 i9 y. @$ G! A V8 b
% A W. z8 j. d$ q2 U m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);$ p9 l$ L6 }* Y: g# Y* R
m_pTextBuilder-> lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);
* ?# a: D. e# e. A8 l. f( L
! c' g/ n1 F7 ?% _+ y i = strlen(fontContent);
; ?" E# e- \' z( k/ u7 E0 } char buf[256] = { 0 };
% d6 f2 c9 c3 n7 }; r$ Y B sprintf(buf, "%f", i * 10 * (wScale / 50.0));. a6 o9 \8 U8 G/ L% b+ H8 H
m_pTextBuilder-> lanarFrame()->Length()->SetRightHandSide(buf);
0 C6 [4 x! ^) q# [ sprintf(buf, "%f", 10 * (wScale / 50.0));
& r3 W2 [7 t/ o" y2 M: F# P0 d m_pTextBuilder-> lanarFrame()->Height()->SetRightHandSide(buf);
2 I$ K }) k% L( X* N+ }* O" A m_pTextBuilder-> lanarFrame()->Shear()->SetRightHandSide("0");8 y# w; l; Q( r0 t1 Y- s7 Y9 B
+ `, T7 X) u3 y3 c m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);
# b- L4 ^ c0 H$ R( a! R3 [ m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");
7 Z3 W8 D, v# X r: a ` m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");
- g/ ` p6 R& i+ t# g8 W m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");
0 o4 O4 g: [" Z4 U. I( T) J, V m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");
) g G$ A" j$ O: Y! k0 k4 U/ x! \
std::vector<NXOpen::Face *> boundaryFaces2(0);
# y3 S$ N0 ~7 H1 }5 y0 H7 T NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);( h% J% C) J- K( S- ?: ^/ M/ z
std::vector<NXOpen::SelectionIntentRule *> rules2(1);
8 d* ^8 s, p8 T6 L6 ? rules2[0] = faceTangentRule2;
" O' ^/ \- {- _7 n m_pTextBuilder-> lacementFaces()->ReplaceRules(rules2, false);
1 s s& Q# S0 D( [6 Y y* m3 _* H9 ~
d% @1 o% u+ F7 j m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);
( Z7 n8 x; h' ~2 _ std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);; V: k: n4 _% [+ h: N3 Y& h
CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);$ l" h8 ?" O( W( a6 P8 n
NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1"));
+ b2 }$ ^' x& k* e/ A NXOpen::Curve *nullNXOpen_Curve(NULL);- }5 u0 ^) F) r p0 _- s3 Q
std::vector<NXOpen::SelectionIntentRule *> rules(1);+ |- |8 t/ {5 b4 ^% i
rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);! `0 l, t/ W% L& y3 p
m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);
- A3 c( ~ |9 T4 k- i) p NXOpen::NXObject *nullNXOpen_NXObject(NULL);6 w' g$ s, C) S# T5 @
NXOpen: oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);7 w) C6 [6 N" }
m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,) Z5 }6 `/ y3 G
NXOpen::Section::ModeCreate, false);/ b- s h& L- r; |
2 x# P8 D% ]8 H& Z& A8 I
if (bools)# z' D( o2 X1 Z1 ?7 I/ m
{
# D6 g; A1 t" v' b* D- _8 s
/ e9 j2 T1 s4 g& {8 Q4 Q if (m_pTextBuilder->Validate())
* p u: u: c' l) F0 h4 E { n- }0 d( k$ H* q" c8 K" x
m_pTextObject = m_pTextBuilder->Commit();3 e$ L2 E' e0 _5 K
m_pTextBuilder->Destroy();9 B! V2 y8 ^8 Y5 i
m_pTextBuilder = NULL;
8 I8 N7 ]* j2 I1 f; Q changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);
& n5 L1 F5 N, E7 {3 w/ E changeStringContent->SetSensitivity(false);
( S3 J. h# j* N+ F! o changeRealScale->SetSensitivity(false);; r0 I+ u! K' h& f
}' M1 w: L% G8 k' F0 h3 J. L
1 E# L2 q5 c9 c0 z8 S }# `% |; M6 s$ g+ l: F4 ^( Y
else
$ H2 W$ \! {- o/ {8 h. S3 e { 2 p4 d5 c7 }$ B# P. q1 \6 u
//
5 W& J0 ~+ {( [ if (m_pTextBuilder->Validate())
. n3 |, ^& k4 x0 P2 a+ o% {: d3 g {
! h# Y% v0 b$ e z8 e9 F* T m_pTextBuilder->Commit();: o4 L, s7 i [
UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible);
1 \& N; }$ _ v. t m_pTextBuilder->Destroy();; B0 Z7 W* f w7 y8 n
m_pTextBuilder = NULL;
5 [* R8 y0 r/ {2 E8 C! j- z }
$ D9 f8 C) k3 Y: q; x. F } - Z9 A/ U# B& l& G
f& V$ r' x3 h) I
}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!' P* I( b! F8 r$ \! b, V% a* `' }
|
|