|
浮游
发表于 2015-8-25 11:30:57
|阅读模式
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:
, z, g* A- g; W: p
8 e: e9 F* ^' a* W: Rvoid Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools)3 Y/ g6 h! Q: R
{
' V9 g! _# u3 |1 i if (m_pTextBuilder == NULL)
- P! w( W% j' Q% A1 `# F m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts);6 E, K6 D, [* c; [$ l3 L
int i = 0;
6 r' W" j- O8 ^5 ~1 S% P1 [- a3 Y) \8 o; \2 J9 y8 P0 `
m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);
7 L* w3 Z7 s, X m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);
' S, Q! m$ J. L5 P: |* b NXOpen::Features::TextBuilder::ScriptOptions characterSet;
0 u+ u X! R6 n9 ]& p8 O3 b2 { if (fontType[1] >= 'A'&&fontType[1] <= 'z')1 M x8 V/ z/ L2 ]% A
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;5 u7 G6 X$ Q2 [" D' \
else
+ _, W/ B8 L# I: ^ characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;1 y& }3 B# g7 w! g* X. K
i = 0;
( a9 ?" g8 ~$ }: [ while (1)/ w; }# z# E- |& T* o3 o
{
% s3 p) U+ ]& x, t* Y if (fontContent == 0) break;
1 l7 L' [1 @4 |) X, c if (fontContent & 0x80)) O# G$ }4 M4 F
if (fontContent[i + 1] & 0x80)' u4 Y, G& y% X
if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312) U& U0 T! u0 s% f3 J% O. c. u% U
{( ]: q4 c! C7 P' B
uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1);
6 U$ D4 u+ _, s% U$ ?4 F break;, n( X) n) Z: G4 ]6 D
}2 c# L8 D; y: t% v. o' w2 H; q
i++;8 c, a- [! X( \& _1 R* u1 O
}
5 ^4 r e# K9 e" x m_pTextBuilder->SetTextString(fontContent);! O6 T( L. i, {1 ^9 B. f& V) m
m_pTextBuilder->SelectFont(fontType, characterSet);' }2 G6 V: h/ l- z8 f# @
m_pTextBuilder->SetCanUseKerningSpaces(true);0 r: Z- h5 H7 u' R8 i# P& i
m_pTextBuilder->SetCanReverseIntersectionCurve(true);
+ h8 r( S$ B$ h% ~4 p7 m
$ o+ c: `2 Z. ] NXOpen:irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),
3 _3 _- \: g) U) j& n; I9 B: O Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8])),
4 y6 U3 n/ x P) O0 G+ U SmartObject::UpdateOption::UpdateOptionWithinModeling);
* d: s# _ k4 F$ ?) F1 w m_pTextBuilder->SetOrientationVector(orientationVector);7 |* K0 X0 |- E2 ~+ u8 M" |' E
|6 B' y) C" J$ x/ p) m
m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);, z- |( p4 O4 A; `2 p7 F
m_pTextBuilder->lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);
+ ^/ `& h& z0 L |5 i
" s8 c( D* @- M w& j4 J i = strlen(fontContent);
9 k% }, c- _$ t0 X* M& G0 s8 @ char buf[256] = { 0 };1 B3 }1 |0 d5 l; b
sprintf(buf, "%f", i * 10 * (wScale / 50.0));
, v7 Z( W/ q# U5 a m_pTextBuilder->lanarFrame()->Length()->SetRightHandSide(buf);
% [0 H( a8 M! g- ` sprintf(buf, "%f", 10 * (wScale / 50.0));- W+ S/ G; w: v! Z. }
m_pTextBuilder->lanarFrame()->Height()->SetRightHandSide(buf);; U$ t/ i, D9 L, O& r; ^
m_pTextBuilder->lanarFrame()->Shear()->SetRightHandSide("0");
% s5 k8 @9 P% K; Q* e+ U7 s8 T9 |, x( a) M
m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);
& _$ @- ]1 q, A6 l# { m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");. G: m6 C" c* L0 m2 O
m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");7 p1 P: y E- y2 Q
m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");; X1 }! B7 d& N. e9 p+ \8 M8 s+ m& E
m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");- y6 t: u6 L1 U+ A, v
$ T4 |" S& \, R std::vector<NXOpen::Face *> boundaryFaces2(0);
7 ]0 t; I( b$ q0 t M" K& b+ ~# Q NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);
' q; Y/ F0 g; {8 z! h1 T std::vector<NXOpen::SelectionIntentRule *> rules2(1);" m% _/ ^- `* M
rules2[0] = faceTangentRule2;3 O8 _; y# D. ?0 M/ d* {
m_pTextBuilder->lacementFaces()->ReplaceRules(rules2, false);1 b0 x9 R% n( R" h: |4 v" [7 P
1 `7 B/ Q3 b: q2 f% O5 S
m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);
3 v; H) `9 U9 ?6 |3 t3 v std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);: L4 ^+ O. x7 Q# y8 z) H/ L, a
CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);
# y' o( S; B! ?. o+ F) b NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1"));
8 q% A3 Z0 @: j7 } NXOpen::Curve *nullNXOpen_Curve(NULL);$ g4 h& U" D; P5 C
std::vector<NXOpen::SelectionIntentRule *> rules(1);
" s/ {9 a: c* M* O3 I) B5 i6 y0 o rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);* Y! I/ d7 g4 u3 N, w
m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);1 Z9 b# ]! F1 A1 i( R
NXOpen::NXObject *nullNXOpen_NXObject(NULL);4 K+ D) S H3 D5 u
NXOpen:oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);3 C4 O- O- Q/ A+ v; {0 a
m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,' ?+ q; Q4 Z$ N9 n% h0 ~
NXOpen::Section::ModeCreate, false);& _/ K) u( u3 s" h! Q
% X9 [. F+ g) g) ]/ m8 e/ v C8 C
if (bools)3 N" q6 M: j' N) |8 l+ \1 L* x
{, k% D7 ?0 o0 i# C4 M$ c
' m7 U5 ]5 f8 w
if (m_pTextBuilder->Validate())
% o$ n8 m- |" @ t) Y, R {: C: A$ H8 B/ }* F7 ]
m_pTextObject = m_pTextBuilder->Commit(); j5 z& n; Z& ]2 @; S& t
m_pTextBuilder->Destroy();
, n+ ?6 i, r0 J/ P; K8 q# a% a1 M m_pTextBuilder = NULL;0 s2 p. m. r( ~/ b9 C1 M. W+ O# Q
changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);
: I3 t* o$ f" \: v changeStringContent->SetSensitivity(false);" V8 d) D. n2 C$ Q+ |* V
changeRealScale->SetSensitivity(false);8 @: n" j) h$ X' [1 X3 n
}8 N) A' Y) F/ b* ?& B2 F, A6 z4 D
3 A7 r/ K% B1 d/ x% |% t
}
6 l" h3 _& f, x, K else& w" q! Q, e2 T# Z% V* O; ]. ?
{ j7 U" [0 |) G* l6 N }% J
//
, a8 ]3 _" b }8 J% Z/ K- I if (m_pTextBuilder->Validate())* T' P9 A. M! v( U( i
{
" K5 \& p; `7 y; S* t m_pTextBuilder->Commit();$ y: _" k8 v' T0 J6 G) e: @
UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible);( Q6 d- w3 [+ a& ~/ {" C+ |. g* h
m_pTextBuilder->Destroy();
- Z" T! D/ n( b( ]4 W# C8 Q5 H m_pTextBuilder = NULL;
& L0 B' f6 J# n4 j# s- o7 Y3 g7 C, k }
2 Y+ E4 ?6 X) o+ w* E }
& X) E+ b/ @( u
: K5 h+ j& l! R& G2 a}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!2 O. j" q7 F B1 o& x$ Y5 X
|
|