|
浮游
发表于 2015-8-25 11:30:57
|阅读模式
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:% n# Q; `" s* y$ a
6 I3 D; [# a& u6 X0 ]3 n3 w. Jvoid Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools)6 T+ P% [/ \6 L' E" `3 P1 s: F
{
/ _4 s+ A% M$ y if (m_pTextBuilder == NULL)$ r$ S4 H% z. s6 A
m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts);
! F/ x/ B9 c K, s" D+ g* | int i = 0;
8 X6 Y9 v1 n7 E( E( U' B7 y1 T3 ~6 q* b8 ^( ]1 K( O
m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);
5 d A& ?# Q% @, _ m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);
! Z1 z( g: c, E4 Z8 W NXOpen::Features::TextBuilder::ScriptOptions characterSet;
1 ]2 g1 n3 `+ R: c( ?. j if (fontType[1] >= 'A'&&fontType[1] <= 'z')
4 ?' ^1 Y/ ]& h characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;
* z* l6 g( \& q8 L \$ w! l else6 Z3 ^+ `; x5 j) ~
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;0 R5 _- d! `) c5 l+ P- S9 f! _
i = 0;
* }0 |. z" M* S" H while (1)) w! \$ @/ f7 Z6 d3 S
{3 W+ l9 R- _* p2 J& a' T" M
if (fontContent == 0) break;
& j/ Z) P! p4 q3 G, I. ~ if (fontContent & 0x80)3 U: f/ k2 p+ u3 i2 w5 p$ n
if (fontContent[i + 1] & 0x80)
" m2 U) R6 t9 W' B if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312)/ e O/ o3 l. }! x
{
$ Z( G$ p0 h8 `9 t. p) K uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1);' C* ?6 g! q" Q" ]; \4 ?
break;
. k2 _3 P5 k# \( I- W/ B6 u% s }$ Q `0 w- ], r% S. @
i++;
" k* M$ f [, o% `" V }
4 g: w0 t! ]8 k m_pTextBuilder->SetTextString(fontContent);* F4 y8 I7 p0 i7 S$ B, k
m_pTextBuilder->SelectFont(fontType, characterSet);& U# c* v" E+ ^, r. `. D
m_pTextBuilder->SetCanUseKerningSpaces(true);
3 e- f+ f7 p# g. Z9 i m_pTextBuilder->SetCanReverseIntersectionCurve(true);
5 J6 z. |' G+ m4 l: D) K7 C( q* O1 P' z$ z6 h
NXOpen: irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),
+ k4 g% ?- @. d* |9 F$ h' v5 K Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8])),
+ |, y; y. b/ J! b; f# i B SmartObject::UpdateOption::UpdateOptionWithinModeling);; u1 V# f0 k4 {& A1 S
m_pTextBuilder->SetOrientationVector(orientationVector); e& E2 x9 P6 Q, i8 v
0 k9 Y- O0 G; g6 k4 N- d m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);+ {, S( u' U& Y: I/ X
m_pTextBuilder-> lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);
) n" a" @+ K& |% J; X# _9 l
* p6 X# {- Y$ l5 D7 ~6 s i = strlen(fontContent);0 k. Z- X# L- ]. c
char buf[256] = { 0 };/ O% K3 d8 s! c& `& a* G/ I
sprintf(buf, "%f", i * 10 * (wScale / 50.0));
4 e+ l; X0 Z5 w0 O, V$ n) V' _ m_pTextBuilder-> lanarFrame()->Length()->SetRightHandSide(buf);
9 j5 C- B/ A. { c sprintf(buf, "%f", 10 * (wScale / 50.0));8 h0 s& k- v+ ?" f, ?
m_pTextBuilder-> lanarFrame()->Height()->SetRightHandSide(buf);6 d( V1 Q0 r& N6 F! @
m_pTextBuilder-> lanarFrame()->Shear()->SetRightHandSide("0");# D4 i5 I' ~ r5 S% |1 H" W1 W
' r- @8 L) R" }. Z: }" B ?! y. y- }
m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);& L- r n2 |4 q) s
m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");+ q5 Z! k7 g, S7 l8 S$ N; X
m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");2 |; {3 Y9 Y& u+ ?$ U& }7 t6 r* i
m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");$ X- v* ~8 ]+ e( L
m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");" x, e& F7 o9 v* x
8 E, y4 D0 D4 ~0 W std::vector<NXOpen::Face *> boundaryFaces2(0);& I1 m. F4 s; U, o$ J( p
NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);8 k- o& t3 f C ] ?6 f) p
std::vector<NXOpen::SelectionIntentRule *> rules2(1);6 B. z/ ^( Z! j- X" a% G
rules2[0] = faceTangentRule2;
1 C# k: P" e0 K+ }3 Z/ o2 C m_pTextBuilder-> lacementFaces()->ReplaceRules(rules2, false);# C" B0 h8 n5 D# F* B
0 X$ I. @/ [& z9 f; M! {8 Y
m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);5 z) T' {- [ v/ ^: f5 ]9 w
std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);7 b P5 j. W7 Q6 x: c
CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);: A& j K8 Y, |, D% E! H8 ]
NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1"));# s0 B& l# ?4 {, l1 V! C) Q* Z
NXOpen::Curve *nullNXOpen_Curve(NULL);
7 ]. U; N$ D9 d3 l3 u& _+ q% ?# O. w std::vector<NXOpen::SelectionIntentRule *> rules(1);& |# G$ @5 K& D
rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);) e u2 S3 p9 c& ~2 V6 i
m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);0 ]' l0 P- f2 h7 N( b
NXOpen::NXObject *nullNXOpen_NXObject(NULL);% u; J8 t4 v W2 ?4 U
NXOpen: oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);5 N4 u# v2 N2 a4 z4 f6 u }4 S5 y
m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,
8 _) ^1 P5 d- r! T% Y NXOpen::Section::ModeCreate, false);
# ?. {& g" s7 c2 q
9 W# \+ h" B, m Q if (bools)
- F$ C% x, Y2 t- d5 Q( } {
7 D4 R: B: g8 C; F# s% @# s9 } _& u5 B- n9 y x1 S; r/ J
if (m_pTextBuilder->Validate())3 j/ I+ Q+ h$ T4 U' y! M3 L
{' Q& ?" @0 r4 W% x6 Z; |
m_pTextObject = m_pTextBuilder->Commit();
/ E5 Y9 I$ B/ c0 h1 ^: c m_pTextBuilder->Destroy();; s0 {9 C. G+ v( f3 ?, o
m_pTextBuilder = NULL;
4 b6 c0 r% t4 @ changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);4 t3 R; K* {* e/ q; X
changeStringContent->SetSensitivity(false);
2 }5 D1 Y; }' j changeRealScale->SetSensitivity(false);
3 f3 V3 m5 ~% `7 I+ L6 V }: b5 U* ~+ Q: p; Z
) E; z+ q. @. \ u/ j# s9 M! c- [ }
K0 G5 b4 I( A. z6 u* I( I! n else
, I S% S' z5 X' h4 @0 z {
: L: x+ G: ?( c0 i/ C7 R" Q' ^ //
) A+ k. U$ w' {2 f) j0 x! c: b& J if (m_pTextBuilder->Validate()). ~1 |- q1 ]* E( H' z, [
{
4 q6 n1 F. y6 q m_pTextBuilder->Commit();+ _1 T4 ~3 ^8 Z8 `: `( u
UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible);
' ^0 t* ]& u* g& |/ I m_pTextBuilder->Destroy();
, a4 G0 u x; N) i* m3 N, A$ n1 Y' A m_pTextBuilder = NULL;
, W, j" X2 b. {2 z1 s/ ?2 q }
* l: P$ R2 T# {) B# x M } - H0 G6 P. ?! c- _& k
% D& A: O7 P4 k4 J4 N}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!# e' L0 P* V. t$ s
|
|