From f0bf70e8cca22bb360df7a72fb6bf2cd92fb7ccd Mon Sep 17 00:00:00 2001 From: ika Date: Thu, 7 Apr 2016 14:57:51 +0300 Subject: [PATCH] 0027372: Import/Export dimension text position Modify Import/Export STEP. Add Draw commands to set and get orientation and position of dimension text. Add Draw commands to set and get presentation. Add test. --- .../STEPCAFControl_GDTProperty.cxx | 4 +- src/STEPCAFControl/STEPCAFControl_Reader.cxx | 18 +- src/STEPCAFControl/STEPCAFControl_Writer.cxx | 14 +- src/XDEDRAW/XDEDRAW_GDTs.cxx | 212 ++++++++++++++++++ tests/gdt/dimensions/A8 | 38 ++++ tests/gdt/dimensions/begin | 1 + tests/gdt/dimensions/end | 31 ++- 7 files changed, 303 insertions(+), 15 deletions(-) create mode 100644 tests/gdt/dimensions/A8 diff --git a/src/STEPCAFControl/STEPCAFControl_GDTProperty.cxx b/src/STEPCAFControl/STEPCAFControl_GDTProperty.cxx index 1d4d0c4ae4..4415930892 100644 --- a/src/STEPCAFControl/STEPCAFControl_GDTProperty.cxx +++ b/src/STEPCAFControl/STEPCAFControl_GDTProperty.cxx @@ -975,12 +975,12 @@ Handle(StepGeom_Axis2Placement3d) STEPCAFControl_GDTProperty::GetAxis2Placement3 Handle(StepGeom_Direction) anAxis, aRefDirection; Handle(TColStd_HArray1OfReal) anAxisCoords = new TColStd_HArray1OfReal(1, 3); for (Standard_Integer i = 1; i <= 3; i++) - anAxisCoords->SetValue(i, theAxis.Direction().Coord(i)); + anAxisCoords->SetValue(i, theAxis.XDirection().Coord(i)); anAxis = new StepGeom_Direction(); anAxis->Init(new TCollection_HAsciiString(), anAxisCoords); Handle(TColStd_HArray1OfReal) aDirCoords = new TColStd_HArray1OfReal(1, 3); for (Standard_Integer i = 1; i <= 3; i++) - aDirCoords->SetValue(i, theAxis.XDirection().Coord(i)); + aDirCoords->SetValue(i, theAxis.YDirection().Coord(i)); aRefDirection = new StepGeom_Direction(); aRefDirection->Init(new TCollection_HAsciiString(), aDirCoords); anA2P3D->Init(new TCollection_HAsciiString(), aPoint, Standard_True, anAxis, Standard_True, aRefDirection); diff --git a/src/STEPCAFControl/STEPCAFControl_Reader.cxx b/src/STEPCAFControl/STEPCAFControl_Reader.cxx index 8022832dd2..9c1f24a8ca 100644 --- a/src/STEPCAFControl/STEPCAFControl_Reader.cxx +++ b/src/STEPCAFControl/STEPCAFControl_Reader.cxx @@ -1805,27 +1805,21 @@ void readAnnotation(const Handle(XSControl_TransferReader)& theTR, if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_DimensionObject))) { Handle(XCAFDimTolObjects_DimensionObject) anObj = Handle(XCAFDimTolObjects_DimensionObject)::DownCast(theDimObject); - Handle(TColgp_HArray1OfPnt) aPnts = new TColgp_HArray1OfPnt(1, 1); anObj->SetPlane(aPlaneAxes); - - } else if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_DatumObject))) { Handle(XCAFDimTolObjects_DatumObject) anObj = Handle(XCAFDimTolObjects_DatumObject)::DownCast(theDimObject); anObj->SetPlane(aPlaneAxes); - } else if (theDimObject->IsKind(STANDARD_TYPE(XCAFDimTolObjects_GeomToleranceObject))) { Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = Handle(XCAFDimTolObjects_GeomToleranceObject)::DownCast(theDimObject); anObj->SetPlane(aPlaneAxes); - } } - // Retrieve presentation Handle(StepVisual_AnnotationCurveOccurrence) anACO; NCollection_Vector aTesselations; @@ -1953,11 +1947,21 @@ void readAnnotation(const Handle(XSControl_TransferReader)& theTR, if(!nbShapes) return; gp_Pnt aPtext(0., 0., 0.); + // if Annotation plane location inside bounding box set it to text position + // else set the center of bounding box to text position if(!aBox.IsVoid()) { Standard_Real aXmin, aYmin, aZmin,aXmax, aYmax, aZmax; aBox.Get(aXmin, aYmin, aZmin,aXmax, aYmax, aZmax); - aPtext = gp_Pnt((aXmin + aXmax) * 0.5, (aYmin + aYmax) * 0.5, (aZmin + aZmax) * 0.5); + if (isHasPlane && !aBox.IsOut(aPlaneAxes.Location())) { + aPtext = aPlaneAxes.Location(); + } + else { + aPtext = gp_Pnt((aXmin + aXmax) * 0.5, (aYmin + aYmax) * 0.5, (aZmin + aZmax) * 0.5); + } + } + else { + aPtext = aPlaneAxes.Location(); } // set point to XCAF diff --git a/src/STEPCAFControl/STEPCAFControl_Writer.cxx b/src/STEPCAFControl/STEPCAFControl_Writer.cxx index 9bc98894e1..09aa5f3162 100644 --- a/src/STEPCAFControl/STEPCAFControl_Writer.cxx +++ b/src/STEPCAFControl/STEPCAFControl_Writer.cxx @@ -2322,6 +2322,7 @@ static Handle(StepRepr_ShapeAspect) WriteShapeAspect (const Handle(XSControl_Wor static void WritePresentation(const Handle(XSControl_WorkSession) &WS, const TopoDS_Shape thePresentation, const gp_Ax2 theAnnotationPlane, + const gp_Pnt theTextPosition, const Handle(Standard_Transient) theDimension) { if (thePresentation.IsNull()) @@ -2365,6 +2366,13 @@ static void WritePresentation(const Handle(XSControl_WorkSession) &WS, // Plane Handle(StepGeom_Plane) aPlane = new StepGeom_Plane(); Handle(StepGeom_Axis2Placement3d) anAxis = STEPCAFControl_GDTProperty::GetAxis2Placement3D(theAnnotationPlane); + // Set text position to plane origin + Handle(StepGeom_CartesianPoint) aTextPos = new StepGeom_CartesianPoint(); + Handle(TColStd_HArray1OfReal) aCoords = new TColStd_HArray1OfReal(1, 3); + for (Standard_Integer i = 1; i <= 3; i++) + aCoords->SetValue(i, theTextPosition.Coord(i)); + aTextPos->Init(new TCollection_HAsciiString(), aCoords); + anAxis->SetLocation(aTextPos); aPlane->Init(new TCollection_HAsciiString(), anAxis); // Annotation plane element StepVisual_AnnotationPlaneElement aPlaneElement; @@ -2576,7 +2584,7 @@ static Handle(StepDimTol_Datum) WriteDatumAP242(const Handle(XSControl_WorkSessi Model->AddWithRefs(aSDR); //Annotation plane and Presentation - WritePresentation(WS, anObject->GetPresentation(), anObject->GetPlane(), aSA); + WritePresentation(WS, anObject->GetPresentation(), anObject->GetPlane(), anObject->GetPointTextAttach(), aSA); return aDatum; } @@ -3187,7 +3195,7 @@ static void WriteGeomTolerance (const Handle(XSControl_WorkSession) &WS, Model->AddWithRefs(aGeomTol); WriteToleranceZone(WS, anObject, aGeomTol, theRC); //Annotation plane and Presentation - WritePresentation(WS, anObject->GetPresentation(), anObject->GetPlane(), aGeomTol); + WritePresentation(WS, anObject->GetPresentation(), anObject->GetPlane(), anObject->GetPointTextAttach(), aGeomTol); } //======================================================================= @@ -3747,7 +3755,7 @@ Standard_Boolean STEPCAFControl_Writer::WriteDGTsAP242 (const Handle(XSControl_W // Write values WriteDimValues(WS, anObject, aRC, aDimension); //Annotation plane and Presentation - WritePresentation(WS, anObject->GetPresentation(), anObject->GetPlane(), aDimension.Value()); + WritePresentation(WS, anObject->GetPresentation(), anObject->GetPlane(), anObject->GetPointTextAttach(), aDimension.Value()); } //----------------------------// diff --git a/src/XDEDRAW/XDEDRAW_GDTs.cxx b/src/XDEDRAW/XDEDRAW_GDTs.cxx index 6fcef29e0a..16884c5f9b 100644 --- a/src/XDEDRAW/XDEDRAW_GDTs.cxx +++ b/src/XDEDRAW/XDEDRAW_GDTs.cxx @@ -2211,6 +2211,202 @@ static Standard_Integer getDimDescr (Draw_Interpretor& di, Standard_Integer argc return 0; } +static Standard_Integer addGDTPosition (Draw_Interpretor& di, Standard_Integer argc, const char** argv) +{ + if (argc < 12) { + di << "Use: XSetGDTPosition Doc GDT_Label loc_x loc_y loc_z normal_x normal_y normal_z xdir_x xdir_y xdir_z\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 << "GDT " << argv[2] << " is absent in " << argv[1] << "\n"; + return 1; + } + + gp_Pnt aPoint(Draw::Atof(argv[3]), Draw::Atof(argv[4]), Draw::Atof(argv[5])); + gp_Dir aNormal(Draw::Atof(argv[6]), Draw::Atof(argv[7]), Draw::Atof(argv[8])); + gp_Dir aDir(Draw::Atof(argv[9]), Draw::Atof(argv[10]), Draw::Atof(argv[11])); + gp_Ax2 aPlane(aPoint, aNormal, aDir); + // Dimension + Handle(XCAFDoc_Dimension) aDimension; + if (aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension)) + { + Handle(XCAFDimTolObjects_DimensionObject) anObj = aDimension->GetObject(); + anObj->SetPlane(aPlane); + anObj->SetPointTextAttach(aPoint); + aDimension->SetObject(anObj); + } + // Geometric Tolerance + Handle(XCAFDoc_GeomTolerance) aGeomTolerance; + if (aLabel.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGeomTolerance)) + { + Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aGeomTolerance->GetObject(); + anObj->SetPlane(aPlane); + anObj->SetPointTextAttach(aPoint); + aGeomTolerance->SetObject(anObj); + } + // Datum + Handle(XCAFDoc_Datum) aDatum; + if (aLabel.FindAttribute(XCAFDoc_Datum::GetID(), aDatum)) + { + Handle(XCAFDimTolObjects_DatumObject) anObj = aDatum->GetObject(); + anObj->SetPlane(aPlane); + anObj->SetPointTextAttach(aPoint); + aDatum->SetObject(anObj); + } + return 0; +} + +static Standard_Integer getGDTPosition (Draw_Interpretor& di, Standard_Integer argc, const char** argv) +{ + if (argc < 3) { + di << "Use: XGetGDTPosition Doc GDT_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 << "GDT " << argv[2] << " is absent in " << argv[1] << "\n"; + return 1; + } + gp_Pnt aPoint; + gp_Dir aNormal, aDir; + // Dimension + Handle(XCAFDoc_Dimension) aDimension; + if (aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension)) + { + Handle(XCAFDimTolObjects_DimensionObject) anObj = aDimension->GetObject(); + aPoint = anObj->GetPointTextAttach(); + aNormal = anObj->GetPlane().Direction(); + aDir = anObj->GetPlane().XDirection(); + } + // Geometric Tolerance + Handle(XCAFDoc_GeomTolerance) aGeomTolerance; + if (aLabel.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGeomTolerance)) + { + Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aGeomTolerance->GetObject(); + aPoint = anObj->GetPointTextAttach(); + aNormal = anObj->GetPlane().Direction(); + aDir = anObj->GetPlane().XDirection(); + } + // Datum + Handle(XCAFDoc_Datum) aDatum; + if (aLabel.FindAttribute(XCAFDoc_Datum::GetID(), aDatum)) + { + Handle(XCAFDimTolObjects_DatumObject) anObj = aDatum->GetObject(); + aPoint = anObj->GetPointTextAttach(); + aNormal = anObj->GetPlane().Direction(); + aDir = anObj->GetPlane().XDirection(); + } + + di << "position: " << aPoint.X() << " " << aPoint.Y() << " " << aPoint.Z() << "\n"; + di << "normal: " << aNormal.X() << " " << aNormal.Y() << " " << aNormal.Z() << "\n"; + di << "x_direction: " << aDir.X() << " " << aDir.Y() << " " << aDir.Z() << "\n"; + return 0; +} + +static Standard_Integer addGDTPresentation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) +{ + if (argc < 5) { + di << "Use: XSetGDTPresentation Doc GDT_Label Shape Name\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 << "GDT " << argv[2] << " is absent in " << argv[1] << "\n"; + return 1; + } + + TopoDS_Shape aPresentation= DBRep::Get(argv[3]); + Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString(argv[4]); + // Dimension + Handle(XCAFDoc_Dimension) aDimension; + if (aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension)) + { + Handle(XCAFDimTolObjects_DimensionObject) anObj = aDimension->GetObject(); + anObj->SetPresentation(aPresentation, aName); + aDimension->SetObject(anObj); + } + // Geometric Tolerance + Handle(XCAFDoc_GeomTolerance) aGeomTolerance; + if (aLabel.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGeomTolerance)) + { + Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aGeomTolerance->GetObject(); + anObj->SetPresentation(aPresentation, aName); + aGeomTolerance->SetObject(anObj); + } + // Datum + Handle(XCAFDoc_Datum) aDatum; + if (aLabel.FindAttribute(XCAFDoc_Datum::GetID(), aDatum)) + { + Handle(XCAFDimTolObjects_DatumObject) anObj = aDatum->GetObject(); + anObj->SetPresentation(aPresentation, aName); + aDatum->SetObject(anObj); + } + return 0; +} + +static Standard_Integer getGDTPresentation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) +{ + if (argc < 3) { + di << "Use: XGetGDTPresentation Doc GDT_Label Shape\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 << "GDT " << argv[2] << " is absent in " << argv[1] << "\n"; + return 1; + } + TopoDS_Shape aPresentation; + // Dimension + Handle(XCAFDoc_Dimension) aDimension; + if (aLabel.FindAttribute(XCAFDoc_Dimension::GetID(), aDimension)) + { + Handle(XCAFDimTolObjects_DimensionObject) anObj = aDimension->GetObject(); + aPresentation = anObj->GetPresentation(); + } + // Geometric Tolerance + Handle(XCAFDoc_GeomTolerance) aGeomTolerance; + if (aLabel.FindAttribute(XCAFDoc_GeomTolerance::GetID(), aGeomTolerance)) + { + Handle(XCAFDimTolObjects_GeomToleranceObject) anObj = aGeomTolerance->GetObject(); + aPresentation = anObj->GetPresentation(); + } + // Datum + Handle(XCAFDoc_Datum) aDatum; + if (aLabel.FindAttribute(XCAFDoc_Datum::GetID(), aDatum)) + { + Handle(XCAFDimTolObjects_DatumObject) anObj = aDatum->GetObject(); + aPresentation = anObj->GetPresentation(); + } + + DBRep::Set (argv[3], aPresentation); + return 0; +} + //======================================================================= //function : InitCommands //purpose : @@ -2556,4 +2752,20 @@ void XDEDRAW_GDTs::InitCommands(Draw_Interpretor& di) di.Add ("XGetDimensionDescr","XGetDimensionDescr Doc Dim_Label\n" "Return all descriptions of given Dimension.", __FILE__, getDimDescr, g); + + di.Add ("XSetGDTPosition","XSetGDTPosition Doc GDT_Label loc_x loc_y loc_z normal_x normal_y normal_z xdir_x xdir_y xdir_z" + "Set plane to display dimension parallel to and point to display text (loc)", + __FILE__, addGDTPosition, g); + + di.Add ("XGetGDTPosition","XGetGDTPosition Doc GDT_Label" + "Returns text position and plane, parallel to which dimension is displayed", + __FILE__, getGDTPosition, g); + + di.Add ("XSetGDTPresentation","XSetGDTPresentation Doc GDT_Label Shape Name" + "Set presentation with given name for dimension", + __FILE__, addGDTPresentation, g); + + di.Add ("XGetGDTPresentation","XGetGDTPresentation Doc GDT_Label Shape" + "Returns Presentation into Shape", + __FILE__, getGDTPresentation, g); } diff --git a/tests/gdt/dimensions/A8 b/tests/gdt/dimensions/A8 new file mode 100644 index 0000000000..fffe3f7b51 --- /dev/null +++ b/tests/gdt/dimensions/A8 @@ -0,0 +1,38 @@ +# test annotation plane +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 +XSetGDTPosition D_init 0:1:4:1 -5 0 7 -1 0 0 0 1 0 +# Presentation +line l -5 0 0 0 0 1 +mkedge prs l 0 10 +XSetGDTPresentation D_init 0:1:4:1 prs presentation +# Export +set isOK 1 +set filename $imagedir/${casename}_D_init.stp +if { [catch { WriteStep D_init $filename } catch_result] } { + puts "Error: File was not written - exception" + set isOK 0 + } +# Import +if {$isOK} { + if { [catch { ReadStep D $filename } 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_pos {position: -5 0 7 +normal: -1 0 0 +x_direction: 0 1 0 +} +} diff --git a/tests/gdt/dimensions/begin b/tests/gdt/dimensions/begin index d8b26eb623..9105223396 100644 --- a/tests/gdt/dimensions/begin +++ b/tests/gdt/dimensions/begin @@ -11,3 +11,4 @@ set c_mod 0 set c_plusminus 0 set c_dump 0 set c_descr 0 +set c_pos 0 diff --git a/tests/gdt/dimensions/end b/tests/gdt/dimensions/end index de04d1fed7..f5bf1c8deb 100644 --- a/tests/gdt/dimensions/end +++ b/tests/gdt/dimensions/end @@ -62,11 +62,10 @@ if {$c_descr != 0} { if {$nb_ref != $nb_cur} { puts "Error: wrong number of descriptions" } else { + set isOK 1; for { set i 0 } { $i < $nb_ref } { incr i } { set refstr [lindex $ref_list $i] - set curstr [lindex $cur_list $i] - set isOK 1; - + set curstr [lindex $cur_list $i] if {[string equal $refstr $curstr] == 0} { set isOK 0 } @@ -77,4 +76,30 @@ if {$c_descr != 0} { } } +# annotation plane and text position +if {$c_pos != 0} { + set position [XGetGDTPosition D 0:1:4:1] + set ref_list [split $position \n] + set cur_list [split $c_pos \n] + set nb_ref [llength $ref_list] + set nb_cur [llength $cur_list] + if {$nb_ref != $nb_cur} { + puts "Error: wrong position" + } else { + set isOK 1; + for { set i 0 } { $i < $nb_ref } { incr i } { + set refstr [lindex $ref_list $i] + set curstr [lindex $cur_list $i] + puts $refstr + puts $curstr + if {[string equal $refstr $curstr] == 0} { + set isOK 0 + } + } + } + if {$isOK == 0} { + puts "Error: wrong position" + } +} + puts "TEST COMPLETED"