- Add poles with array of descriptions and description names to DimensionObject,
- Modify Import/Export STEP,
- Add Draw commands for descriptions,
- Create test,
- Reorganize end script for test/gdt/dimensions.
Handle(StepShape_DimensionalLocation) aDimLocation =
Handle(StepShape_DimensionalLocation)::DownCast(theEnt);
+ aDimObj = new XCAFDimTolObjects_DimensionObject();
Standard_Real aDim1=-1.,aDim2=-1.,aDim3=-1.;
Handle(StepShape_TypeQualifier) aTQ;
Handle(StepShape_ValueFormatTypeQualifier) aVFTQ;
aVFTQ = aQRI->Qualifiers()->Value(l).ValueFormatTypeQualifier();
}
}
+ else if (aDRI->IsKind(STANDARD_TYPE(StepRepr_DescriptiveRepresentationItem))) {
+ Handle(StepRepr_DescriptiveRepresentationItem) aDescription =
+ Handle(StepRepr_DescriptiveRepresentationItem)::DownCast(aDRI);
+ aDimObj->AddDescription(aDescription->Description(), aDescription->Name());
+ }
else if(aDRI->IsKind(STANDARD_TYPE(StepRepr_CompoundRepresentationItem))) {
aCRI = Handle(StepRepr_CompoundRepresentationItem)::DownCast(aDRI);
}
if(aDim1<0) return;
- aDimObj = new XCAFDimTolObjects_DimensionObject();
if(aDim2 < 0)
aDimObj->SetValue(aDim1);
else if (aDim3 < 0)
#include <XSControl_TransferWriter.hxx>
#include <XSControl_WorkSession.hxx>
-enum DimensionalValueNumber {
- DimensionalValueNumber_Nominal = 1,
- DimensionalValueNumber_Lower,
- DimensionalValueNumber_Upper
-};
static NCollection_Vector<Handle(StepVisual_AnnotationPlane)> gdtAnnotationPlanes;
static Handle(StepVisual_DraughtingModel) gdtPresentationDM;
static Handle(StepVisual_HArray1OfPresentationStyleAssignment) gdtPrsCurveStyle;
// Values
Handle(StepRepr_HArray1OfRepresentationItem) aValues;
- Standard_Integer aNbValItems = 1, aNbAddItems = 0;
+ Standard_Integer aNbItems = 1, aValIt = 1;
if (theObject->IsDimWithRange())
- aNbValItems += 2;
+ aNbItems += 2;
if (aModifiers.Length() > 0)
- aNbAddItems++;
+ aNbItems++;
if (theObject->GetType() == XCAFDimTolObjects_DimensionType_Location_Oriented)
- aNbAddItems++;
- aValues = new StepRepr_HArray1OfRepresentationItem(1, aNbValItems + aNbAddItems);
+ aNbItems++;
+ aNbItems += theObject->NbDescriptions();
+ aValues = new StepRepr_HArray1OfRepresentationItem(1, aNbItems);
// Nominal value
Standard_Real aNominal = theObject->GetValue();
aQRI->SetQualifiers(aQualifiers);
Handle(StepRepr_ReprItemAndMeasureWithUnit) anItem = CreateDimValue(aNominal, aUnit,
new TCollection_HAsciiString("nominal value"), aMeasureName, isAngle, Standard_True, aQRI);
- aValues->SetValue(DimensionalValueNumber_Nominal, anItem);
+ aValues->SetValue(aValIt, anItem);
+ aValIt++;
}
// Without qualifiers
else {
Handle(StepRepr_ReprItemAndMeasureWithUnit) anItem = CreateDimValue(aNominal, aUnit,
new TCollection_HAsciiString("nominal value"), aMeasureName, isAngle);
- aValues->SetValue(DimensionalValueNumber_Nominal, anItem);
+ aValues->SetValue(aValIt, anItem);
+ aValIt++;
}
+
// Ranges
if (theObject->IsDimWithRange()) {
Handle(StepRepr_ReprItemAndMeasureWithUnit) aLowerItem = CreateDimValue(theObject->GetLowerBound(), aUnit,
new TCollection_HAsciiString("lower limit"), aMeasureName, isAngle);
Handle(StepRepr_ReprItemAndMeasureWithUnit) anUpperItem = CreateDimValue(theObject->GetUpperBound(), aUnit,
new TCollection_HAsciiString("upper limit"), aMeasureName, isAngle);
- aValues->SetValue(DimensionalValueNumber_Lower, aLowerItem);
- aValues->SetValue(DimensionalValueNumber_Upper, anUpperItem);
+ aValues->SetValue(aValIt, aLowerItem);
+ aValIt++;
+ aValues->SetValue(aValIt, anUpperItem);
+ aValIt++;
}
// Modifiers
aModifItems->SetValue(i, aModifItem);
}
aCompoundRI->Init(new TCollection_HAsciiString(), aModifItems);
- aValues->SetValue(aNbValItems + 1, aCompoundRI);
+ aValues->SetValue(aValIt, aCompoundRI);
+ aValIt++;
}
// Orientation
aCoords->SetValue(3, aDir.Z());
anAxis->Init(new TCollection_HAsciiString(), aCoords);
anOrientation->Init(new TCollection_HAsciiString("orientation"), aLoc, Standard_True, anAxis, Standard_False, NULL);
- aValues->SetValue(aValues->Length(), anOrientation);
+ aValues->SetValue(aValIt, anOrientation);
+ aValIt++;
+ }
+
+ // Descriptions
+ if (theObject->HasDescriptions()) {
+ for (Standard_Integer i = 0; i < theObject->NbDescriptions(); i++) {
+ Handle(StepRepr_DescriptiveRepresentationItem) aDRI = new StepRepr_DescriptiveRepresentationItem();
+ aDRI->Init(theObject->GetDescriptionName(i), theObject->GetDescription(i));
+ aValues->SetValue(aValIt, aDRI);
+ aValIt++;
+ }
}
for (Standard_Integer i = 1; i <= aValues->Length(); i++)
#include <Precision.hxx>
#include <TColgp_HArray1OfPnt.hxx>
-
IMPLEMENT_STANDARD_RTTIEXT(XCAFDimTolObjects_DimensionObject,Standard_Transient)
//=======================================================================
{
myPnts = thePnts;
}
+
+//=======================================================================
+//function : RemoveDescription
+//purpose :
+//=======================================================================
+void XCAFDimTolObjects_DimensionObject::RemoveDescription(const Standard_Integer theNumber)
+{
+ if (theNumber < myDescriptions.Lower() || theNumber > myDescriptions.Upper())
+ return;
+ NCollection_Vector<Handle(TCollection_HAsciiString)> aDescriptions;
+ NCollection_Vector<Handle(TCollection_HAsciiString)> aDescriptionNames;
+ for (Standard_Integer i = aDescriptions.Lower(); i < theNumber; i++) {
+ aDescriptions.Append(myDescriptions.Value(i));
+ aDescriptionNames.Append(myDescriptionNames.Value(i));
+ }
+ for (Standard_Integer i = theNumber + 1; i <= aDescriptions.Upper(); i++) {
+ aDescriptions.Append(myDescriptions.Value(i));
+ aDescriptionNames.Append(myDescriptionNames.Value(i));
+ }
+ myDescriptions = aDescriptions;
+ myDescriptionNames = aDescriptionNames;
+}
#include <Standard_Real.hxx>
#include <XCAFDimTolObjects_DimensionModif.hxx>
#include <TCollection_HAsciiString.hxx>
+#include <NCollection_Vector.hxx>
+#include <TColStd_HArray1OfExtendedString.hxx>
class XCAFDimTolObjects_DimensionObject;
DEFINE_STANDARD_HANDLE(XCAFDimTolObjects_DimensionObject, Standard_Transient)
Standard_EXPORT Standard_Boolean HasPoints() const { return (!myPnts.IsNull() && myPnts->Length() > 0); }
-
-
//! Set graphical presentation for object
Standard_EXPORT void SetPresentation(const TopoDS_Shape& thePresentation,
const Handle(TCollection_HAsciiString)& thePresentationName)
return myPresentationName;
}
+ //! Returns true, if the object has descriptions
+ Standard_EXPORT Standard_Boolean HasDescriptions() const
+ {
+ return (myDescriptions.Length() > 0);
+ }
+
+ //! Returns number of descriptions
+ Standard_EXPORT Standard_Integer NbDescriptions() const
+ {
+ return myDescriptions.Length();
+ }
+
+ //! Returns description with the given number
+ Standard_EXPORT Handle(TCollection_HAsciiString) GetDescription(const Standard_Integer theNumber) const
+ {
+ if (theNumber < myDescriptions.Lower() || theNumber > myDescriptions.Upper())
+ return new TCollection_HAsciiString();
+ return myDescriptions.Value(theNumber);
+ }
+
+ //! Returns name of description with the given number
+ Standard_EXPORT Handle(TCollection_HAsciiString) GetDescriptionName(const Standard_Integer theNumber) const
+ {
+ if (theNumber < myDescriptions.Lower() || theNumber > myDescriptions.Upper())
+ return new TCollection_HAsciiString();
+ return myDescriptionNames.Value(theNumber);
+ }
+
+ //! Remove description with the given number
+ Standard_EXPORT void RemoveDescription(const Standard_Integer theNumber);
+
+ //! Add new description
+ Standard_EXPORT void AddDescription(const Handle(TCollection_HAsciiString) theDescription, const Handle(TCollection_HAsciiString) theName)
+ {
+ myDescriptions.Append(theDescription);
+ myDescriptionNames.Append(theName);
+ }
+
DEFINE_STANDARD_RTTIEXT(XCAFDimTolObjects_DimensionObject,Standard_Transient)
private:
gp_Pnt myPntText;
TopoDS_Shape myPresentation;
Handle(TCollection_HAsciiString) myPresentationName;
+ NCollection_Vector<Handle(TCollection_HAsciiString)> myDescriptions;
+ NCollection_Vector<Handle(TCollection_HAsciiString)> myDescriptionNames;
};
#include <TColgp_HArray1OfPnt.hxx>
#include <TDataStd_Integer.hxx>
#include <TDataStd_IntegerArray.hxx>
+#include <TDataStd_ExtStringArray.hxx>
#include <TDataStd_Real.hxx>
#include <TDataStd_RealArray.hxx>
#include <TNaming_Builder.hxx>
ChildLab_PlaneN,
ChildLab_PlaneRef,
ChildLab_PntText,
- ChildLab_Presentation
-
+ ChildLab_Presentation,
+ ChildLab_Descriptions,
+ ChildLab_DescriptionNames
};
//=======================================================================
TDataStd_Name::Set ( aLPres, str );
}
}
-
+
+ if (theObject->HasDescriptions())
+ {
+ Handle(TDataStd_ExtStringArray) aDescriptions = new TDataStd_ExtStringArray();
+ Handle(TDataStd_ExtStringArray) aDescriptionNames = new TDataStd_ExtStringArray();
+ Handle(TColStd_HArray1OfExtendedString) aDescrArr = new TColStd_HArray1OfExtendedString(1, theObject->NbDescriptions());
+ Handle(TColStd_HArray1OfExtendedString) aDescrNameArr = new TColStd_HArray1OfExtendedString(1, theObject->NbDescriptions());
+ for (Standard_Integer i = 0; i < theObject->NbDescriptions(); i++) {
+ TCollection_ExtendedString aDescr(theObject->GetDescription(i)->String());
+ aDescrArr->SetValue(i + 1, aDescr);
+ TCollection_ExtendedString aDescrName(theObject->GetDescriptionName(i)->String());
+ aDescrNameArr->SetValue(i + 1, aDescrName);
+ }
+ aDescriptions->ChangeArray(aDescrArr);
+ aDescriptionNames->ChangeArray(aDescrNameArr);
+ Label().FindChild(ChildLab_Descriptions).AddAttribute(aDescriptions);
+ Label().FindChild(ChildLab_DescriptionNames).AddAttribute(aDescriptionNames);
+ }
}
//=======================================================================
anObj->SetPresentation(aPresentation, aPresentName);
}
}
+
+ Handle(TDataStd_ExtStringArray) aDescriptions, aDescriptionNames;
+ if (Label().FindChild(ChildLab_Descriptions).FindAttribute(TDataStd_ExtStringArray::GetID(), aDescriptions) &&
+ Label().FindChild(ChildLab_DescriptionNames).FindAttribute(TDataStd_ExtStringArray::GetID(), aDescriptionNames)) {
+ for (Standard_Integer i = 1; i <= aDescriptions->Length(); i++) {
+ Handle(TCollection_HAsciiString) aDescription, aDescriptionName;
+ aDescription = new TCollection_HAsciiString(TCollection_AsciiString(aDescriptions->Value(i)));
+ aDescriptionName = new TCollection_HAsciiString(TCollection_AsciiString(aDescriptionNames->Value(i)));
+ anObj->AddDescription(aDescription, aDescriptionName);
+ }
+ }
return anObj;
}
static Standard_Integer getDimDir (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
if (argc < 3) {
- di<<"Use: XSetDimensionDir Doc Dim_Label\n";
+ di<<"Use: XGetDimensionDir Doc Dim_Label\n";
return 1;
}
Handle(TDocStd_Document) Doc;
return 0;
}
+static Standard_Integer addDimDescr (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+{
+ if (argc < 4) {
+ di<<"Use: XAddDimensionDescr Doc Dim_Label Description [DescriptionName]\n";
+ return 1;
+ }
+ Handle(TDocStd_Document) Doc;
+ DDocStd::GetDocument(argv[1], Doc);
+ if ( Doc.IsNull() ) {
+ di << argv[1] << " is not a document\n";
+ return 1;
+ }
+
+ TDF_Label aLabel;
+ TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
+ if ( aLabel.IsNull() )
+ {
+ di << "Dimension "<< argv[2] << " is absent in " << argv[1] << "\n";
+ return 1;
+ }
+ Handle(XCAFDoc_Dimension) aDimension;
+ if(aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
+ {
+ Handle(XCAFDimTolObjects_DimensionObject) anObj = aDimension->GetObject();
+ Handle(TCollection_HAsciiString) aDescription = new TCollection_HAsciiString(argv[3]);
+ Handle(TCollection_HAsciiString) aDescrName = (argc == 4) ? new TCollection_HAsciiString()
+ : new TCollection_HAsciiString(argv[4]);
+ anObj->AddDescription(aDescription, aDescrName);
+ aDimension->SetObject(anObj);
+ }
+ return 0;
+}
+
+static Standard_Integer getDimDescr (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+{
+ if (argc < 3) {
+ di << "Use: XGetDimensionDescr Doc Dim_Label\n";
+ return 1;
+ }
+ Handle(TDocStd_Document) Doc;
+ DDocStd::GetDocument(argv[1], Doc);
+ if ( Doc.IsNull() ) {
+ di << argv[1] << " is not a document\n";
+ return 1;
+ }
+
+ TDF_Label aLabel;
+ TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
+ if ( aLabel.IsNull() )
+ {
+ di << "Dimension "<< argv[2] << " is absent in " << argv[1] << "\n";
+ return 1;
+ }
+ Handle(XCAFDoc_Dimension) aDimension;
+ if(aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension))
+ {
+ Handle(XCAFDimTolObjects_DimensionObject) anObject = aDimension->GetObject();
+ for (Standard_Integer i = 0; i < anObject->NbDescriptions(); i++) {
+ Handle(TCollection_HAsciiString) aDescription = anObject->GetDescription(i);
+ Handle(TCollection_HAsciiString) aDescrName = anObject->GetDescriptionName(i);
+ di << "name: " << aDescrName->ToCString() << " description: " << aDescription->ToCString() << "\n";
+ }
+ }
+ return 0;
+}
+
//=======================================================================
//function : InitCommands
//purpose :
di.Add ("XGetDimensionDir","XGetDimensionDir Doc Dim_Label",
__FILE__, getDimDir, g);
+
+ di.Add ("XAddDimensionDescr","XAddDimensionDescr Doc Dim_Label Description [DescriptionName]\n"
+ "Add named text description to given Dimension, if DescriptionName is missed"
+ "name will be an empty string.",
+ __FILE__, addDimDescr, g);
+
+ di.Add ("XGetDimensionDescr","XGetDimensionDescr Doc Dim_Label\n"
+ "Return all descriptions of given Dimension.",
+ __FILE__, getDimDescr, g);
}
--- /dev/null
+# test text descriptions
+box b 10 10 10
+explode b e
+
+NewDocument D_init
+XAddShape D_init b
+XAddDimension D_init b_1
+#0:1:4:1
+XSetDimensionType D_init 0:1:4:1 14
+XSetDimensionValue D_init 0:1:4:1 10
+XAddDimensionDescr D_init 0:1:4:1 description1
+XAddDimensionDescr D_init 0:1:4:1 description2 name2
+# Export
+set isOK 1
+if { [catch { WriteStep D_init $imagedir/${casename}_D_init.stp } catch_result] } {
+ puts "Error: File was not written - exception"
+ set isOK 0
+ }
+# Import
+if {$isOK} {
+ if { [catch { ReadStep D $imagedir/${casename}_D_init.stp } catch_result] } {
+ puts "Error: File was not read - exception"
+ set isOK 0
+ }
+ }
+# Reference data
+if {$isOK} {
+set c_value "10"
+set c_type "Size_CurveLength"
+set c_descr {name: description: description1
+name: name2 description: description2
+}
+}
set c_range 0
set c_mod 0
set c_plusminus 0
-set c_dump 0
\ No newline at end of file
+set c_dump 0
+set c_descr 0
+# value
set value [XGetDimensionValue D 0:1:4:1]
+if { $c_value != 0 && $value != $c_value} {
+ puts "Error: wrong value"
+}
+# type
set type [XGetDimensionType D 0:1:4:1]
+if { $c_type != 0 && [string compare $type $c_type] != 0} {
+ puts "Error: wrong type"
+}
+# qualifier
set qualif [XGetDimensionQualifier D 0:1:4:1]
-set range [XGetDimensionRange D 0:1:4:1]
+if { $c_qalif != 0 && [string compare $qualif $c_qalif] != 0} {
+ puts "Error: wrong qualifier"
+}
+# tolerance class
set classtol [XGetDimensionClassOfTol D 0:1:4:1]
+if { $c_classtol != 0 && $classtol != $c_classtol} {
+ puts "Error: wrong class of tolerance"
+}
+# number of decimal digits
set d [XGetDimensionNbOfDecimalPlaces D 0:1:4:1]
+if { $c_d != 0 && $d != $c_d} {
+ puts "Error: wrong number of decimal digits"
+}
+# modifiers
+if { $c_modif != 0 && [string compare $modif $c_modif] != 0} {
+ puts "Error: wrong modifiers"
+}
+# direction
set dir [XGetDimensionDir D 0:1:4:1]
+if { $c_dir != 0 && [string compare $dir $c_dir] != 0} {
+ puts "Error: wrong direction"
+}
+#points
set pnts [XGetDimensionPoints D 0:1:4:1]
+if { $c_pnts != 0 && [string compare $pnts $c_pnts] != 0} {
+ puts "Error: wrong points"
+}
+# range
+set range [XGetDimensionRange D 0:1:4:1]
+if { $c_range != 0 && [string compare $range $c_range] != 0} {
+ puts "Error: wrong range"
+}
+# modifiers
set mod [XGetDimensionModifiers D 0:1:4:1]
+if { $c_mod != 0 && [string compare $mod $c_mod] != 0} {
+ puts "Error: wrong modifiers"
+}
+# plus minus tolerance
set plusminus [XGetDimensionPlusMinusTol D 0:1:4:1]
-set dump [XDumpDGTs D all]
-
-if { $c_value != 0 && $value != $c_value} {
- puts "Error wrong value"
-} else {
- if { $c_type != 0 && [string compare $type $c_type] != 0} {
- puts "Error wrong type"
+if { $c_plusminus != 0 && [string compare $plusminus $c_plusminus] != 0} {
+ puts "Error: wrong plus minus tolerance"
+}
+# descriptions
+set descriptions [XGetDimensionDescr D 0:1:4:1]
+if {$c_descr != 0} {
+ set ref_list [split $descriptions \n]
+ set cur_list [split $c_descr \n]
+ set nb_ref [llength $ref_list]
+ set nb_cur [llength $cur_list]
+ if {$nb_ref != $nb_cur} {
+ puts "Error: wrong number of descriptions"
} else {
- if { $c_qalif != 0 && [string compare $qualif $c_qalif] != 0} {
- puts "Error wrong qualifier"
- } else {
- if { $c_classtol != 0 && $classtol != $c_classtol} {
- puts "Error wrong class of tolerance"
- } else {
- if { $c_d != 0 && $d != $c_d} {
- puts "Error wrong nbdigit"
- } else {
- if { $c_modif != 0 && [string compare $modif $c_modif] != 0} {
- puts "Error wrong modifiers"
- } else {
- if { $c_dir != 0 && [string compare $dir $c_dir] != 0} {
- puts "Error wrong direction"
- } else {
- if { $c_pnts != 0 && [string compare $pnts $c_pnts] != 0} {
- puts "Error wrong points"
- } else {
- if { $c_range != 0 && [string compare $range $c_range] != 0} {
- puts "Error wrong range"
- } else {
- if { $c_mod != 0 && [string compare $mod $c_mod] != 0} {
- puts "Error wrong modifiers"
- } else {
- if { $c_plusminus != 0 && [string compare $plusminus $c_plusminus] != 0} {
- puts "Error wrong modifiers"
- } else {
- puts "TEST COMPLETED"
- }
- }
- }
- }
- }
- }
- }
+ for { set i 0 } { $i < $nb_ref } { incr i } {
+ set refstr [lindex $ref_list $i]
+ set curstr [lindex $cur_list $i]
+ set isOK 1;
+
+ if {[string equal $refstr $curstr] == 0} {
+ set isOK 0
}
}
}
+ if {$isOK == 0} {
+ puts "Error: wrong descriptions"
+ }
}
+
+puts "TEST COMPLETED"