二次开发NXOpenC++中NXOpen::Features::TextBuilder对象如何实现预览功
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:void Letter::textProcess(const char * fontContent, char* fontType, double& wScale,bool bools)
{
if (m_pTextBuilder == NULL)
m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts);
int i = 0;
m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);
m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);
NXOpen::Features::TextBuilder::ScriptOptions characterSet;
if (fontType >= 'A'&&fontType <= 'z')
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;
else
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;
i = 0;
while (1)
{
if (fontContent == 0) break;
if (fontContent & 0x80)
if (fontContent & 0x80)
if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312)
{
uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1);
break;
}
i++;
}
m_pTextBuilder->SetTextString(fontContent);
m_pTextBuilder->SelectFont(fontType, characterSet);
m_pTextBuilder->SetCanUseKerningSpaces(true);
m_pTextBuilder->SetCanReverseIntersectionCurve(true);
NXOpen::Direction * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint, m_pnPoint, m_pnPoint),
Vector3d((m_pnPoint - m_pnPoint), (m_pnPoint - m_pnPoint), (m_pnPoint - m_pnPoint)),
SmartObject::UpdateOption::UpdateOptionWithinModeling);
m_pTextBuilder->SetOrientationVector(orientationVector);
m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);
m_pTextBuilder->;PlanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);
i = strlen(fontContent);
char buf = { 0 };
sprintf(buf, "%f", i * 10 * (wScale / 50.0));
m_pTextBuilder->;PlanarFrame()->Length()->SetRightHandSide(buf);
sprintf(buf, "%f", 10 * (wScale / 50.0));
m_pTextBuilder->;PlanarFrame()->Height()->SetRightHandSide(buf);
m_pTextBuilder->;PlanarFrame()->Shear()->SetRightHandSide("0");
m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);
m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");
m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");
m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");
m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");
std::vector<NXOpen::Face *> boundaryFaces2(0);
NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);
std::vector<NXOpen::SelectionIntentRule *> rules2(1);
rules2 = faceTangentRule2;
m_pTextBuilder->;PlacementFaces()->ReplaceRules(rules2, false);
m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);
std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);
CurveOnSurfaceFeatures = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);
NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures->FindObject("CURVE 1"));
NXOpen::Curve *nullNXOpen_Curve(NULL);
std::vector<NXOpen::SelectionIntentRule *> rules(1);
rules = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);
m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);
NXOpen::NXObject *nullNXOpen_NXObject(NULL);
NXOpen::Point3d helpPoint1(m_pnPoint, -m_pnPoint, m_pnPoint);
m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,
NXOpen::Section::ModeCreate, false);
if (bools)
{
if (m_pTextBuilder->Validate())
{
m_pTextObject = m_pTextBuilder->Commit();
m_pTextBuilder->Destroy();
m_pTextBuilder = NULL;
changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);
changeStringContent->SetSensitivity(false);
changeRealScale->SetSensitivity(false);
}
}
else
{
//
if (m_pTextBuilder->Validate())
{
m_pTextBuilder->Commit();
UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible);
m_pTextBuilder->Destroy();
m_pTextBuilder = NULL;
}
}
}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!
预览就是你先commit 生成,然后设置下透明度 而已 这个是不可行的,commit会生成一个实体的,这个不是我们想要的结果.其实我发完帖子不就之后就知道如何解决了.设置 撤销操作即可
theSession->SetUndoMark();
theSession->UndoToMark();
theSession->DeleteUndoMark();
这样是没问题的,速度又很快.
但是问题又来了:
在拉伸的时候出现 err:the tool and target do not form a complete intersection ...嘿嘿 我知道如何解决了 ,最后双向拉伸就好了 这是布尔运算造成的... 浮游 发表于 2015-8-25 18:07
...嘿嘿 我知道如何解决了 ,最后双向拉伸就好了 这是布尔运算造成的...
m_pTextObject 这个nxobject对象如何使用到后面拉伸所用的截面线的呢?需要转化? 浮游 发表于 2015-8-25 17:56
这个是不可行的,commit会生成一个实体的,这个不是我们想要的结果.其实我发完帖子不就之后就知道如何解决了. ...
要预览的代码你放在哪里,我放在update中,但是生成的模型无法再撤回了,求指点一下
页:
[1]