|
浮游
发表于 2015-8-25 11:30:57
|阅读模式
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:# u: O% v7 ~; o6 c# a1 b2 m; c
, w+ a& A9 q) u3 J0 h8 {8 V+ t" o: X, }+ ~void Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools)' ?1 E" Q2 G; s: p
{
: g5 F5 m1 @, \+ R3 h if (m_pTextBuilder == NULL)
7 c' ]1 h# H) _5 F x$ z; T m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts);8 B' k$ O5 o' a+ o5 ?
int i = 0;
1 H! M/ Z! l, h8 L3 [( j' j4 q# d3 x& |1 w
m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);
- s6 ]- F: R0 `$ d2 F4 r m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);4 h9 N5 ^( ?: a5 \% [
NXOpen::Features::TextBuilder::ScriptOptions characterSet;+ ?0 T/ S, u" U8 ~$ w# M
if (fontType[1] >= 'A'&&fontType[1] <= 'z')! t0 c- v6 e! }/ Z
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;
- G2 L# `# l. F/ B else
4 m: X( g, @2 l5 k# @ r characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;5 i7 G; g' b$ j4 d
i = 0;5 E8 {- k! P4 f" U- [
while (1)& H/ x G1 S; i' ]# b) m3 y
{
x/ y a1 J5 |6 K0 c if (fontContent == 0) break;7 P3 V& @ F t& N
if (fontContent & 0x80)5 F" `" |8 b5 [* l
if (fontContent[i + 1] & 0x80)7 a2 j9 T/ H7 @0 S/ I1 }! n" [, @6 j8 P
if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312)
+ u+ M. T: Q- a: g: k6 k {
: K/ S5 `$ G$ Y+ ^0 _* m uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1);/ \) e- e( M4 Z
break;' h7 G" {$ ]' R5 P
}; w( S& G% l& |- p: b
i++;
- E+ F3 w7 K: }6 K }
9 ?$ P) Z5 \' d) Y2 g% X/ H. @# u# M m_pTextBuilder->SetTextString(fontContent);
! n0 I6 ^* V0 `& { m_pTextBuilder->SelectFont(fontType, characterSet);
( o. |8 U# j! c, W m_pTextBuilder->SetCanUseKerningSpaces(true);
$ C5 X. Y4 X* s4 o" } m_pTextBuilder->SetCanReverseIntersectionCurve(true); S3 _7 ?5 |) C, s/ D$ {: y& S% I
_% m5 F8 h7 M4 L/ X
NXOpen: irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),& _* Q! O4 }5 w
Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8])),
1 o/ W; k; x8 ^' Z* g4 O3 y SmartObject::UpdateOption::UpdateOptionWithinModeling);% u% g, M- I+ p7 Z
m_pTextBuilder->SetOrientationVector(orientationVector);+ ]6 x! R0 v$ }7 ]1 s1 Q: i, T
- L3 e* T9 \( B7 E0 b) G m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);
+ K- J2 u8 L6 _9 N m_pTextBuilder-> lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);
' l- P0 K. [( B; {, N6 B* B" T/ r0 i7 J" M
i = strlen(fontContent);# ~ F+ _! i& ]2 {: S
char buf[256] = { 0 };
" l' r; Y% f: Z+ G5 e; R sprintf(buf, "%f", i * 10 * (wScale / 50.0));
& }3 |, m% I9 X+ \7 O m_pTextBuilder-> lanarFrame()->Length()->SetRightHandSide(buf);: O. K, U6 B+ t$ N, X1 K4 b
sprintf(buf, "%f", 10 * (wScale / 50.0));
, a! ^ T3 \5 I0 T m_pTextBuilder-> lanarFrame()->Height()->SetRightHandSide(buf);
8 S% x% U7 _' ?+ K) n; I m_pTextBuilder-> lanarFrame()->Shear()->SetRightHandSide("0");
0 @* @: X6 F+ z/ L. E1 r$ z% I; r. H! c8 {" W: G
m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);' ^: d( s: i% R' d" V8 B1 K" H
m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");
. \& ]6 u; X, v) v/ |# f8 L m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");
3 \3 U- f( _& ?9 _- I$ ^ m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");7 o8 w1 h: C% Q
m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");9 H) \; H: L1 o& \
( T6 \1 p9 A. ^) A7 x
std::vector<NXOpen::Face *> boundaryFaces2(0);
" p, s8 E. F# y& X" ~# v& m NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);7 ?* B) E0 x3 @, O! `2 h$ ~
std::vector<NXOpen::SelectionIntentRule *> rules2(1);
! c4 H5 {% M* ~7 ]9 d4 @ rules2[0] = faceTangentRule2;
2 |1 d! }1 C- w7 j; \1 U5 L4 Q m_pTextBuilder-> lacementFaces()->ReplaceRules(rules2, false);
# N7 Q9 _9 R- K
% i$ p7 W0 r1 H2 H m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);& J9 e1 n; v8 y2 K
std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);& g" ]* A9 r) Q; \/ x# y
CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);9 N* h* m' K* L' x. l
NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1"));( A, m. j) @" {8 y/ C
NXOpen::Curve *nullNXOpen_Curve(NULL);
7 R( a5 U X; c& T9 f9 x( O1 w std::vector<NXOpen::SelectionIntentRule *> rules(1);
. n5 a2 l! e7 \ rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);4 z* P9 [' I$ d _ w7 ]- `
m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);% l" Y q) w4 H! ~4 [
NXOpen::NXObject *nullNXOpen_NXObject(NULL);
) H. p% o7 S4 }# `* E$ u NXOpen: oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);
3 u/ t" f+ k2 P1 Y' g m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,3 Y$ |: n, P i4 H
NXOpen::Section::ModeCreate, false);
) h% a+ s/ f$ x5 N y: o1 R. V) Z, d6 J. u6 f/ j: D1 o5 R
if (bools)
0 R6 Z& L: T r" p& L2 s% N7 w {
1 w- ?+ [+ a& B: r0 B& P 5 p* ?9 B2 F9 ^' L3 _- O
if (m_pTextBuilder->Validate())0 x9 r2 |9 j2 V6 Z# d/ f
{
: o* q9 D4 F$ Y l: B m_pTextObject = m_pTextBuilder->Commit();
3 }+ M7 E; V5 B6 A- g3 H8 J/ u: t m_pTextBuilder->Destroy();
/ r/ h Y( p n" i! p" k8 |% g m_pTextBuilder = NULL;* R3 p1 _5 \9 e. u
changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);
, h+ [" M, s; B; M0 i; g# ~' G) ? changeStringContent->SetSensitivity(false);
5 J6 a8 ]1 Z! U changeRealScale->SetSensitivity(false);
9 B$ o2 v% P& V9 R }* ]. I$ L1 m4 ]" \
: @3 _' [# v) k8 i7 x- V5 ] }
; Y) _! A. V! X else; A$ v `* Q( A7 O
{ 6 ]3 `6 T6 ^* w
//
+ ^4 Q2 W! o8 s if (m_pTextBuilder->Validate())
7 S3 s9 Y" k8 { {
" `9 X" B% _, B8 i8 G+ `1 } m_pTextBuilder->Commit();
2 ]% Y6 I. x9 G8 }% V/ z; b UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible);
5 y6 T( I% d! u0 `1 P m_pTextBuilder->Destroy();
' U. e+ Q9 r1 {& e- i8 V( K) r m_pTextBuilder = NULL;
4 k( q, G) b+ n1 l$ N: s( N }" `7 u: l y1 ^8 D
} % \$ N; M! V% B! {
' L3 m. y6 y8 C$ s3 X}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!, K" S+ A7 e% ]) a% p5 J& w0 |+ u5 `
|
|