NX二次开发源码分享:报告选择尺寸的相关信息
Dimension* plmhome::select_a_dimension()
{
// ask user to select a label
UI *ui = UI::GetUI();
Selection *sm = ui->SelectionManager();
NXMessageBox *mb = ui->NXMessageBox(); // as of NX5
NXString message("Select Dimension:");
NXString title("Select Dimension");
Selection::SelectionScope scope = Selection::SelectionScopeUseDefault;
Selection::SelectionAction action = Selection::SelectionActionClearAndEnableSpecific;
bool include_features = 0;
bool keep_highlighted = 0;
// Define the mask triple(s)
std::vector<Selection::MaskTriple> mask(1);
mask = Selection::MaskTriple( UF_dimension_type, 0, 0 );
Point3d cursor;
TaggedObject *object;
// Select objects using filter defined by mask triples
Selection::Response res = sm->SelectTaggedObject(
message, title, scope, action, include_features,
keep_highlighted, mask, &object, &cursor );
if( res == Selection::ResponseObjectSelected )
{
Annotations::Dimension *theDim;
// this doesn't work and 'note' will be a zero pointer, see PR-1850850
//note = dynamic_cast<Annotations::PmiNote *>(object);
// this works as a workaround
theDim = (Annotations::Dimension *)(object);
return theDim;
}
return 0;
}
void plmhome::do_it()
{
workPart = theSession->Parts()->Work();
Part *displayPart = theSession->Parts()->Display();
stringstream out;
Dimension *theDim = 0;
NXString tolTypeStrings[] =
{
"ToleranceTypeNone",
"ToleranceTypeLimitOneLine",
"ToleranceTypeLimitTwoLines",
"ToleranceTypeBilateralOneLine",
"ToleranceTypeBilateralTwoLines",
"ToleranceTypeUnilateralAbove",
"ToleranceTypeUnilateralBelow",
"ToleranceTypeBasic",
"ToleranceTypeReference",
"ToleranceTypeLimitLargerFirst",
"ToleranceTypeLimitLargerBelow",
"ToleranceTypeLimitsAndFits",
"ToleranceTypeNotToScale",
"ToleranceTypeDiameterReference",
"ToleranceTypeBasicNotToScale"
};
while( (theDim=select_a_dimension()) != 0 )
{
out.str(""); out.clear();
if(! lw->IsOpen() ) lw->Open();
out << "Selected Object: " << theDim->Tag() << endl;
std::vector<NXString> mainTextLines;
std::vector<NXString> dualTextLines;
theDim->GetDimensionText(mainTextLines, dualTextLines);
for( int ii=0; ii<mainTextLines.size(); ii++)
out << " MainTextLine: " << mainTextLines.GetText() << endl;
for( int ii=0; ii<dualTextLines.size(); ii++)
out << " DualTextLine: " << dualTextLines.GetText() << endl;
bool refFlag = theDim->ReferenceDimensionFlag();
out << " ReferenceDimensionFlag: " << refFlag << endl;
int tolType = (int) theDim->ToleranceType();
out << " ToleranceType: " << tolTypeStrings.GetText() << endl;
ComponentData *theData = displayPart->Annotations()->CreateComponentData(theDim);
std::vector<TextComponent*> textComps = theData->GetTextComponents();
for( int ii=0; ii<textComps.size(); ii++)
{
std::vector<NXString> compText = textComps->GetText();
for( int jj=0; jj<compText.size(); jj++ )
out << " Component Text: " << compText.GetText() << endl;
}
int subtype;
double origin;
UF_DRF_dim_info_t *info;
UF_CALL(UF_DRF_ask_dim_info(theDim->Tag(), &subtype, origin, &info));
for (int ii = 0; ii<info->num_text; ii++)
if (info->text_info.text_type == UF_DRF_DIM_TEXT)
for (int jj = 0; jj < info->text_info.num_lines; jj++)
out << " UF_DRF_ask_dim_info Text: " << info->text_info.text.string << endl;
UF_CALL(UF_DRF_free_dimension(&info));
lw->WriteLine(out.str().c_str());
} // while
}
页:
[1]