|
浮游
发表于 2015-8-25 11:30:57
|阅读模式
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:
. r* K Y' A- G3 h. c" A3 k6 W
3 F2 ]/ y- C! ~! c" f! X& Yvoid Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools)
/ v! I* c6 n& F }{
; B* n; o o: t+ r- V5 S& m if (m_pTextBuilder == NULL)
4 h: t% H. _8 }/ o m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts);. i# Z5 D- C) A7 p# L1 b7 e: D
int i = 0;
6 e8 I' g5 h N# _ P& A5 `0 \" J
m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);' k3 Q5 V$ @+ H' i! o8 l1 E5 E
m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);! L* o- N. H7 J* m$ b8 ]( k1 {5 q
NXOpen::Features::TextBuilder::ScriptOptions characterSet;
' s) |3 b/ f! R+ t* O if (fontType[1] >= 'A'&&fontType[1] <= 'z')
6 W) C9 w5 U; P/ s _$ x( j. V characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;& Z% k, w$ l# _9 n7 N( Y, B
else
: r, I: k8 a- P! o) S, m characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;
$ Y2 f( {$ l) w/ B6 M4 f i = 0;$ H$ e) d T3 n" i
while (1)
0 a1 L$ R; V* l2 ]. d- x' u {
: |$ u# W. _* D) f if (fontContent == 0) break;
# o. [( t/ x5 ~. @ if (fontContent & 0x80)
' z w, U6 E, j if (fontContent[i + 1] & 0x80)
$ O0 f& f# }3 n8 ]( ? S4 d) { if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312)2 R+ N! J' h0 O; ^8 ]
{" S T" h6 K! \! q$ D# Y7 V
uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1);; n" u# Q% ^/ A7 A4 i* i, v9 R
break;
1 L# i. _7 ~& x8 m6 v }
+ C, B1 _7 F- \+ f9 }: M4 \4 C! k i++;% P7 g% [4 b0 o/ D# D) T' W: s; C
}
( y0 L- S/ p. ~8 X$ j( ]% ` m_pTextBuilder->SetTextString(fontContent);
) [; u9 N3 `) Z5 k9 U! T m_pTextBuilder->SelectFont(fontType, characterSet);
" E2 [# t1 y+ p, e- U m_pTextBuilder->SetCanUseKerningSpaces(true);8 [7 v* i) s" {- A( d. G
m_pTextBuilder->SetCanReverseIntersectionCurve(true);& Y+ f# R5 f* k. e
; P2 v' S* e9 Q NXOpen:irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),( j: _/ g2 K1 q- X+ x! \9 x9 o
Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8])),4 }* A0 X0 c# @
SmartObject::UpdateOption::UpdateOptionWithinModeling);
' `" u: {2 O, K/ l5 h m_pTextBuilder->SetOrientationVector(orientationVector); l' [( L# d/ H8 o' C+ Q
/ }' }8 i5 q" F m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);/ _3 d' M2 G1 T( K
m_pTextBuilder->lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);
% a% u E8 |- O) T1 C! @8 W
) J) R/ y6 P3 m5 R1 I$ A i = strlen(fontContent);
5 c0 u9 A8 p/ E* u7 V: | char buf[256] = { 0 };
/ y9 ?# q9 J) z& C$ I1 n# R sprintf(buf, "%f", i * 10 * (wScale / 50.0));
! ~& D; @" |- N7 p! X! z4 B m_pTextBuilder->lanarFrame()->Length()->SetRightHandSide(buf);
, c& X8 ?1 D9 n3 h4 Y! { sprintf(buf, "%f", 10 * (wScale / 50.0));
) ^1 b% @* z1 O% X8 { m_pTextBuilder->lanarFrame()->Height()->SetRightHandSide(buf);4 J0 d7 n- F; i% b, Z2 K
m_pTextBuilder->lanarFrame()->Shear()->SetRightHandSide("0");
- i4 l* J) W( i3 |9 m
- e9 t x5 t. s+ \ E m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);& _, C0 ~' a$ ~0 ?
m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");
8 f2 k+ l$ K; C3 T1 C: M m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");
! L; `/ l4 l+ k0 n m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");1 `1 _8 N, k1 A
m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");7 l, o2 o) }' L) j& e
2 l2 J7 a7 q9 }$ B
std::vector<NXOpen::Face *> boundaryFaces2(0); N& z1 T8 L/ K5 z5 F7 j
NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);" T4 N5 e# j+ M d, g+ V9 B7 m6 E- f
std::vector<NXOpen::SelectionIntentRule *> rules2(1);
2 `7 N* W+ v; Z% f+ Q7 S5 G rules2[0] = faceTangentRule2;8 K4 n+ ^1 ~8 y
m_pTextBuilder->lacementFaces()->ReplaceRules(rules2, false);
% n( S( F; l! s6 e: i& M7 r+ [- Z% t$ P7 _6 Y2 p F9 Z
m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);& x8 F% }6 G& U7 e: _
std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);( G2 ]% ^- k9 U+ |5 M: J4 B5 ?$ t1 `
CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);
6 X- Z$ H! Y* a* S NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1"));
- x8 n- @9 y6 {5 H: O, c5 X. J% X NXOpen::Curve *nullNXOpen_Curve(NULL);
" E* K% N; t1 h2 @% x0 u _6 U std::vector<NXOpen::SelectionIntentRule *> rules(1);( g2 ^2 [, Q6 T+ _, x4 r$ Q$ o7 l
rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);
3 X. F1 X5 [- H" R' N$ G$ \% \ m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);$ D! e! m0 z. h
NXOpen::NXObject *nullNXOpen_NXObject(NULL);! G. B- {/ h. @; O
NXOpen:oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);) Q' Q0 P6 r, M7 I o# y0 }
m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,; S& d" Y: z( k( K* {
NXOpen::Section::ModeCreate, false);) m% Z' ?, t F0 g" |+ h
/ z9 _) [" f/ b% M, ~1 f if (bools)
& T W* @" O& n: j" W$ H3 p3 \. g9 w {
% z( i7 F+ \6 u3 s! M
d3 O* ^# T6 l" [3 o1 d8 q if (m_pTextBuilder->Validate())1 v! s! M" K. Q9 s$ N; y0 z& d4 B
{* k5 @) P0 Y c. P
m_pTextObject = m_pTextBuilder->Commit(); i) K& m5 G m+ S* k* ?3 p
m_pTextBuilder->Destroy();6 z- J; w; z" Z/ ~8 j9 ^
m_pTextBuilder = NULL;2 e- }) d& X6 h G- o* R: L
changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);
) J: r' }9 s3 K, N: A( s% j changeStringContent->SetSensitivity(false);2 o* l+ w. _) D8 y4 K
changeRealScale->SetSensitivity(false);
* ^9 L+ P, k5 k. D- m+ L }) E: o- G7 n, l9 K7 B9 I0 F/ d
+ i3 V; |0 E/ K7 z# h# ~+ A9 x8 y
}
3 C" ]" Z2 w* F else
6 I+ y F, f; ]$ o/ X2 Y. Y {
: t/ ~7 p8 ~+ Z( {$ o5 t //
8 ]* k: N) _7 { s$ s" | if (m_pTextBuilder->Validate()) Y' L. r! l8 }! i6 I
{
- d" k/ \+ @9 j m_pTextBuilder->Commit();, i. `; D; j. S3 |- p( {6 e
UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible);
# }* B; h$ a# R+ G6 T m_pTextBuilder->Destroy();
/ B5 P9 P/ e8 q2 H: }! K* E m_pTextBuilder = NULL;8 O. r2 }& p6 N8 l9 }% {$ x
}
; k9 A! w" ^0 ` }
( S. M4 N' p" D
( s+ T: h5 _$ f5 j* r}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!: U0 |) A" s y' X$ j' X
|
|