|
浮游
发表于 2015-8-25 11:30:57
|阅读模式
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:
2 {! `7 b* L- A' o% d! v2 F( h& z, p" L
void Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools)
% j; n% R! f7 W" j+ V* I{
/ z2 u' m: ?+ m if (m_pTextBuilder == NULL)
( |! F# j6 L: f! T m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts);6 c" t0 q8 E5 ~8 B; U
int i = 0;" V2 L0 _3 s- z% ~
, i1 ]: i% U, S+ L! a6 g- y: B
m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);
; k7 @4 }6 W2 ]. b# T& C! t m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);$ @0 f, d2 {4 ^5 [9 {! L
NXOpen::Features::TextBuilder::ScriptOptions characterSet;. L& S; Q ` M
if (fontType[1] >= 'A'&&fontType[1] <= 'z')" h% x! S, D) j$ J& S
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;( r8 ?9 {1 i. f: D
else3 X6 h$ }% |/ W" B" B
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;
4 \2 }, ?- L, r# a4 h& U i = 0;
6 B3 D3 h; A) i while (1), E- b( I8 r+ H. K ~7 i6 x
{" r" b; a1 y$ P. I1 w6 s
if (fontContent == 0) break;) Q% Y; J0 L8 j$ ?7 i) l
if (fontContent & 0x80); Z( a3 h+ k! ]0 f
if (fontContent[i + 1] & 0x80)
, d" w9 Q! f- V0 L3 L! F0 ~! }8 d if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312)8 Z# ?( D3 E/ G1 ]2 X% _% u
{ `1 X2 S: {6 V: Z6 d3 m% C9 R5 e6 v
uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1);
' E, e, R+ @' `5 R" F% E break;# w! v+ X$ I' i2 G* i
}0 W, O* T# ?2 q* H, H$ ]: R
i++;
, W1 V: N$ \7 x. {8 E }
1 c/ f2 w: t$ n1 C m_pTextBuilder->SetTextString(fontContent);
; x! j; Z9 v" v! S% p% w m_pTextBuilder->SelectFont(fontType, characterSet);9 M+ @0 [- b \2 v
m_pTextBuilder->SetCanUseKerningSpaces(true);
4 |2 ~; i9 S* m% E' S4 x2 T m_pTextBuilder->SetCanReverseIntersectionCurve(true);1 o7 u- m2 R! I6 c& @& b4 o7 g
0 B! y% U; F0 w# Q; J; F
NXOpen: irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),
5 p+ Y, [9 f: w+ W% J; K1 Z Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8])),
: z8 ~/ P9 Y% w SmartObject::UpdateOption::UpdateOptionWithinModeling);1 m8 a* n8 l& }2 j# ?8 o* q7 l* T
m_pTextBuilder->SetOrientationVector(orientationVector);
* l7 P+ a" `, c, X0 ^) d) x% n7 C" r# _
m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);, ~3 c, l; o+ X& b$ n5 r; H0 t
m_pTextBuilder-> lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);
* Y m0 Q, A1 A
0 ]6 P8 @/ A1 S i = strlen(fontContent);
# i, t+ k! J( M4 d9 V/ m char buf[256] = { 0 };( N1 m( N+ T- l. h" y
sprintf(buf, "%f", i * 10 * (wScale / 50.0));* t5 Z8 W1 o9 u' M) h" R
m_pTextBuilder-> lanarFrame()->Length()->SetRightHandSide(buf);
( g3 x7 ]0 |: V# J! ], L3 G2 ~ sprintf(buf, "%f", 10 * (wScale / 50.0));& C3 j$ D- @- |% ^
m_pTextBuilder-> lanarFrame()->Height()->SetRightHandSide(buf);% x8 z( ?$ Y( n1 D! ] v
m_pTextBuilder-> lanarFrame()->Shear()->SetRightHandSide("0");9 v% A' U v/ Y3 E2 J
& O' ]% N7 ^+ n7 h9 b, A m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);
+ O' q7 w5 p! I' _" e* X m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");/ T* h0 c) M, S( R
m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");
+ R; U4 c/ Z( T: O m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");
+ c: H8 i7 G2 U/ b m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");1 i. t% A& p3 R6 m; p. h8 g, U
6 \. P! D; T$ s' ~' ? a: T
std::vector<NXOpen::Face *> boundaryFaces2(0);* A& s* x8 l) r3 Y
NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);; x& e \' t. J- f. `$ v. \* I
std::vector<NXOpen::SelectionIntentRule *> rules2(1);
2 x+ x5 S" X4 ~5 L8 U6 O rules2[0] = faceTangentRule2;5 G6 t' \6 x u. d
m_pTextBuilder-> lacementFaces()->ReplaceRules(rules2, false);. x |) h( j6 I' w0 w) b! m$ {
4 k5 I( m) I/ d A R
m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);6 S$ G- b0 `9 c' Y
std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);: ]2 l# Y8 w8 O. E0 Q9 b
CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);! ?6 j) g. d2 e& x2 B) p! c! j
NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1"));4 C% I# e- w9 j- _% w
NXOpen::Curve *nullNXOpen_Curve(NULL);
/ X, v: U- p8 P& w std::vector<NXOpen::SelectionIntentRule *> rules(1);
5 J. N5 F5 t( e/ ^% A2 ?) d rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);
5 V9 K) b( ~1 i' @ m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);" ?9 P0 G7 e1 E4 p- x5 I' n# `
NXOpen::NXObject *nullNXOpen_NXObject(NULL);
! j1 }* _5 f) K# _+ p# o NXOpen: oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);4 C m1 o& h% S: V. V+ S
m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,& D$ ?% i5 d" I
NXOpen::Section::ModeCreate, false);! J3 Y3 k0 T3 _7 {1 K: _3 B
, o* z; ?( o6 ]& E8 Q if (bools)0 H5 I2 `5 x7 R
{# z* Z% d& F5 B, _- A. D. n
6 O% \3 ~4 d/ \, i if (m_pTextBuilder->Validate())
" I. u5 _1 m0 k: x5 G- O: @ {' m j& J$ R: U' }' H7 U
m_pTextObject = m_pTextBuilder->Commit();
8 u: z8 O6 p8 P m_pTextBuilder->Destroy();" i9 r( Y: H& H% c, s& J& L! U1 _
m_pTextBuilder = NULL;* T! r2 ~. o+ l" x" A( }1 D
changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);1 E+ r" _& C! V1 `, r
changeStringContent->SetSensitivity(false);; z1 H8 ]/ \$ z& k6 a
changeRealScale->SetSensitivity(false);
# @/ ?" M; C! ?8 J+ P- F% {( B; [ }% b# }, F7 `/ j- J& H: J
- r7 J. T9 y9 t! f3 K }$ B8 L. W$ G8 o4 F6 o0 Q$ k! d
else
: G0 k' C( k1 `. j* S* U5 u. I { # H% k! c* K" A8 c0 C) a5 ], p
//
, a) g! H9 S. Z. h5 ~ if (m_pTextBuilder->Validate()); ~% y1 P4 e* g) F2 {, ?' A! ^5 f+ [
{4 H4 |2 n1 o5 h& w/ U
m_pTextBuilder->Commit();
* ]/ ]6 C! N" w: } UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible);
8 [( ^( W* {- i8 g3 p. w m_pTextBuilder->Destroy();5 {$ [+ S% g% c# G" R) u* c
m_pTextBuilder = NULL;
4 H& B3 H! S" q1 g- ^: Q }
- E) @' u- N2 { }
8 d, P* d3 C5 [
# w3 I; z& \* J) [}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!& A4 _3 c: ]* s8 S/ R, O
|
|