|
浮游
发表于 2015-8-25 11:30:57
|阅读模式
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:
2 t* |# i2 H) e- w
% W9 q- ^7 J* O. u; J* R0 h6 dvoid Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools)/ b+ M+ f5 }5 P `& u: R# g) f
{
5 P$ h* O! v0 c, T2 p if (m_pTextBuilder == NULL). A3 v& t( ?$ C0 b
m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts);' o6 Q2 a7 c, x+ F# K% H
int i = 0;
% \8 O8 _7 p! ~0 \- n3 Z! h/ g, i) U9 E* P
m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);6 F- J" o; e; f
m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);" p+ h" N" U9 D6 Z
NXOpen::Features::TextBuilder::ScriptOptions characterSet;
% }! _8 L5 e. n; i. x6 b if (fontType[1] >= 'A'&&fontType[1] <= 'z')4 |9 f( N5 A0 F/ u2 e0 b, I7 u9 p% ~' @
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;% p" H s$ T2 Y# N+ J |( ]2 t
else
K0 C" o& Z/ [ characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;& S, s% y2 w- f8 {5 ~" A
i = 0;
1 n) R1 x4 K7 X- B6 h$ l while (1)+ Q% d K: k' F% m% n: E. A
{
% q& c+ Y5 A4 f: S if (fontContent == 0) break;
4 B4 K' g% i) w g7 l* ]! W" w if (fontContent & 0x80)5 Q; v+ z- I' b; ^( r: ^. _- E3 d
if (fontContent[i + 1] & 0x80)& t* I) s1 a9 N/ P! Q+ ?/ l
if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312)
4 U, u( G0 r: q- I$ R1 d {
5 P6 z) k; U- I5 f uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1);
% _: d8 ~, `9 ] break;) g3 N1 T/ e$ Y/ N# a' V
}6 D) Q+ F4 t$ g0 m2 U5 V
i++;/ A9 U% O' L9 V5 C7 q
}
. ?$ ^; e% J! W. C; W( b m_pTextBuilder->SetTextString(fontContent);
( `8 v0 N( Y* l9 _. L m_pTextBuilder->SelectFont(fontType, characterSet);8 C: w6 B$ y$ v r6 t6 I
m_pTextBuilder->SetCanUseKerningSpaces(true);
+ [) S# `: ~ v( y7 L m_pTextBuilder->SetCanReverseIntersectionCurve(true);
: M7 ~$ a! h6 O
% V( I' ~: L ]* m% { NXOpen: irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),
+ d3 \7 I! n" c) }$ t T Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8])),
. Q! b' Y i( {9 M! G1 ~9 f @ SmartObject::UpdateOption::UpdateOptionWithinModeling);+ s C2 g% @: i$ u1 ]
m_pTextBuilder->SetOrientationVector(orientationVector);- V+ P. O) Z4 _
- y% g3 q6 q4 r: f M m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);
& `* @6 O0 Q% `. c9 _- t m_pTextBuilder-> lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);
" u8 W- K# Q! E- w' Z! K" j( M' ^$ l+ y
~! T3 j: @ l5 K9 a, {9 n( H i = strlen(fontContent);4 {) A) S; o4 y3 G
char buf[256] = { 0 };
' V. r1 z6 C- S R/ W, D9 L sprintf(buf, "%f", i * 10 * (wScale / 50.0));
1 |, {0 j8 P* N% { m_pTextBuilder-> lanarFrame()->Length()->SetRightHandSide(buf);* y9 ?9 c, t* |$ [1 F
sprintf(buf, "%f", 10 * (wScale / 50.0));
2 y1 H* \' F+ `& Y m_pTextBuilder-> lanarFrame()->Height()->SetRightHandSide(buf);
# f ^# H+ J* M7 i" |. D m_pTextBuilder-> lanarFrame()->Shear()->SetRightHandSide("0");
$ e: l9 O/ W; ], c) I) C% o8 T5 [4 S. o1 g' z: `
m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);
+ O4 a# f9 F+ |' U* k4 H m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0"); @8 i, c* ~: G" T
m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");
, v9 V( I! h4 ?; f+ N m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1"); d2 h% p3 A( y, P. @
m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");
) \; S# s7 w) K9 S& m1 D8 p4 o7 Z
5 ?, o& {5 y% ] std::vector<NXOpen::Face *> boundaryFaces2(0);
% w8 w, d4 j! V P2 E1 r8 [ NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);) F6 e2 L E: I/ P, e/ `" Z4 I( \
std::vector<NXOpen::SelectionIntentRule *> rules2(1);. \1 i4 j0 F8 {) D" N
rules2[0] = faceTangentRule2;+ `5 M, V5 G) P1 w! t
m_pTextBuilder-> lacementFaces()->ReplaceRules(rules2, false);
% G' `9 H) }; ^, Q& n& ?# G6 m3 U% [ q& M* c
m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);2 M3 E" R: x4 z" o) P
std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);2 G# m. ?, K' v( ?1 i, C B; X
CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);
1 n9 N' T% H- Q* ~1 \/ a3 w, @& `& R: H NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1"));9 T& A' [. l& k: E M9 w( B8 U
NXOpen::Curve *nullNXOpen_Curve(NULL);$ w* I4 @7 h; A' o( f' D
std::vector<NXOpen::SelectionIntentRule *> rules(1);9 c# o& F$ c' {' R- b# F- p
rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);9 o* e0 s, ~; u- b) w% }& W
m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);
% I3 P6 W3 M; w- |8 q$ S y NXOpen::NXObject *nullNXOpen_NXObject(NULL);
+ ~1 k5 L" t, T- E+ K/ z' X: ^ NXOpen: oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);
; o4 V. x1 P* n/ N, Z m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,
1 b( z3 X! c! l+ E# B9 P- M+ t NXOpen::Section::ModeCreate, false);
9 g$ d- [# G9 W" U! f0 V( N' H2 B0 A3 r7 f4 ?" f( @
if (bools)
4 F' b$ I9 Z/ P W {
: ^2 z/ E1 L+ _( b4 z! R
* V" G1 z$ M/ t8 ] if (m_pTextBuilder->Validate())
3 Z- J6 z) B3 ~8 S; Q) c! O/ F H* l {
- B, r& N0 x6 V( c* ]3 J( b4 y( S m_pTextObject = m_pTextBuilder->Commit();; [; w" S0 i) K
m_pTextBuilder->Destroy();/ q" L8 r3 V h7 S' k( f1 t
m_pTextBuilder = NULL; c8 Z4 q! B- {: l( D8 _: u
changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);
. w. ~' L1 h$ {7 X changeStringContent->SetSensitivity(false);
$ J1 D- m' I# A4 a changeRealScale->SetSensitivity(false);3 N* b* L3 w* r$ B; L5 P1 L" z
}
- b" z" V3 o3 ~1 H2 k; M5 S) j
7 i& R$ u* B2 q) m0 I }
- z2 |/ d6 i4 P |2 t6 W6 c else0 o6 M" Y: P; @& W
{
, g; v y8 X, Q* } // $ x6 l' P, u- g* c
if (m_pTextBuilder->Validate())
, n; d% o }/ J3 I+ q9 q2 s# j {
3 g+ k* N( {! X m_pTextBuilder->Commit();
1 u# L* n, z6 x1 t UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible);
7 ~7 T0 X+ M( T7 V+ a& c( I m_pTextBuilder->Destroy();* v2 z4 y- c% j: @; I6 U
m_pTextBuilder = NULL;0 o0 x* g# D$ P) l
}7 z6 O8 t+ S; x4 v( C
} 4 h$ s) [3 ]- W! r( Q
/ e1 e& L$ `/ n% `8 S2 A}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!. q7 a9 V/ }) J) H# w& G
|
|