|
浮游
发表于 2015-8-25 11:30:57
|阅读模式
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:
6 T# c9 v; Q# o0 D0 ?
9 e" r3 \7 K* ]void Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools)& f# t% g) F+ I2 s* D! _+ Q7 L
{
" R6 t1 W6 ~$ e9 c2 L! {. O) L if (m_pTextBuilder == NULL): G: C: w2 m5 q% I |
m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts);
$ Y4 p2 L( C/ K! f# Y7 j9 O5 ` int i = 0;; Y$ I( f. r$ _7 S! G; ~- o ?' j
, p. X. _9 M6 B1 u5 f( T+ ~% Q m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);" p& \5 H- @3 _. c
m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);8 y" l& U' `: ?7 s9 h" c% C6 y$ o/ i
NXOpen::Features::TextBuilder::ScriptOptions characterSet;& c" J6 i; ~6 }& R+ D
if (fontType[1] >= 'A'&&fontType[1] <= 'z')5 U3 A* L) l% {+ C, e1 p1 i
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;
% ]( w2 M, @7 U! X else
6 H; r) ?& h6 n# V$ v5 O! Q characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;4 G4 b: i+ A* ^& O" x
i = 0;
- V8 c+ l1 \' [1 q t" `; ]' ` while (1), Y& Y* z3 R% N* N
{
5 |& ~8 ^: Y0 h) Y if (fontContent == 0) break;
, b- ^4 b6 o' w5 _7 `9 X+ Q if (fontContent & 0x80)* s5 W8 j/ y- ?$ f* o
if (fontContent[i + 1] & 0x80)( @( U3 P1 ^& E& G) a3 P! v
if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312)( x: e$ U3 ]: k; f6 u, Y: H
{& ^# n7 b, w* T. H
uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1);
- T8 v8 z! c; o$ R# S2 V5 @; ^ break;
6 `2 z4 @3 T! b6 Q" h }
: }2 B& a* f1 A& h0 |! [ i++;
, O3 t: y5 q: u0 w* d% z }
. h: J+ a( {! m! _; B9 P6 G m_pTextBuilder->SetTextString(fontContent);+ `1 ?8 v0 ~: i# F1 X0 F
m_pTextBuilder->SelectFont(fontType, characterSet);
# X+ Q0 A6 u l1 C! @% Q( w m_pTextBuilder->SetCanUseKerningSpaces(true);
/ |/ p# g0 U) R5 ^% \" |: }2 C m_pTextBuilder->SetCanReverseIntersectionCurve(true);
" I: b8 f/ ~ g6 x( `4 Q$ G, O
5 R# X4 d2 D2 s9 [! n NXOpen: irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),* j; x+ ^+ A0 o1 t8 o# [
Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8])), r/ D, P z# d3 }! p, s# V& i+ a
SmartObject::UpdateOption::UpdateOptionWithinModeling);; h. R; }5 d' |' u$ b- q
m_pTextBuilder->SetOrientationVector(orientationVector);
; v4 A- w/ I& k5 y. {
6 t- s7 o! |6 x3 @; v" k7 u3 } m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);, S8 y* a% b2 {; |$ b; @8 |
m_pTextBuilder-> lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);# O4 H" _+ k$ D% f
' M* D& r" z) }% d
i = strlen(fontContent);
0 d( }! I3 m3 I! h: o! \ char buf[256] = { 0 };+ B" A! ^' d# r9 O* ^- Y1 w
sprintf(buf, "%f", i * 10 * (wScale / 50.0));8 q/ ^) h( c4 Y$ h# ^- j
m_pTextBuilder-> lanarFrame()->Length()->SetRightHandSide(buf);
4 K ] m$ S: q! b- T5 I k sprintf(buf, "%f", 10 * (wScale / 50.0));
3 w" C, b/ @3 O2 \5 w- g m_pTextBuilder-> lanarFrame()->Height()->SetRightHandSide(buf);# ^, L* S/ E0 G* `+ F) X) r8 b; ^
m_pTextBuilder-> lanarFrame()->Shear()->SetRightHandSide("0"); F: B. ~4 _; q0 x ^
8 t$ a6 l* @: b
m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);/ B6 A0 `2 N! I$ ^7 l- Q. U f
m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");7 m9 Z7 l& K% s5 x
m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");
; G) b$ W& n/ J9 Q) Y m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");/ z$ b" l' D' H2 E, N, r7 z1 T9 h# V
m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");
; A3 k3 C- ~$ {7 @: U
# c, \8 j2 Z8 Y: |" m) ~ std::vector<NXOpen::Face *> boundaryFaces2(0);
( x9 }4 N+ l& T1 N y NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);
$ Y2 ^! f& h" L$ A std::vector<NXOpen::SelectionIntentRule *> rules2(1);0 z2 }* G' k& |% q1 Q7 [
rules2[0] = faceTangentRule2;% r9 E# x- P$ i* F: Q
m_pTextBuilder-> lacementFaces()->ReplaceRules(rules2, false);1 R+ v6 S, j2 n2 T( Q( S4 W" P
4 N- n' L) Q) j! d( [% t- g! V9 ?0 B
m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);
/ T( {) w- `7 D$ n) e+ h | std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);
" l7 i6 M# V! }$ h: }0 U8 u$ U5 I CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);* S' ]1 w2 N0 l* n5 c
NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1"));
& e8 ^0 ^2 v/ ] NXOpen::Curve *nullNXOpen_Curve(NULL);
, ^/ h5 g, z0 p# }5 ^# X# \ std::vector<NXOpen::SelectionIntentRule *> rules(1);9 l' v5 s4 C9 r. w6 m
rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);
% @& U" a; w$ ^$ C. L3 A m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);
- Q+ s; {' U3 S NXOpen::NXObject *nullNXOpen_NXObject(NULL);9 d) g j' j+ o* Y$ i
NXOpen: oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);
! w* y \3 ^; O6 u5 R2 [- h m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,) c) t* l2 m( Q9 q4 V
NXOpen::Section::ModeCreate, false);
% `* L6 K, T" t# V$ \6 i
6 ]6 ?! i; e+ J$ U1 M5 G9 R if (bools)3 N% Y* J4 ~* F4 W$ S
{
* W. f# R- K8 }5 g0 G7 d" e. w 9 q5 t% ?( v u: \3 \- c1 V& h, T
if (m_pTextBuilder->Validate())( N0 I e+ W) |5 y9 R3 [# z5 e
{
1 M& {2 j+ D8 {) y; t m_pTextObject = m_pTextBuilder->Commit();& e' X: y8 e" ^9 n
m_pTextBuilder->Destroy();
& ~ }/ l+ ^2 J m_pTextBuilder = NULL;
7 Q @ R. L/ S) R; Q9 v changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);
( v. p4 j0 Y, H" Q changeStringContent->SetSensitivity(false);
& [' q p6 Y9 A7 v changeRealScale->SetSensitivity(false);2 N4 {7 [( w6 A2 K a$ v& D4 A
}+ |' s: q1 [) [% ]$ w c
* z$ g8 }& b( \& X. B }& M9 i! B$ @, i% R* R; E
else! P4 w1 I0 a" M' p7 T
{
" E0 o% _5 M- q) n3 ~. g) ^ // + z7 H# {/ S. R! @0 L
if (m_pTextBuilder->Validate())$ w3 E* \$ |$ q6 J
{
& a8 `$ X* I, E2 l7 p m_pTextBuilder->Commit();
1 W; \. Y5 |* A$ L8 Q UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible);6 ?% A0 e8 M" ^9 E0 P% H
m_pTextBuilder->Destroy();3 P2 L1 B+ Q4 Y0 F8 I
m_pTextBuilder = NULL;- Y0 Y7 d5 t+ s
}* k* O! q8 \3 _+ {% {
} 8 @+ S# i: Z6 u: R. b+ Z
; A0 a% q$ g$ z}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!
& I0 j' t: I5 K) I: N0 U5 j( _" i T |
|