|
浮游
发表于 2015-8-25 11:30:57
|阅读模式
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:
) s- k2 t4 _5 r! D$ S+ C
8 X( b& r4 I$ [+ U, P" ~( dvoid Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools)7 w" H8 `+ |* G# C S0 G
{
8 N9 U" H: I; _' z3 w1 l% C if (m_pTextBuilder == NULL)
& y) ?: v6 z, [3 c m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts);
$ g! W4 H& V0 Y |& j% ^ int i = 0;
1 s! d+ G- i, j W: a8 p4 u5 Z# s, |
m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);
4 ~: U' A0 E; p0 r6 c ? m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);! s4 Z& k- }5 a! o# P7 H. P5 [
NXOpen::Features::TextBuilder::ScriptOptions characterSet;5 Q! q/ U3 J( b' ]2 S' ]3 N
if (fontType[1] >= 'A'&&fontType[1] <= 'z')* p) X9 u: D6 w7 r. p: _! O
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;4 h; ]2 \4 ~9 G V$ M; O. M" n# s& N- \
else
/ m' _7 w' l" G$ Q& | characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;8 o! w; Y5 j: H" e
i = 0;
6 y4 C4 F1 X+ [* g1 b+ Z while (1)
2 s! n7 v4 p* d8 z( D4 A {2 n* t5 U' ?2 h8 [2 }* T
if (fontContent == 0) break;9 }/ t$ A# z, |) A: ?7 v
if (fontContent & 0x80)' v8 q0 k' H5 o& i& C$ {
if (fontContent[i + 1] & 0x80)
3 p2 r" s% P5 F3 z9 g A! u if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312)8 k6 Y/ c6 J+ H; H
{! _( W+ ^% v# z" H
uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1);
" @' y, M* d' {+ k% g break;* Y) ~8 r5 `5 ~7 W, w
}/ F/ \; k' ]9 @$ L! J! `; A# K$ O
i++;
8 X) O9 l. u5 j# h7 W m7 Q( K }. u+ C: N. r, l. i8 Y
m_pTextBuilder->SetTextString(fontContent);
% P; p4 h- b. n# Q m_pTextBuilder->SelectFont(fontType, characterSet);
8 x Z( Y$ b4 Y. F7 i6 O3 @' ^0 N m_pTextBuilder->SetCanUseKerningSpaces(true);
* i$ Z* B6 E' H: J& C2 ~ m_pTextBuilder->SetCanReverseIntersectionCurve(true);
! q# P) t6 n- h$ b F x, y8 ^9 q- o$ f6 W7 f/ u) a7 m
NXOpen:irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),1 F0 }& r! u( F( F& A
Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8])),1 ?: }+ e4 L8 J
SmartObject::UpdateOption::UpdateOptionWithinModeling);
9 F) G" t% Q; T( {) A# n m_pTextBuilder->SetOrientationVector(orientationVector);/ D x, K5 I; m) c/ B' e
- W9 }! b& U) b1 _/ O: j, ?
m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);
& u5 W5 |! n, Y3 q9 X' V$ w/ q m_pTextBuilder->lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);. P$ V5 }2 L; F* q4 c# B+ h
% s- }+ c5 X& M- c7 f$ Z: W
i = strlen(fontContent);
+ z$ e; h* z; q: T0 n9 x char buf[256] = { 0 };
8 d* H8 r9 Q# ~# C/ s2 H) j sprintf(buf, "%f", i * 10 * (wScale / 50.0));+ R5 M% X i6 B3 P0 [
m_pTextBuilder->lanarFrame()->Length()->SetRightHandSide(buf);+ }: g4 a& N+ @( V
sprintf(buf, "%f", 10 * (wScale / 50.0));
% I: h. Y& X, I m_pTextBuilder->lanarFrame()->Height()->SetRightHandSide(buf);8 k4 W* U9 Z- u& |. l7 v
m_pTextBuilder->lanarFrame()->Shear()->SetRightHandSide("0");
7 f$ g0 e1 C, ^* K
, Y+ o) c* _: ^# F" j y4 J0 M2 S" s! k m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);
+ ~3 k" F' |+ m0 I) B& a m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");+ v! S. ]( h0 E' T8 h9 x0 z
m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");, {" c2 C1 ?7 b3 O& n+ ^0 t0 u
m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");9 w1 n' T; q F2 H/ v/ e
m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");
}* _0 A( Q9 }: w0 [8 w- I8 f h& ? @( {) E! c1 A
std::vector<NXOpen::Face *> boundaryFaces2(0);
1 w$ l l9 b+ G' c$ U7 U! H3 J( ^+ k NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);
8 k0 I s& f7 w4 }9 B" P. E* n; p std::vector<NXOpen::SelectionIntentRule *> rules2(1);
/ o2 g2 s8 w! M) Z7 K rules2[0] = faceTangentRule2;& _( i/ V- y C; v o9 @( x
m_pTextBuilder->lacementFaces()->ReplaceRules(rules2, false);
# x$ m, g9 Z$ u6 W: k! m* F1 ^* V3 f# A" M0 [ ~# D3 r
m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);
% J* i6 H9 O v* ?0 C$ ~ std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);
; D9 d1 Y, M3 h7 ]# \+ ^ CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);3 b& _6 Z1 x; S) \& w, m
NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1"));# f# M0 ]/ r4 N% D
NXOpen::Curve *nullNXOpen_Curve(NULL);1 U- M$ @5 N [
std::vector<NXOpen::SelectionIntentRule *> rules(1);
# t3 R9 ~* W# J% A rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);1 I- q& m& x5 |+ c2 a, k' @
m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);" }5 P$ Y1 i6 ]( ^' n$ d% a" N
NXOpen::NXObject *nullNXOpen_NXObject(NULL);
1 K7 V1 M: C8 `+ W5 r8 g NXOpen:oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);. r' n7 p) z( \( M* g3 T; k
m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,
' |9 e" `2 }. b U$ k6 }" N NXOpen::Section::ModeCreate, false);
8 x. a' e5 w& t, J/ O) _0 A) v8 Z3 E" |' L C7 z
if (bools)* i6 W1 B4 R7 q: R
{
* |' Y. U4 G& C3 l6 X3 S ; s+ b& x! a/ G' W# W( o
if (m_pTextBuilder->Validate()): k- [+ E0 t3 X& V5 f
{4 h& J) `8 I$ ?1 S, C
m_pTextObject = m_pTextBuilder->Commit();
- A$ o9 a2 ]' S' |( @4 J m_pTextBuilder->Destroy();
% E: J1 p7 h$ T3 w8 T m_pTextBuilder = NULL;
2 h- U7 F7 }1 }) j) X4 z! c1 g changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);
/ c3 W. d1 e! v7 I' H changeStringContent->SetSensitivity(false);
v! E/ }7 l' s, Z changeRealScale->SetSensitivity(false);+ m$ H- Q2 I2 z! m' I' G* e$ Y% j
}, b* F- `9 m$ P
2 n+ X! ?7 }* a( a; n
}
; h" D& I5 H' D' @: F' J else
7 T, q N9 {& M' l/ g { ' U1 A J1 a& g6 o; ]
// & ^2 o/ v! C" E
if (m_pTextBuilder->Validate())' ?2 w& y* O" U* }* \7 H" @
{
/ e8 X8 L, ^3 Y" `: E m_pTextBuilder->Commit();
9 X) y! \# ?, p) ^( Q UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible);& x z# W' @# e, z4 O- R2 N
m_pTextBuilder->Destroy();6 a1 l+ J- \, @; k1 |3 B$ O
m_pTextBuilder = NULL;) M T; i& q* Q4 f$ J& ~
}) \% i: g+ S1 } Q
} ; a& k# _; X9 d+ q
/ ]+ |( I& Z2 e2 |, y2 |! k) {}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!, J0 W/ r! {4 k
|
|