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<Handle(StepVisual_TessellatedAnnotationOccurrence)> aTesselations;
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
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())
// 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;
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;
}
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);
}
//=======================================================================
// 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());
}
//----------------------------//
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 :
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);
}