|
浮游
发表于 2015-8-25 11:30:57
|阅读模式
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:0 B' h- ~ N2 k
, x/ ~5 @3 C/ k+ w, X% Y* d& m# Cvoid Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools)6 V5 i+ j: K% E6 P
{
: h( T$ e6 Z+ S( ] if (m_pTextBuilder == NULL)
+ G3 `! {5 b4 |6 E# a$ k m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts);
% X& T: f( h$ F int i = 0;
/ m6 m/ Y+ F4 x# @" v
) C4 ]& o7 F3 N; J+ N9 f0 V m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);. ]$ t- {- X, O' n4 S
m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);- U1 X) W% H( g( o- @ y3 F
NXOpen::Features::TextBuilder::ScriptOptions characterSet;, P$ q( K! d% W P8 C6 t. r( \* F M
if (fontType[1] >= 'A'&&fontType[1] <= 'z')
+ W. J5 q( l ~& D8 K* t9 ~ characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;
! H7 N; u8 S' g- a else
; G5 \5 ?9 ^" H$ q9 r* L) i% U characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;* Y2 A" N' G- V6 N& ?0 o
i = 0;
W! f. H0 U; m. U8 V while (1) ^! ?; K1 U% F: p* n1 B
{5 a" |5 G4 n E& \' W
if (fontContent == 0) break;
/ Z+ ` b, b! X+ K! C& n if (fontContent & 0x80)
4 Y+ r! J, m# H8 A if (fontContent[i + 1] & 0x80)- D% w7 c- j: _, d4 l% J
if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312)2 H3 A$ e' g4 d
{
: \! E9 P5 M$ b6 z, _) ~ uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1); Y" U1 \. v" D( J( \
break;# n2 S# f& n9 j0 i1 A
}/ Y1 u: A* b/ J9 r9 o. d. M
i++;7 Q" Q; d+ A' x; U/ J7 B$ E
}9 M% U8 v) r# ?- F B
m_pTextBuilder->SetTextString(fontContent);
' y1 ]+ a9 L' a1 J- A' R m_pTextBuilder->SelectFont(fontType, characterSet);/ X8 R* Z# H' |1 {, @- k& W( F
m_pTextBuilder->SetCanUseKerningSpaces(true);9 G$ B' S% ]+ F5 w& ?$ J
m_pTextBuilder->SetCanReverseIntersectionCurve(true);
1 ?6 N/ _! x: V3 M& ~: m9 P) T% F; o5 Q/ b* j; ~9 y+ I
NXOpen: irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),
7 a* e8 a: l4 Q/ {3 ` Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8])),
* f0 }: h/ z* w SmartObject::UpdateOption::UpdateOptionWithinModeling);
5 i3 Y8 t, T. _6 i* ~; |! Q m_pTextBuilder->SetOrientationVector(orientationVector);
}( ~, i# G6 S0 h
( b; t+ |. v7 F9 u0 t5 t" Q! E m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);, Z/ A# S0 N. j$ o
m_pTextBuilder-> lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);5 z% n" ?5 a: H r5 G' T0 s: T5 k
& {) F+ H+ J9 h1 S% b g G i = strlen(fontContent);
1 S' |# r! O! h char buf[256] = { 0 };7 t. R& _9 d8 H. B% \( V4 b
sprintf(buf, "%f", i * 10 * (wScale / 50.0));; Y" s5 b# G @5 l# d2 v
m_pTextBuilder-> lanarFrame()->Length()->SetRightHandSide(buf);- H! R5 s5 ]/ B* v6 s+ Q
sprintf(buf, "%f", 10 * (wScale / 50.0));2 g$ o8 h6 t7 B9 f1 W
m_pTextBuilder-> lanarFrame()->Height()->SetRightHandSide(buf);& {7 w* X$ {* o" R, t0 G
m_pTextBuilder-> lanarFrame()->Shear()->SetRightHandSide("0");) R R1 ]: C2 ^8 L; v/ n q& C
8 i2 m' T4 a, r W( K/ S
m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);: T( ]3 |' ]& R
m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");
6 U# q/ l% J9 x2 G n3 q m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");3 E0 @( D! z# j2 B {1 `
m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");* O* d) _1 r3 G9 K0 d' H9 H
m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");% `9 W* d9 r5 ^1 t: e
f6 H2 _+ L- y. R* F! a std::vector<NXOpen::Face *> boundaryFaces2(0);
- W5 N" k! S. t( k) K NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);+ B% i9 D+ w6 i9 e3 w$ b- T1 d
std::vector<NXOpen::SelectionIntentRule *> rules2(1);( c9 |% K7 [' e- r6 _9 Q K; x
rules2[0] = faceTangentRule2;
L, {; u& A$ n m_pTextBuilder-> lacementFaces()->ReplaceRules(rules2, false);
/ a" B6 F2 ^1 I/ S- p+ A7 R8 ~" C' f7 y6 s% V% ~
m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);
1 A' j$ m1 L3 t) `1 ]- C9 s" p* h std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);, ~( T+ }2 H2 R3 D7 j M& g: _
CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);0 N# N+ W/ g$ S* X
NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1"));
( n" l$ @: F) Q0 V NXOpen::Curve *nullNXOpen_Curve(NULL);
& O# w/ |5 m% H6 `: a3 l std::vector<NXOpen::SelectionIntentRule *> rules(1);
( q& N/ P9 ^1 d# } rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);+ q7 T& _1 d! l" E- V# n
m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);: _& ~& v/ Z/ Q8 ?2 O
NXOpen::NXObject *nullNXOpen_NXObject(NULL);
% J, @! R2 I0 y! [ @& y3 ` NXOpen: oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);
/ N% t" t; \0 F3 E5 i k m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,& z; p2 s q' o4 i7 Z, u3 |( @
NXOpen::Section::ModeCreate, false);" w, Z2 k2 ?( L' b" {: Q2 {
* M; I: \# A- V: @ if (bools)
) V7 F n; I2 T! {( T+ _7 P {# d' i" A7 Q+ d) }+ Q' W
- ~& m3 t: Z. l; f3 N5 [ if (m_pTextBuilder->Validate()): \ x$ ]( `# v0 g% ]
{
! |7 o, k! l5 C J! ^ m_pTextObject = m_pTextBuilder->Commit();. @# D7 a2 N2 K( a
m_pTextBuilder->Destroy();
3 K- D& v3 }( h m_pTextBuilder = NULL;7 o. l/ p3 e4 E# ~* @: ]# _
changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);
! ]. l! H$ o! K) j changeStringContent->SetSensitivity(false);
0 u) Q$ s+ s( g1 X changeRealScale->SetSensitivity(false);! T% y8 ]0 N* Q
}6 ^6 E& L+ |, D0 _
+ h( O: w8 k" t& Q4 p# m+ I& h( G# j }- g) s" o; g1 k. \- h# ]
else5 ?- S# S: y- p+ X* o
{ . z3 X1 e/ _1 C7 |
// 3 L e/ f; R9 j) T" T, ~( P
if (m_pTextBuilder->Validate())
' \: c4 c& s' E( A# G" ~! s6 l, F {9 k. S( K {$ o+ |7 ~
m_pTextBuilder->Commit();
: `4 J- Z! I/ w' |# w; d UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible);# O6 ^; r5 E c5 u V8 o3 G
m_pTextBuilder->Destroy();. }. E2 a$ f0 N
m_pTextBuilder = NULL;, w& M/ F, ^# h
}
" C) F6 F4 F; V5 \ }
% A f5 v( ~: Z2 A4 B+ c / e) U% U, d& d
}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!
" H* A' H1 Y# j+ e4 z |
|