|
|
浮游
发表于 2015-8-25 11:30:57
|阅读模式
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:
1 V8 D" Q8 ~: s! }4 t8 L R0 ?3 ^2 X3 a+ w% F8 T
void Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools)
: T* t1 \" C! W9 p; C$ t* r1 g{
0 R2 {* B0 L( \( Y6 { if (m_pTextBuilder == NULL)+ C P. P+ m3 o
m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts);
6 O; {7 _5 N2 D+ | int i = 0;7 R# y( o+ p" d5 Y; W2 C- t. O7 s
# l% E; u! B% d3 L' u& n1 X# ^7 [
m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);
: c, y9 h) P& u# J# A) B/ u* B m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);
: D, A0 V; U9 _- t6 f5 b! x NXOpen::Features::TextBuilder::ScriptOptions characterSet;
9 j0 l9 n% u( E6 _$ X if (fontType[1] >= 'A'&&fontType[1] <= 'z')
8 K9 e1 y6 {' x& b$ ^, S7 A$ h characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;- `2 D) q7 F L
else3 @ A4 {! w! f' ?$ [
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;
% b9 G; |$ I2 c1 y i = 0;- F/ m& n0 t3 l% o0 ~& y
while (1)8 U# I2 Y' h, \# D( `: M8 M
{1 f n; I" V; L4 `/ S# ~
if (fontContent == 0) break;) o [4 Q; J0 {" R9 q+ t
if (fontContent & 0x80)9 {3 F6 i! Z) q3 y- t
if (fontContent[i + 1] & 0x80)- A! h4 h0 z0 f, Y2 q
if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312), V( X" ]# \* y+ l+ K. {( f2 a7 T
{ v3 m( T7 v# ?0 e1 a
uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1);& F. A6 b3 Q& `+ ~, \: @5 H8 y5 V
break;4 L$ U% p& ^; [
}! o0 H2 j& U- d/ v- U0 _( s* b
i++;
0 k% m2 k# S; p8 H4 p1 p }
5 Y# w+ O" x& c0 z m_pTextBuilder->SetTextString(fontContent);
! x9 r; J3 P9 u* p) A s6 d: e- `; s6 | m_pTextBuilder->SelectFont(fontType, characterSet);/ F$ W7 w2 g8 g& n0 z
m_pTextBuilder->SetCanUseKerningSpaces(true);
: X! b( r+ S7 G m_pTextBuilder->SetCanReverseIntersectionCurve(true);# F/ l% c$ o' k: I- X( M5 _
% \0 `) i' f% { NXOpen: irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),3 z# y c2 I1 }; e
Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8])),
( u; @! E; K4 \5 | SmartObject::UpdateOption::UpdateOptionWithinModeling);7 K0 _8 `5 M: s- o
m_pTextBuilder->SetOrientationVector(orientationVector);( R# r) y. |* D3 W% u! L, m4 V! }
) z1 a2 G- ~3 X1 g3 o3 _9 H m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);* \# }# H* |+ M. y0 k
m_pTextBuilder-> lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);6 e! G' ?7 C" x% l# R" p5 @6 O0 s& A
M) k3 o) a/ L0 K) J
i = strlen(fontContent);
/ }! d A# ^$ D6 x5 {6 |; @ char buf[256] = { 0 };
4 Q+ B4 F- d5 @ ~/ K sprintf(buf, "%f", i * 10 * (wScale / 50.0));
& k& @% t! Y, j& X! l, a$ m: s m_pTextBuilder-> lanarFrame()->Length()->SetRightHandSide(buf);. D) e! I# K3 H4 j+ |6 v
sprintf(buf, "%f", 10 * (wScale / 50.0));, N/ |2 U3 l" ]( \/ A+ ]8 K& l, G
m_pTextBuilder-> lanarFrame()->Height()->SetRightHandSide(buf);
k: W) g9 a2 h m_pTextBuilder-> lanarFrame()->Shear()->SetRightHandSide("0");# z( ]8 _, N- N1 x4 a
) _* h# N; Z. c" b8 X. c8 I m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);8 J x( @5 s* m, c4 `4 U
m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");; C) a/ A2 v R1 i8 T
m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");1 c4 I' t5 s8 d9 B. B& w# \
m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");
. }% E) d2 ?2 d7 }1 D. @ m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");
' r: F/ m5 t3 T2 W! ?+ ]5 Z) ^8 M6 M# y2 m
std::vector<NXOpen::Face *> boundaryFaces2(0);. ?. @. u3 q8 C7 Q& F; B# X
NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);
3 }$ q: f* A, h4 @9 ]3 ` std::vector<NXOpen::SelectionIntentRule *> rules2(1);% t y/ \; `9 u1 T* X9 v
rules2[0] = faceTangentRule2;- V3 x2 [8 V5 I& \7 o1 T
m_pTextBuilder-> lacementFaces()->ReplaceRules(rules2, false);. A3 x3 n0 c2 p( [ ]: [
. ^( P1 L' U0 g9 n
m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);
, A' P3 p; S$ x1 g/ J std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);
1 [' e8 ^1 ^$ B- E CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);" T- b# A3 v5 a
NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1"));
& g0 j) Q% {2 ]3 U3 b' U' Q+ d' P NXOpen::Curve *nullNXOpen_Curve(NULL);
5 A! E/ L9 `/ Q+ Y5 @' X& Y std::vector<NXOpen::SelectionIntentRule *> rules(1);
$ ` E$ P: Y- S; S: f/ [6 s rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);) o' C& s5 {0 I1 |" u
m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);
+ L. Z. N! @8 _. ? NXOpen::NXObject *nullNXOpen_NXObject(NULL);
* I+ L! L! K' S5 K% O+ r6 K3 X NXOpen: oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);' M. h+ H1 G% Q: b0 K! R; x
m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,
2 y) E& |; ~1 h+ X3 s! c NXOpen::Section::ModeCreate, false);/ Z& U5 {& @3 M
4 x9 p2 P5 D$ }. [ if (bools)
, k3 ~- G6 h _1 \) B {5 O- ^5 v( j: W1 c5 }
/ I% {8 L3 P$ b1 Q6 [) A6 J
if (m_pTextBuilder->Validate())
3 N! g( H* n) n7 { {
8 T% a$ E1 }' R. g m_pTextObject = m_pTextBuilder->Commit();
+ H( Y. S% d, T' R; ]! @8 A' |9 e m_pTextBuilder->Destroy();% V" S4 P Y5 _, Y3 r
m_pTextBuilder = NULL;
[( q2 Q! N& W, y% D" \ changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);
$ a) t# W' g7 i3 e8 t changeStringContent->SetSensitivity(false);
+ Y Q% {( V' R6 J changeRealScale->SetSensitivity(false);) n- F5 y) z. V2 \( G0 X# ?
}" }: o5 Q4 z, u) q; m
5 T: ?1 C2 Y R+ F; N9 E8 ~8 y( H }
5 R' z- {. \$ j% u else3 ^' Y" F: Q% a5 Q6 W# L5 Y! Y+ k
{ 1 w1 K% H; c- s% r$ {
// ' ~# _* M F1 H ^) x4 k1 l$ c
if (m_pTextBuilder->Validate())1 }. Z! b1 W! ~& _
{
& {0 h# \9 \& z- `, m2 j) |2 j m_pTextBuilder->Commit();( I0 ^8 h* j. |# f% ? q$ ], F9 F. O
UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible); z, @! w% L6 Y6 c- ?; N
m_pTextBuilder->Destroy();- E7 o1 Z. |) |* s
m_pTextBuilder = NULL;6 Z ]4 t$ L( l$ V: A# ]. H) Z8 v8 ^! C
}
" U: S \+ I5 D% C5 a8 C u }
& w' C9 t; _6 T* q
: M& e9 p+ i7 L4 P6 Q) }}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!% H* D& w& j. L5 E& j0 ?
|
|