#include <BRep_Builder.hxx>
+#include <Geom_Axis2Placement.hxx>
+#include <Geom_CartesianPoint.hxx>
+#include <Geom_Plane.hxx>
#include <Interface_EntityIterator.hxx>
#include <Interface_InterfaceModel.hxx>
#include <StepData_StepModel.hxx>
#include <STEPCAFControl_DataMapOfPDExternFile.hxx>
#include <STEPCAFControl_DataMapOfSDRExternFile.hxx>
#include <STEPCAFControl_DataMapOfShapePD.hxx>
-#include <STEPCAFControl_DictionaryOfExternFile.hxx>
#include <STEPCAFControl_ExternFile.hxx>
#include <STEPCAFControl_Reader.hxx>
#include <STEPConstruct.hxx>
#include <StepRepr_DerivedShapeAspect.hxx>
#include <StepRepr_DescriptiveRepresentationItem.hxx>
#include <StepRepr_HArray1OfRepresentationItem.hxx>
+#include <StepRepr_MappedItem.hxx>
#include <StepRepr_MeasureRepresentationItem.hxx>
#include <StepRepr_NextAssemblyUsageOccurrence.hxx>
#include <StepRepr_ProductDefinitionShape.hxx>
#include <StepRepr_Representation.hxx>
#include <StepRepr_RepresentationItem.hxx>
#include <StepRepr_HArray1OfRepresentationItem.hxx>
+#include <StepRepr_RepresentationMap.hxx>
#include <StepRepr_RepresentationRelationship.hxx>
#include <StepRepr_RepresentedDefinition.hxx>
#include <StepRepr_ReprItemAndLengthMeasureWithUnit.hxx>
#include <StepShape_ToleranceValue.hxx>
#include <StepShape_ValueFormatTypeQualifier.hxx>
#include <StepShape_Vertex.hxx>
+#include <StepToGeom.hxx>
#include <StepVisual_AnnotationCurveOccurrence.hxx>
+#include <StepVisual_AnnotationFillArea.hxx>
#include <StepVisual_AnnotationPlane.hxx>
+#include <StepVisual_CameraModelD3.hxx>
+#include <StepVisual_CameraModelD3MultiClipping.hxx>
+#include <StepVisual_CameraModelD3MultiClippingIntersection.hxx>
+#include <StepVisual_CameraModelD3MultiClippingUnion.hxx>
+#include <StepVisual_CoordinatesList.hxx>
+#include <StepVisual_HArray1OfCameraModelD3MultiClippingInterectionSelect.hxx>
+#include <StepVisual_HArray1OfCameraModelD3MultiClippingUnionSelect.hxx>
#include <StepVisual_DraughtingCallout.hxx>
#include <StepVisual_DraughtingCalloutElement.hxx>
#include <StepVisual_DraughtingModel.hxx>
#include <StepVisual_PresentationStyleByContext.hxx>
#include <StepVisual_StyleContextSelect.hxx>
#include <StepVisual_StyledItem.hxx>
+#include <StepVisual_ViewVolume.hxx>
#include <StepShape_TypeQualifier.hxx>
#include <TCollection_AsciiString.hxx>
#include <TCollection_HAsciiString.hxx>
#include <XCAFDoc.hxx>
#include <XCAFDoc_Area.hxx>
#include <XCAFDoc_Centroid.hxx>
+#include <XCAFDoc_ClippingPlaneTool.hxx>
#include <XCAFDoc_ColorTool.hxx>
#include <XCAFDoc_DataMapOfShapeLabel.hxx>
#include <XCAFDoc_DimTolTool.hxx>
#include <XCAFDoc_LayerTool.hxx>
#include <XCAFDoc_MaterialTool.hxx>
#include <XCAFDoc_ShapeTool.hxx>
+#include <XCAFDoc_View.hxx>
+#include <XCAFDoc_ViewTool.hxx>
#include <XCAFDoc_Volume.hxx>
#include <XCAFDimTolObjects_DimensionModifiersSequence.hxx>
#include <XCAFDimTolObjects_GeomToleranceType.hxx>
#include <XCAFDimTolObjects_DimensionObject.hxx>
#include <XCAFDimTolObjects_GeomToleranceObject.hxx>
#include <XCAFDimTolObjects_DatumObject.hxx>
+#include <XCAFView_Object.hxx>
#include <XSControl_TransferReader.hxx>
#include <XSControl_WorkSession.hxx>
#include <StepAP242_DraughtingModelItemAssociation.hxx>
myPropsMode( Standard_True ),
mySHUOMode ( Standard_False ),
myGDTMode ( Standard_True ),
- myMatMode ( Standard_True )
+ myMatMode(Standard_True),
+ myViewMode(Standard_True)
{
STEPCAFControl_Controller::Init();
- myFiles = new STEPCAFControl_DictionaryOfExternFile;
}
myPropsMode( Standard_True ),
mySHUOMode ( Standard_False ),
myGDTMode ( Standard_True ),
- myMatMode ( Standard_True )
+ myMatMode(Standard_True),
+ myViewMode(Standard_True)
{
STEPCAFControl_Controller::Init();
Init ( WS, scratch );
{
// necessary only in Writer, to set good actor: WS->SelectNorm ( "STEP" );
myReader.SetWS (WS,scratch);
- myFiles = new STEPCAFControl_DictionaryOfExternFile;
+ myFiles.Clear();
}
//purpose :
//=======================================================================
-const Handle(STEPCAFControl_DictionaryOfExternFile) &STEPCAFControl_Reader::ExternFiles () const
+const NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)>& STEPCAFControl_Reader::ExternFiles () const
{
return myFiles;
}
Handle(STEPCAFControl_ExternFile) &ef) const
{
ef.Nullify();
- if ( myFiles.IsNull() || ! myFiles->HasItem ( name ) )
+ if ( myFiles.IsEmpty() || !myFiles.IsBound ( name ) )
return Standard_False;
- ef = myFiles->Item ( name );
+ ef = myFiles.Find ( name );
return Standard_True;
}
if(GetMatMode())
ReadMaterials(reader.WS(),doc,SeqPDS);
+ // read View entities from STEP model
+ if (GetViewMode())
+ ReadViews(reader.WS(), doc);
+
// Expand resulting CAF structure for sub-shapes (optionally with their
// names) if requested
ExpandSubShapes(STool, map, ShapePDMap);
+ // Update assembly compounds
+ STool->UpdateAssemblies();
+
return Standard_True;
}
Handle(TDocStd_Document)& doc)
{
// if the file is already read, associate it with SDR
- if ( myFiles->HasItem ( file, Standard_True ) ) {
- return myFiles->Item ( file );
+ if ( myFiles.IsBound ( file ) ) {
+ return myFiles.ChangeFind ( file );
}
#ifdef OCCT_DEBUG
}
// add read file to dictionary
- myFiles->SetItem ( file, EF );
+ myFiles.Bind( file, EF );
return EF;
}
Handle(StepRepr_AssemblyComponentUsage) ACU =
Handle(StepRepr_AssemblyComponentUsage)::DownCast(aCharDef.ProductDefinitionRelationship());
+ if (ACU.IsNull())
+ continue;
// PTV 10.02.2003 skip styled item that refer to SHUO
if (ACU->IsKind(STANDARD_TYPE(StepRepr_SpecifiedHigherUsageOccurrence))) {
isSkipSHUOstyle = Standard_True;
if ( ! enti->IsKind ( tSVPLA ) ) continue;
Handle(StepVisual_PresentationLayerAssignment) SVPLA =
Handle(StepVisual_PresentationLayerAssignment)::DownCast(enti);
+ if (SVPLA->AssignedItems().IsNull())
+ continue;
Handle(TCollection_HAsciiString) descr = SVPLA->Description();
Handle(TCollection_HAsciiString) hName = SVPLA->Name();
}
//=======================================================================
-//function : readAnnotation
-//purpose : read annotation plane and position for given GDT
-// (Dimension, Geometric_Tolerance, Datum_Feature or Placed_Datum_Target_Feature)
+//function : readPMIPresentation
+//purpose : read polyline or tessellated presentation for
+// (Annotation_Curve_Occurrence or Draughting_Callout)
//=======================================================================
-void readAnnotation(const Handle(XSControl_TransferReader)& theTR,
- const Handle(Standard_Transient) theGDT,
- const Handle(Standard_Transient)& theDimObject)
+Standard_Boolean readPMIPresentation(const Handle(Standard_Transient)& thePresentEntity,
+ const Handle(XSControl_TransferReader)& theTR,
+ const Standard_Real theFact,
+ TopoDS_Shape& thePresentation,
+ Handle(TCollection_HAsciiString)& thePresentName,
+ Bnd_Box& theBox)
{
- Handle(TCollection_HAsciiString) aPresentName;
- TopoDS_Compound aResAnnotation;
+ if (thePresentEntity.IsNull())
+ return Standard_False;
Handle(Transfer_TransientProcess) aTP = theTR->TransientProcess();
- const Interface_Graph& aGraph = aTP->Graph();
- // find the proper DraughtingModelItemAssociation
- Interface_EntityIterator subs = aGraph.Sharings(theGDT);
- Handle(StepAP242_DraughtingModelItemAssociation) aDMIA;
- for (subs.Start(); subs.More() && aDMIA.IsNull(); subs.Next()) {
- if (!subs.Value()->IsKind(STANDARD_TYPE(StepAP242_DraughtingModelItemAssociation)))
- continue;
- aDMIA = Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(subs.Value());
- Handle(TCollection_HAsciiString) aName = aDMIA->Name();
- aName->LowerCase();
- if (!aName->Search(new TCollection_HAsciiString("pmi representation to presentation link"))) {
- aDMIA = NULL;
- }
- }
- if (aDMIA.IsNull() || aDMIA->NbIdentifiedItem() == 0)
- return;
-
- // calculate units
- Handle(StepVisual_DraughtingModel) aDModel =
- Handle(StepVisual_DraughtingModel)::DownCast(aDMIA->UsedRepresentation());
- Standard_Real aFact = 1;
- if (!aDModel.IsNull())
- GetLengthConversionFactorFromContext(aDModel->ContextOfItems(), aFact);
-
- // retrieve AnnotationPlane
- Standard_Boolean isHasPlane = Standard_False;
- gp_Ax2 aPlaneAxes;
- Handle(StepRepr_RepresentationItem) aDMIAE = aDMIA->IdentifiedItemValue(1);
- if (aDMIAE.IsNull())
- return;
- subs = aGraph.Sharings(aDMIAE);
- Handle(StepVisual_AnnotationPlane) anAnPlane;
- for (subs.Start(); subs.More() && anAnPlane.IsNull(); subs.Next()) {
- anAnPlane = Handle(StepVisual_AnnotationPlane)::DownCast(subs.Value());
- }
- if (!anAnPlane.IsNull()) {
- Handle(StepRepr_RepresentationItem) aPlaneItem = anAnPlane->Item();
- Handle(StepGeom_Axis2Placement3d) aA2P3D;
- //retrieve axes from AnnotationPlane
- if (aPlaneItem->IsKind(STANDARD_TYPE(StepGeom_Plane))) {
- Handle(StepGeom_Plane) aPlane = Handle(StepGeom_Plane)::DownCast(aPlaneItem);
- aA2P3D = aPlane->Position();
- }
- else if (aPlaneItem->IsKind(STANDARD_TYPE(StepVisual_PlanarBox))) {
- Handle(StepVisual_PlanarBox) aBox = Handle(StepVisual_PlanarBox)::DownCast(aPlaneItem);
- aA2P3D = aBox->Placement().Axis2Placement3d();
- }
- // build gp_Ax2 from axes
- if (!aA2P3D.IsNull())
- {
- Handle(StepGeom_Direction) anAxis = aA2P3D->Axis(),
- aRefDir = aA2P3D->RefDirection();
- if (!anAxis.IsNull() && !aRefDir.IsNull()) {
- Handle(TColStd_HArray1OfReal) aCoords;
- aCoords = anAxis->DirectionRatios();
- gp_Dir aXDir(aCoords->Value(1), aCoords->Value(2), aCoords->Value(3));
- aCoords = aRefDir->DirectionRatios();
- gp_Dir aYDir(aCoords->Value(1), aCoords->Value(2), aCoords->Value(3));
- aPlaneAxes.SetDirection(aXDir.Crossed(aYDir));
- aPlaneAxes.SetYDirection(aYDir);
- //set location of the annotation plane
- Handle(TColStd_HArray1OfReal) aLocCoords;
- Handle(StepGeom_CartesianPoint) aLoc = aA2P3D->Location();
- gp_Pnt aLocPos( aLoc->CoordinatesValue(1) * aFact, aLoc->CoordinatesValue(2) * aFact, aLoc->CoordinatesValue(3) * aFact);
- aPlaneAxes.SetLocation(aLocPos);
- isHasPlane = Standard_True;
- }
- }
- }
-
- // set plane axes to XCAF
- if (isHasPlane) {
- 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;
+ Handle(StepVisual_AnnotationOccurrence) anAO;
NCollection_Vector<Handle(StepVisual_StyledItem)> anAnnotations;
- if (aDMIAE->IsKind(STANDARD_TYPE(StepVisual_AnnotationCurveOccurrence)))
+ if (thePresentEntity->IsKind(STANDARD_TYPE(StepVisual_AnnotationOccurrence)))
{
- anACO = Handle(StepVisual_AnnotationCurveOccurrence)::DownCast(aDMIAE);
- if( !anACO.IsNull())
- anAnnotations.Append(anACO);
+ anAO = Handle(StepVisual_AnnotationOccurrence)::DownCast(thePresentEntity);
+ if (!anAO.IsNull()) {
+ thePresentName = anAO->Name();
+ anAnnotations.Append(anAO);
+ }
}
-
- else if (aDMIAE->IsKind(STANDARD_TYPE(StepVisual_DraughtingCallout)))
+ else if (thePresentEntity->IsKind(STANDARD_TYPE(StepVisual_DraughtingCallout)))
{
Handle(StepVisual_DraughtingCallout) aDCallout =
- Handle(StepVisual_DraughtingCallout)::DownCast(aDMIAE);
- for (Standard_Integer i = 1; i <= aDCallout->NbContents() && anACO.IsNull(); i++) {
- anACO = aDCallout->ContentsValue(i).AnnotationCurveOccurrence();
- if(!anACO.IsNull())
+ Handle(StepVisual_DraughtingCallout)::DownCast(thePresentEntity);
+ thePresentName = aDCallout->Name();
+ for (Standard_Integer i = 1; i <= aDCallout->NbContents() && anAO.IsNull(); i++) {
+ anAO = Handle(StepVisual_AnnotationOccurrence)::DownCast(aDCallout->ContentsValue(i).Value());
+ if (!anAO.IsNull())
{
- anAnnotations.Append(anACO);
+ anAnnotations.Append(anAO);
continue;
}
- Handle(StepVisual_TessellatedAnnotationOccurrence) aTesselation =
+ Handle(StepVisual_TessellatedAnnotationOccurrence) aTesselation =
aDCallout->ContentsValue(i).TessellatedAnnotationOccurrence();
- if( !aTesselation.IsNull())
+ if (!aTesselation.IsNull())
anAnnotations.Append(aTesselation);
}
}
if (!anAnnotations.Length())
- return;
+ return Standard_False;
BRep_Builder aB;
+ TopoDS_Compound aResAnnotation;
aB.MakeCompound(aResAnnotation);
- Standard_Integer i =0;
+ Standard_Integer i = 0;
Bnd_Box aBox;
- Standard_Integer nbShapes =0;
- for( ; i < anAnnotations.Length(); i++)
+ Standard_Integer nbShapes = 0;
+ for (; i < anAnnotations.Length(); i++)
{
Handle(StepVisual_StyledItem) anItem = anAnnotations(i);
-
- aPresentName = anItem->Name();
-
- anACO = Handle(StepVisual_AnnotationCurveOccurrence)::DownCast(anItem);
+ anAO = Handle(StepVisual_AnnotationOccurrence)::DownCast(anItem);
TopoDS_Shape anAnnotationShape;
- if(!anACO.IsNull())
+ if (!anAO.IsNull())
{
- Handle(StepRepr_RepresentationItem) aCurveItem = anACO->Item();
- anAnnotationShape = STEPConstruct::FindShape (aTP,aCurveItem);
- if( anAnnotationShape.IsNull())
+ Handle(StepRepr_RepresentationItem) aCurveItem = anAO->Item();
+ anAnnotationShape = STEPConstruct::FindShape(aTP, aCurveItem);
+ if (anAnnotationShape.IsNull())
{
Handle(Transfer_Binder) binder = theTR->Actor()->Transfer(aCurveItem, aTP);
- if ( ! binder.IsNull() && binder->HasResult() ) {
- anAnnotationShape = TransferBRep::ShapeResult ( aTP, binder );
+ if (!binder.IsNull() && binder->HasResult()) {
+ anAnnotationShape = TransferBRep::ShapeResult(aTP, binder);
}
}
}
else
{
Handle(StepRepr_RepresentationItem) aTessItem = anItem->Item();
- if(aTessItem.IsNull())
+ if (aTessItem.IsNull())
continue;
Handle(StepVisual_TessellatedGeometricSet) aTessSet = Handle(StepVisual_TessellatedGeometricSet)::DownCast(aTessItem);
- if( aTessSet.IsNull())
+ if (aTessSet.IsNull())
continue;
NCollection_Handle<StepVisual_Array1OfTessellatedItem> aListItems = aTessSet->Items();
Standard_Integer nb = aListItems.IsNull() ? 0 : aListItems->Length();
{
aTessCurve = Handle(StepVisual_TessellatedCurveSet)::DownCast(aListItems->Value(n));
}
- if( aTessCurve.IsNull())
+ if (aTessCurve.IsNull())
continue;
Handle(StepVisual_CoordinatesList) aCoordList = aTessCurve->CoordList();
- if( aCoordList.IsNull())
+ if (aCoordList.IsNull())
continue;
Handle(TColgp_HArray1OfXYZ) aPoints = aCoordList->Points();
Standard_Integer aNbC = (aCurves.IsNull() ? 0 : aCurves->Length());
TopoDS_Compound aComp;
aB.MakeCompound(aComp);
-
+
Standard_Integer k = 0;
- for( ; k < aNbC; k++)
+ for (; k < aNbC; k++)
{
Handle(TColStd_HSequenceOfInteger) anIndexes = aCurves->Value(k);
TopoDS_Wire aCurW;
aB.MakeWire(aCurW);
- for(Standard_Integer n = 1; n < anIndexes->Length(); n++)
+ for (Standard_Integer n = 1; n < anIndexes->Length(); n++)
{
Standard_Integer ind = anIndexes->Value(n);
Standard_Integer indnext = anIndexes->Value(n + 1);
- if( ind > aPoints->Length() || indnext > aPoints->Length())
+ if (ind > aPoints->Length() || indnext > aPoints->Length())
continue;
- gp_Pnt aP1(aPoints->Value(ind) * aFact);
- gp_Pnt aP2(aPoints->Value(indnext) * aFact);
+ gp_Pnt aP1(aPoints->Value(ind) * theFact);
+ gp_Pnt aP2(aPoints->Value(indnext) * theFact);
BRepBuilderAPI_MakeEdge aMaker(aP1, aP2);
- if( aMaker.IsDone())
+ if (aMaker.IsDone())
{
TopoDS_Edge aCurE = aMaker.Edge();
aB.Add(aCurW, aCurE);
}
anAnnotationShape = aComp;
}
- if(!anAnnotationShape.IsNull())
+ if (!anAnnotationShape.IsNull())
{
nbShapes++;
aB.Add(aResAnnotation, anAnnotationShape);
- if( i == anAnnotations.Length() - 1)
+ if (i == anAnnotations.Length() - 1)
BRepBndLib::AddClose(anAnnotationShape, aBox);
}
}
-
- if(!nbShapes)
+
+ thePresentation = aResAnnotation;
+ theBox = aBox;
+ return (nbShapes > 0);
+}
+
+//=======================================================================
+//function : readAnnotationPlane
+//purpose : read annotation plane
+//=======================================================================
+Standard_Boolean readAnnotationPlane(const Handle(StepVisual_AnnotationPlane) theAnnotationPlane,
+ const Standard_Real theFact,
+ gp_Ax2& thePlane)
+{
+ if (theAnnotationPlane.IsNull())
+ return Standard_False;
+ gp_Ax2 aPlaneAxes;
+ Handle(StepRepr_RepresentationItem) aPlaneItem = theAnnotationPlane->Item();
+ if (aPlaneItem.IsNull())
+ return Standard_False;
+ Handle(StepGeom_Axis2Placement3d) aA2P3D;
+ //retrieve axes from AnnotationPlane
+ if (aPlaneItem->IsKind(STANDARD_TYPE(StepGeom_Plane))) {
+ Handle(StepGeom_Plane) aPlane = Handle(StepGeom_Plane)::DownCast(aPlaneItem);
+ aA2P3D = aPlane->Position();
+ }
+ else if (aPlaneItem->IsKind(STANDARD_TYPE(StepVisual_PlanarBox))) {
+ Handle(StepVisual_PlanarBox) aBox = Handle(StepVisual_PlanarBox)::DownCast(aPlaneItem);
+ aA2P3D = aBox->Placement().Axis2Placement3d();
+ }
+ if (aA2P3D.IsNull())
+ return Standard_False;
+
+ // build gp_Ax2 from axes
+ Handle(StepGeom_Direction) anAxis = aA2P3D->Axis(),
+ aRefDir = aA2P3D->RefDirection();
+ if (anAxis.IsNull() || aRefDir.IsNull())
+ return Standard_False;
+
+ Handle(TColStd_HArray1OfReal) aCoords;
+ aCoords = anAxis->DirectionRatios();
+ gp_Dir aXDir(aCoords->Value(1), aCoords->Value(2), aCoords->Value(3));
+ aCoords = aRefDir->DirectionRatios();
+ gp_Dir aYDir(aCoords->Value(1), aCoords->Value(2), aCoords->Value(3));
+ aPlaneAxes.SetDirection(aXDir.Crossed(aYDir));
+ aPlaneAxes.SetYDirection(aYDir);
+ //set location of the annotation plane
+ Handle(TColStd_HArray1OfReal) aLocCoords;
+ Handle(StepGeom_CartesianPoint) aLoc = aA2P3D->Location();
+ gp_Pnt aLocPos(aLoc->CoordinatesValue(1) * theFact, aLoc->CoordinatesValue(2) * theFact, aLoc->CoordinatesValue(3) * theFact);
+ aPlaneAxes.SetLocation(aLocPos);
+ thePlane = aPlaneAxes;
+ return Standard_True;
+}
+
+//=======================================================================
+//function : readAnnotation
+//purpose : read annotation plane and position for given GDT
+// (Dimension, Geometric_Tolerance, Datum_Feature or Placed_Datum_Target_Feature)
+//=======================================================================
+void readAnnotation(const Handle(XSControl_TransferReader)& theTR,
+ const Handle(Standard_Transient)& theGDT,
+ const Handle(Standard_Transient)& theDimObject)
+{
+ if (theGDT.IsNull() || theDimObject.IsNull())
+ return;
+ Handle(TCollection_HAsciiString) aPresentName;
+ TopoDS_Compound aResAnnotation;
+ Handle(Transfer_TransientProcess) aTP = theTR->TransientProcess();
+ const Interface_Graph& aGraph = aTP->Graph();
+ // find the proper DraughtingModelItemAssociation
+ Interface_EntityIterator subs = aGraph.Sharings(theGDT);
+ Handle(StepAP242_DraughtingModelItemAssociation) aDMIA;
+ for (subs.Start(); subs.More() && aDMIA.IsNull(); subs.Next()) {
+ if (!subs.Value()->IsKind(STANDARD_TYPE(StepAP242_DraughtingModelItemAssociation)))
+ continue;
+ aDMIA = Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(subs.Value());
+ Handle(TCollection_HAsciiString) aName = aDMIA->Name();
+ aName->LowerCase();
+ if (!aName->Search(new TCollection_HAsciiString("pmi representation to presentation link"))) {
+ aDMIA = NULL;
+ }
+ }
+ if (aDMIA.IsNull() || aDMIA->NbIdentifiedItem() == 0)
+ return;
+
+ // calculate units
+ Handle(StepVisual_DraughtingModel) aDModel =
+ Handle(StepVisual_DraughtingModel)::DownCast(aDMIA->UsedRepresentation());
+ Standard_Real aFact = 1;
+ if (!aDModel.IsNull())
+ GetLengthConversionFactorFromContext(aDModel->ContextOfItems(), aFact);
+
+ // retrieve AnnotationPlane
+ Handle(StepRepr_RepresentationItem) aDMIAE = aDMIA->IdentifiedItemValue(1);
+ if (aDMIAE.IsNull())
+ return;
+ gp_Ax2 aPlaneAxes;
+ subs = aGraph.Sharings(aDMIAE);
+ Handle(StepVisual_AnnotationPlane) anAnPlane;
+ for (subs.Start(); subs.More() && anAnPlane.IsNull(); subs.Next()) {
+ anAnPlane = Handle(StepVisual_AnnotationPlane)::DownCast(subs.Value());
+ }
+ Standard_Boolean isHasPlane = readAnnotationPlane(anAnPlane, aFact, aPlaneAxes);
+
+ // set plane axes to XCAF
+ if (isHasPlane) {
+ 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
+ Bnd_Box aBox;
+ if (!readPMIPresentation(aDMIAE, theTR, aFact, aResAnnotation, aPresentName, aBox))
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())
+ if (!aBox.IsVoid())
{
- Standard_Real aXmin, aYmin, aZmin,aXmax, aYmax, aZmax;
- aBox.Get(aXmin, aYmin, aZmin,aXmax, aYmax, aZmax);
+ Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
+ aBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
if (isHasPlane && !aBox.IsOut(aPlaneAxes.Location())) {
aPtext = aPlaneAxes.Location();
}
const Handle(Standard_Transient) theGDT,
const Handle(XCAFDimTolObjects_DimensionObject)& theDimObject)
{
+ if (theGDT.IsNull() || theDimObject.IsNull())
+ return;
Handle(Transfer_TransientProcess) aTP = theTR->TransientProcess();
const Interface_Graph& aGraph = aTP->Graph();
return Standard_True;
}
+//=======================================================================
+//function : FindShapeIndexForDGT
+//purpose : auxiliary find shape index in map og imported shapes
+//=======================================================================
+static Standard_Integer FindShapeIndexForDGT(const Handle(Standard_Transient)& theEnt,
+ const Handle(XSControl_WorkSession)& theWS)
+{
+ const Handle(Transfer_TransientProcess) &aTP = theWS->TransferReader()->TransientProcess();
+ // try to find index of given entity
+ Standard_Integer anIndex = aTP->MapIndex(theEnt);
+ if (anIndex > 0)
+ return anIndex;
+ // if theEnt is a geometry item try to find its topological item
+ const Interface_Graph& aGraph = aTP->Graph();
+ Interface_EntityIterator anIter = aGraph.Sharings(theEnt);
+ for (anIter.Start(); anIter.More(); anIter.Next()) {
+ if (anIter.Value()->IsKind(STANDARD_TYPE(StepShape_TopologicalRepresentationItem)))
+ {
+ anIndex = aTP->MapIndex(anIter.Value());
+ if (anIndex > 0)
+ return anIndex;
+ }
+ }
+ return 0;
+}
+
+//=======================================================================
+//function : collectShapeAspect
+//purpose :
+//=======================================================================
+static void collectShapeAspect(const Handle(StepRepr_ShapeAspect)& theSA,
+ const Handle(XSControl_WorkSession)& theWS,
+ NCollection_Sequence<Handle(StepRepr_ShapeAspect)>& theSAs)
+{
+ if (theSA.IsNull())
+ return;
+ Handle(XSControl_TransferReader) aTR = theWS->TransferReader();
+ Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
+ const Interface_Graph& aGraph = aTP->Graph();
+ // Retrieve Shape_Aspect, connected to Representation_Item from Derived_Shape_Aspect
+ if (theSA->IsKind(STANDARD_TYPE(StepRepr_DerivedShapeAspect))) {
+ Interface_EntityIterator anIter = aGraph.Sharings(theSA);
+ Handle(StepRepr_ShapeAspectDerivingRelationship) aSADR = NULL;
+ for (; aSADR.IsNull() && anIter.More(); anIter.Next()) {
+ aSADR = Handle(StepRepr_ShapeAspectDerivingRelationship)::DownCast(anIter.Value());
+ }
+ if (!aSADR.IsNull())
+ collectShapeAspect(aSADR->RelatedShapeAspect(), theWS, theSAs);
+ }
+ else if (theSA->IsKind(STANDARD_TYPE(StepDimTol_DatumFeature)) ||
+ theSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget))) {
+ theSAs.Append(theSA);
+ return;
+ }
+ else {
+ // Find all children Shape_Aspect
+ Standard_Boolean isSimple = Standard_True;
+ Interface_EntityIterator anIter = aGraph.Sharings(theSA);
+ for (; anIter.More(); anIter.Next()) {
+ if (anIter.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspectRelationship)) &&
+ !anIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation))) {
+ Handle(StepRepr_ShapeAspectRelationship) aSAR =
+ Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIter.Value());
+ if (aSAR->RelatingShapeAspect() == theSA && !aSAR->RelatedShapeAspect().IsNull()
+ && !aSAR->RelatedShapeAspect()->IsKind(STANDARD_TYPE(StepDimTol_Datum))) {
+ collectShapeAspect(aSAR->RelatedShapeAspect(), theWS, theSAs);
+ isSimple = Standard_False;
+ }
+ }
+ }
+ // If not Composite_Shape_Aspect (or subtype) append to sequence.
+ if (isSimple)
+ theSAs.Append(theSA);
+ }
+}
+
+//=======================================================================
+//function : getShapeLabel
+//purpose :
+//=======================================================================
+
+static TDF_Label getShapeLabel(const Handle(StepRepr_RepresentationItem)& theItem,
+ const Handle(XSControl_WorkSession)& theWS,
+ const Handle(XCAFDoc_ShapeTool)& theShapeTool)
+{
+ TDF_Label aShapeL;
+ const Handle(Transfer_TransientProcess) &aTP = theWS->TransferReader()->TransientProcess();
+ Standard_Integer index = FindShapeIndexForDGT(theItem, theWS);
+ TopoDS_Shape aShape;
+ if (index > 0) {
+ Handle(Transfer_Binder) aBinder = aTP->MapItem(index);
+ aShape = TransferBRep::ShapeResult(aBinder);
+ }
+ if (aShape.IsNull())
+ return aShapeL;
+ theShapeTool->Search(aShape, aShapeL, Standard_True, Standard_True, Standard_True);
+ return aShapeL;
+}
//=======================================================================
//function : setDatumToXCAF
//purpose :
//=======================================================================
-static Standard_Boolean setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat,
- const TDF_Label theGDTL,
- const Standard_Integer thePositionCounter,
- const XCAFDimTolObjects_DatumModifiersSequence& aXCAFModifiers,
- const XCAFDimTolObjects_DatumModifWithValue aXCAFModifWithVal,
- const Standard_Real aModifValue,
- const Handle(TDocStd_Document)& theDoc,
- const Handle(XSControl_WorkSession)& theWS)
+
+Standard_Boolean STEPCAFControl_Reader::setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat,
+ const TDF_Label theGDTL,
+ const Standard_Integer thePositionCounter,
+ const XCAFDimTolObjects_DatumModifiersSequence& theXCAFModifiers,
+ const XCAFDimTolObjects_DatumModifWithValue theXCAFModifWithVal,
+ const Standard_Real theModifValue,
+ const Handle(TDocStd_Document)& theDoc,
+ const Handle(XSControl_WorkSession)& theWS)
{
- Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( theDoc->Main() );
- Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool( theDoc->Main() );
+ Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
+ Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main());
const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
const Interface_Graph& aGraph = aTP->Graph();
Handle(XCAFDoc_Datum) aDat;
- TDF_Label aShL;
- Standard_Boolean aRefShapeIsFound = Standard_False;
- Standard_Boolean aFirstStep = Standard_True;
+ TDF_LabelSequence aShapeLabels;
+ Handle(XCAFDimTolObjects_DatumObject) aDatObj = new XCAFDimTolObjects_DatumObject();
+
+ // Collect all links to shapes
+ NCollection_Sequence<Handle(StepRepr_ShapeAspect)> aSAs;
Interface_EntityIterator anIterD = aGraph.Sharings(theDat);
- for(anIterD.Start(); anIterD.More(); anIterD.Next()) {
- Handle(StepRepr_ShapeAspectRelationship) aSAR =
- Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIterD.Value());
- if(aSAR.IsNull()) continue;
-
- Handle(StepRepr_ShapeAspect) aSA = aSAR->RelatingShapeAspect();
- if (aSA.IsNull()) continue;
- Handle(StepAP242_GeometricItemSpecificUsage) aPGISU;
- if(aSA->IsKind(STANDARD_TYPE(StepRepr_CompShAspAndDatumFeatAndShAsp)))
- {
- //processing for complex entity
- Interface_EntityIterator anIterC = aGraph.Sharings(aSA);
- for(anIterC.Start(); anIterC.More(); anIterC.Next()) {
- Handle(StepRepr_ShapeAspectRelationship) SAR =
- Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIterC.Value());
- if(SAR.IsNull()) continue;
- Handle(StepRepr_ShapeAspect) aS = SAR->RelatedShapeAspect();
- if(aS.IsNull()) continue;
- Interface_EntityIterator anIterSA = aGraph.Sharings(aS);
- for(anIterSA.Start(); anIterSA.More() && aPGISU.IsNull(); anIterSA.Next()) {
- aPGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterSA.Value());
- }
- if(!aPGISU.IsNull()){
- aSA = aS;
- break;
- }
+ for (anIterD.Start(); anIterD.More(); anIterD.Next()) {
+ Handle(StepRepr_ShapeAspectRelationship) aSAR = Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIterD.Value());
+ if (aSAR.IsNull() || aSAR->RelatingShapeAspect().IsNull())
+ continue;
+ collectShapeAspect(aSAR->RelatingShapeAspect(), theWS, aSAs);
+ Handle(StepDimTol_DatumFeature) aDF = Handle(StepDimTol_DatumFeature)::DownCast(aSAR->RelatingShapeAspect());
+ if (!aSAR->RelatingShapeAspect()->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)))
+ readAnnotation(aTR, aSAR->RelatingShapeAspect(), aDatObj);
+ }
+
+ // Collect shape labels
+ for (Standard_Integer i = 1; i <= aSAs.Length(); i++) {
+ Handle(StepRepr_ShapeAspect) aSA = aSAs.Value(i);
+ if (aSA.IsNull())
+ continue;
+ // Skip datum targets
+ if (aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)))
+ continue;
+
+ // Process all connected GISU
+ Interface_EntityIterator anIter = aGraph.Sharings(aSA);
+ for (; anIter.More(); anIter.Next()) {
+ Handle(StepAP242_GeometricItemSpecificUsage) aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIter.Value());
+ if (aGISU.IsNull())
+ continue;
+ for (Standard_Integer j = 1; j <= aGISU->NbIdentifiedItem(); j++) {
+ TDF_Label aShapeL = getShapeLabel(aGISU->IdentifiedItemValue(j), theWS, aSTool);
+ if (!aShapeL.IsNull())
+ aShapeLabels.Append(aShapeL);
}
}
- else if(aSA->IsKind(STANDARD_TYPE(StepDimTol_PlacedDatumTargetFeature)))
- {
- //processing for datum target
- Interface_EntityIterator anIterDTF = aGraph.Sharings(aSA);
- for(anIterDTF.Start(); anIterDTF.More(); anIterDTF.Next()) {
- if(anIterDTF.Value()->IsKind(STANDARD_TYPE(StepRepr_FeatureForDatumTargetRelationship)))
- {
- Handle(StepRepr_FeatureForDatumTargetRelationship) aFFDTR =
- Handle(StepRepr_FeatureForDatumTargetRelationship)::DownCast(anIterDTF.Value());
- Handle(StepRepr_ShapeAspect) aTmpSA = aFFDTR->RelatedShapeAspect();
- Interface_EntityIterator anIterDSWP = aGraph.Sharings(aTmpSA);
- for(anIterDSWP.Start(); anIterDSWP.More() && aPGISU.IsNull(); anIterDSWP.Next()) {
- aPGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterDSWP.Value());
+ }
+
+ // Process datum targets and create objects for them
+ Standard_Boolean isExistDatumTarget = Standard_False;
+ for (Standard_Integer i = 1; i <= aSAs.Length(); i++) {
+ Handle(StepDimTol_PlacedDatumTargetFeature) aDT = Handle(StepDimTol_PlacedDatumTargetFeature)::DownCast(aSAs.Value(i));
+ if (aDT.IsNull())
+ continue;
+ Handle(XCAFDimTolObjects_DatumObject) aDatTargetObj = new XCAFDimTolObjects_DatumObject();
+ XCAFDimTolObjects_DatumTargetType aType;
+ if (!STEPCAFControl_GDTProperty::GetDatumTargetType(aDT->Description(), aType))
+ continue;
+ aDatTargetObj->SetDatumTargetType(aType);
+ Standard_Boolean isValidDT = Standard_False;
+
+ // Feature for datum target
+ TDF_LabelSequence aDTShapeLabels;
+ Interface_EntityIterator aDTIter = aGraph.Sharings(aDT);
+ Handle(StepRepr_FeatureForDatumTargetRelationship) aRelationship;
+ for (; aDTIter.More() && aRelationship.IsNull(); aDTIter.Next()) {
+ aRelationship = Handle(StepRepr_FeatureForDatumTargetRelationship)::DownCast(aDTIter.Value());
}
+ if (!aRelationship.IsNull()) {
+ Handle(StepRepr_ShapeAspect) aSA = aRelationship->RelatingShapeAspect();
+ Interface_EntityIterator aSAIter = aGraph.Sharings(aSA);
+ for (; aSAIter.More(); aSAIter.Next()) {
+ Handle(StepAP242_GeometricItemSpecificUsage) aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(aSAIter.Value());
+ if (aGISU.IsNull())
+ continue;
+ for (Standard_Integer j = 1; j <= aGISU->NbIdentifiedItem(); j++) {
+ TDF_Label aShapeL = getShapeLabel(aGISU->IdentifiedItemValue(j), theWS, aSTool);
+ if (!aShapeL.IsNull()) {
+ aDTShapeLabels.Append(aShapeL);
+ isValidDT = Standard_True;
+ }
}
}
}
- if (aSA.IsNull()) continue;
- Interface_EntityIterator anIterDSWP = aGraph.Sharings(aSA);
- for(anIterDSWP.Start(); anIterDSWP.More() && aPGISU.IsNull(); anIterDSWP.Next()) {
- aPGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterDSWP.Value());
- }
- if(aPGISU.IsNull()) continue;
- // get representation item
- Handle(StepRepr_RepresentationItem) aRI;
- for(Standard_Integer i = 1 ; i <= aPGISU->NbIdentifiedItem() && aRI.IsNull(); i++)
- {
- aRI = aPGISU->IdentifiedItemValue(i);
- }
- if(aRI.IsNull()) continue;
- Standard_Integer index = aTP->MapIndex(aRI);
- TopoDS_Shape aSh;
- if(index >0) {
- Handle(Transfer_Binder) binder = aTP->MapItem(index);
- aSh = TransferBRep::ShapeResult(binder);
+
+ if (aType != XCAFDimTolObjects_DatumTargetType_Area && !isValidDT) {
+ // Try another way of feature connection
+ for (aDTIter.Start(); aDTIter.More(); aDTIter.Next()) {
+ Handle(StepAP242_GeometricItemSpecificUsage) aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(aDTIter.Value());
+ if (aGISU.IsNull())
+ continue;
+ for (Standard_Integer j = 1; j <= aGISU->NbIdentifiedItem(); j++) {
+ TDF_Label aShapeL = getShapeLabel(aGISU->IdentifiedItemValue(j), theWS, aSTool);
+ if (!aShapeL.IsNull()) {
+ aDTShapeLabels.Append(aShapeL);
+ isValidDT = Standard_True;
+ }
+ }
+ }
}
- if(aSh.IsNull()) continue;
- if( !aSTool->Search(aSh, aShL, Standard_True, Standard_True, Standard_True) ) continue;
- Handle(TDataStd_TreeNode) aNode;
- if(aFirstStep && aShL.FindAttribute(XCAFDoc::DatumRefGUID(),aNode) && aNode->HasFirst() &&
- aNode->First()->Label().FindAttribute(XCAFDoc_Datum::GetID(),aDat))
- {
- //if datums already attached, not need add datum target
- aRefShapeIsFound = Standard_True;
+
+ if (aType == XCAFDimTolObjects_DatumTargetType_Area) {
+ // Area datum target
+ Interface_EntityIterator anIterDTF = aGraph.Shareds(aDT);
+ Handle(StepAP242_GeometricItemSpecificUsage) aGISU;
+ for (; anIterDTF.More() && aGISU.IsNull(); anIterDTF.Next()) {
+ aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterDTF.Value());
+ }
+ Handle(StepRepr_RepresentationItem) anItem;
+ if (aGISU->NbIdentifiedItem() > 0)
+ anItem = aGISU->IdentifiedItemValue(1);
+ if (anItem.IsNull())
+ continue;
+ Standard_Integer anItemIndex = FindShapeIndexForDGT(anItem, theWS);
+ if (anItemIndex > 0) {
+ Handle(Transfer_Binder) aBinder = aTP->MapItem(anItemIndex);
+ TopoDS_Shape anItemShape = TransferBRep::ShapeResult(aBinder);
+ aDatTargetObj->SetDatumTarget(anItemShape);
+ isValidDT = Standard_True;
+ }
}
- aFirstStep = Standard_False;
- Handle(XCAFDimTolObjects_DatumObject) aDatObj;
- if(aSA->IsKind(STANDARD_TYPE(StepDimTol_PlacedDatumTargetFeature)))
- {
- if(!aRefShapeIsFound)
- {
- //if datum targers not yet added
- TDF_Label aDatL = aDGTTool->AddDatum();
- aDat = XCAFDoc_Datum::Set(aDatL);
- aDGTTool->SetDatum(aShL, aDatL);
- aDatObj = aDat->GetObject();
- aDatObj->SetName(theDat->Identification());
- aDatObj->SetPosition (thePositionCounter);
- if(!aXCAFModifiers.IsEmpty())
- aDatObj->SetModifiers(aXCAFModifiers);
- if (aXCAFModifWithVal != XCAFDimTolObjects_DatumModifWithValue_None)
- aDatObj->SetModifierWithValue(aXCAFModifWithVal, aModifValue);
- aDGTTool->SetDatumToGeomTol(aDatL, theGDTL);
- Handle(StepDimTol_PlacedDatumTargetFeature) aPDTF = Handle(StepDimTol_PlacedDatumTargetFeature)::DownCast(aSA);
- if (aPDTF->TargetId()->IsIntegerValue())
- aDatObj->SetDatumTargetNumber(aPDTF->TargetId()->IntegerValue());
- else
- aDatObj->SetDatumTargetNumber(0);
- aDatObj->IsDatumTarget(Standard_True);
- XCAFDimTolObjects_DatumTargetType aType;
- if(STEPCAFControl_GDTProperty::GetDatumTargetType(aSA->Description(),aType))
- {
- aDatObj->SetDatumTargetType(aType);
- if(aType == XCAFDimTolObjects_DatumTargetType_Area)
- {
- Interface_EntityIterator anIterDTF = aGraph.Shareds(aSA);
- for(anIterDTF.Start(); anIterDTF.More(); anIterDTF.Next()) {
- if(anIterDTF.Value()->IsKind(STANDARD_TYPE(StepAP242_GeometricItemSpecificUsage)))
+ else {
+ // Point/line/rectangle/circle datum targets
+ Interface_EntityIterator anIter = aGraph.Sharings(aDT);
+ Handle(StepRepr_PropertyDefinition) aPD;
+ for (; anIter.More() && aPD.IsNull(); anIter.Next()) {
+ aPD = Handle(StepRepr_PropertyDefinition)::DownCast(anIter.Value());
+ }
+ if (!aPD.IsNull()) {
+ anIter = aGraph.Sharings(aPD);
+ Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
+ for (; anIter.More() && aSDR.IsNull(); anIter.Next()) {
+ aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(anIter.Value());
+ }
+ if (!aSDR.IsNull()) {
+ Handle(StepShape_ShapeRepresentationWithParameters) aSRWP
+ = Handle(StepShape_ShapeRepresentationWithParameters)::DownCast(aSDR->UsedRepresentation());
+ if (!aSRWP.IsNull()) {
+ isValidDT = Standard_True;
+ // Collect parameters of datum target
+ for (Standard_Integer j = aSRWP->Items()->Lower(); j <= aSRWP->Items()->Upper(); j++)
+ {
+ if (aSRWP->ItemsValue(j).IsNull())
+ continue;
+ if (aSRWP->ItemsValue(j)->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d)))
{
- Handle(StepAP242_GeometricItemSpecificUsage) aGISU
- = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIterDSWP.Value());
- Handle(StepRepr_RepresentationItem) anItem;
- if(aPGISU->NbIdentifiedItem() > 0) {
- anItem = aPGISU->IdentifiedItemValue(1);
- }
- if(anItem.IsNull()) continue;
- Standard_Integer anItemIndex = aTP->MapIndex(anItem);
- if(anItemIndex >0) {
- Handle(Transfer_Binder) binder = aTP->MapItem(anItemIndex);
- TopoDS_Shape anItemShape = TransferBRep::ShapeResult(binder);
- aDatObj->SetDatumTarget(anItemShape);
- }
+ Handle(StepGeom_Axis2Placement3d) anAx
+ = Handle(StepGeom_Axis2Placement3d)::DownCast(aSRWP->ItemsValue(j));
+ Handle(Geom_Axis2Placement) anAxis = StepToGeom::MakeAxis2Placement(anAx);
+ aDatTargetObj->SetDatumTargetAxis(anAxis->Ax2());
}
- }
- }
- else
- {
- Interface_EntityIterator anIterDTF = aGraph.Shareds(aSA);
- for(anIterDTF.Start(); anIterDTF.More(); anIterDTF.Next()) {
- if(anIterDTF.Value()->IsKind(STANDARD_TYPE(StepRepr_PropertyDefinition)))
+ else if (aSRWP->ItemsValue(j)->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit)))
{
- Interface_EntityIterator anIterPD = aGraph.Shareds(anIterDTF.Value());
- for(anIterPD.Start(); anIterPD.More(); anIterPD.Next()) {
- if(anIterPD.Value()->IsKind(STANDARD_TYPE(StepShape_ShapeDefinitionRepresentation)))
- {
- Interface_EntityIterator anIterSDR = aGraph.Sharings(anIterPD.Value());
- for(anIterSDR.Start(); anIterSDR.More(); anIterSDR.Next()) {
- if(anIterSDR.Value()->IsKind(STANDARD_TYPE(StepShape_ShapeRepresentationWithParameters)))
- {
- Handle(StepShape_ShapeRepresentationWithParameters) aSRWP
- = Handle(StepShape_ShapeRepresentationWithParameters)::DownCast(anIterSDR.Value());
- for(Standard_Integer r = aSRWP->Items()->Lower(); r <= aSRWP->Items()->Upper(); r++)
- {
- if(aSRWP->ItemsValue(r)->IsKind(STANDARD_TYPE(StepGeom_Axis2Placement3d)))
- {
- Handle(StepGeom_Axis2Placement3d) anAx
- = Handle(StepGeom_Axis2Placement3d)::DownCast(aSRWP->ItemsValue(r));
- Handle(TColStd_HArray1OfReal) aDirArr = anAx->Axis()->DirectionRatios();
- Handle(TColStd_HArray1OfReal) aDirRArr = anAx->RefDirection()->DirectionRatios();
- Handle(TColStd_HArray1OfReal) aLocArr = anAx->Location()->Coordinates();
- gp_Dir aDir;
- gp_Dir aDirR;
- gp_Pnt aPnt;
- if(!aDirArr.IsNull() && aDirArr->Length() > 2 &&
- !aDirRArr.IsNull() && aDirRArr->Length() > 2 &&
- !aLocArr.IsNull() && aLocArr->Length() > 2)
- {
- aDir.SetCoord(aDirArr->Lower(), aDirArr->Lower()+1, aDirArr->Lower()+2);
- aDirR.SetCoord(aDirRArr->Lower(), aDirRArr->Lower()+1, aDirRArr->Lower()+2);
- aPnt.SetCoord(aLocArr->Lower(), aLocArr->Lower()+1, aLocArr->Lower()+2);
- gp_Ax2 anA(aPnt, aDir, aDirR);
- aDatObj->SetDatumTargetAxis(anA);
- }
- }
- else if(aSRWP->ItemsValue(r)->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndLengthMeasureWithUnit)))
- {
- Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) aM =
- Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(aSRWP->ItemsValue(r));
- Standard_Real aVal = aM->GetMeasureWithUnit()->ValueComponent();
- StepBasic_Unit anUnit = aM->GetMeasureWithUnit()->UnitComponent();
- Standard_Real aFact=1.;
- if(anUnit.IsNull()) continue;
- if( !(anUnit.CaseNum(anUnit.Value())==1) ) continue;
- Handle(StepBasic_NamedUnit) NU = anUnit.NamedUnit();
- if(GetLengthConversionFactor(NU,aFact)) aVal=aVal*aFact;
- if(aM->Name()->String().IsEqual("target length") ||
- aM->Name()->String().IsEqual("target diameter"))
- aDatObj->SetDatumTargetLength(aVal);
- else
- aDatObj->SetDatumTargetWidth(aVal);
- }
- }
- }
- }
- }
- }
+ Handle(StepRepr_ReprItemAndLengthMeasureWithUnit) aM =
+ Handle(StepRepr_ReprItemAndLengthMeasureWithUnit)::DownCast(aSRWP->ItemsValue(j));
+ Standard_Real aVal = aM->GetMeasureWithUnit()->ValueComponent();
+ StepBasic_Unit anUnit = aM->GetMeasureWithUnit()->UnitComponent();
+ Standard_Real aFact = 1.;
+ if (anUnit.IsNull())
+ continue;
+ Handle(StepBasic_NamedUnit) aNU = anUnit.NamedUnit();
+ if (aNU.IsNull())
+ continue;
+ if (GetLengthConversionFactor(aNU, aFact))
+ aVal = aVal * aFact;
+ if (aM->Name()->String().IsEqual("target length") ||
+ aM->Name()->String().IsEqual("target diameter"))
+ aDatTargetObj->SetDatumTargetLength(aVal);
+ else
+ aDatTargetObj->SetDatumTargetWidth(aVal);
}
}
}
}
}
}
- else
- {
- //processing for darum feature
+
+ // Create datum target object
+ if (isValidDT) {
TDF_Label aDatL = aDGTTool->AddDatum();
+ myGDTMap.Bind(aDT, aDatL);
+ aDGTTool->Lock(aDatL);
aDat = XCAFDoc_Datum::Set(aDatL);
- aDGTTool->SetDatum(aShL, aDatL);
- aDatObj = aDat->GetObject();
- aDatObj->SetName(theDat->Identification());
- aDatObj->SetPosition (thePositionCounter);
- if(!aXCAFModifiers.IsEmpty())
- aDatObj->SetModifiers(aXCAFModifiers);
- if (aXCAFModifWithVal != XCAFDimTolObjects_DatumModifWithValue_None)
- aDatObj->SetModifierWithValue(aXCAFModifWithVal, aModifValue);
+ aDGTTool->SetDatum(aDTShapeLabels, aDatL);
+ aDatTargetObj->SetName(theDat->Identification());
+ aDatTargetObj->SetPosition(thePositionCounter);
+ if (!theXCAFModifiers.IsEmpty())
+ aDatTargetObj->SetModifiers(theXCAFModifiers);
+ if (theXCAFModifWithVal != XCAFDimTolObjects_DatumModifWithValue_None)
+ aDatTargetObj->SetModifierWithValue(theXCAFModifWithVal, theModifValue);
aDGTTool->SetDatumToGeomTol(aDatL, theGDTL);
+ aDatTargetObj->IsDatumTarget(Standard_True);
+ aDatTargetObj->SetDatumTargetNumber(aDT->TargetId()->IntegerValue());
+ readAnnotation(aTR, aDT, aDatTargetObj);
+ aDat->SetObject(aDatTargetObj);
+ isExistDatumTarget = Standard_True;
}
- if(!aDatObj.IsNull()) {
- readAnnotation(aTR, aSAR->RelatingShapeAspect(), aDatObj);
- aDat->SetObject(aDatObj);
+ }
+
+ if (aShapeLabels.Length() > 0 || !isExistDatumTarget) {
+ // Create object for datum
+ TDF_Label aDatL = aDGTTool->AddDatum();
+ myGDTMap.Bind(theDat, aDatL);
+ aDGTTool->Lock(aDatL);
+ aDat = XCAFDoc_Datum::Set(aDatL);
+ aDGTTool->SetDatum(aShapeLabels, aDatL);
+ aDatObj->SetName(theDat->Identification());
+ aDatObj->SetPosition(thePositionCounter);
+ if (!theXCAFModifiers.IsEmpty())
+ aDatObj->SetModifiers(theXCAFModifiers);
+ if (theXCAFModifWithVal != XCAFDimTolObjects_DatumModifWithValue_None)
+ aDatObj->SetModifierWithValue(theXCAFModifWithVal, theModifValue);
+ aDGTTool->SetDatumToGeomTol(aDatL, theGDTL);
+ if (aDatObj->GetPresentation().IsNull()) {
+ // Try find annotation connected to datum entity (not right case, according recommended practices)
+ readAnnotation(aTR, theDat, aDatObj);
}
+ aDat->SetObject(aDatObj);
}
- return !aDat.IsNull();
+
+ return Standard_True;
}
//function : ReadDatums
//purpose : auxilary
//=======================================================================
-static Standard_Boolean readDatumsAP242(const Handle(Standard_Transient)& theEnt,
- const TDF_Label theGDTL,
- const Handle(TDocStd_Document)& theDoc,
- const Handle(XSControl_WorkSession)& theWS)
+Standard_Boolean STEPCAFControl_Reader::readDatumsAP242(const Handle(Standard_Transient)& theEnt,
+ const TDF_Label theGDTL,
+ const Handle(TDocStd_Document)& theDoc,
+ const Handle(XSControl_WorkSession)& theWS)
{
- Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool( theDoc->Main() );
- Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool( theDoc->Main() );
const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
const Handle(Transfer_TransientProcess) &aTP = aTR->TransientProcess();
const Interface_Graph& aGraph = aTP->Graph();
return Standard_True;
}
-//=======================================================================
-//function : collectShapeAspect
-//purpose :
-//=======================================================================
-static void collectShapeAspect(const Handle(StepRepr_ShapeAspect)& theSA,
- const Handle(XSControl_WorkSession)& theWS,
- NCollection_Sequence<Handle(StepRepr_ShapeAspect)>& theSAs)
-{
- Handle(XSControl_TransferReader) aTR = theWS->TransferReader();
- Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
- const Interface_Graph& aGraph = aTP->Graph();
- // Retrieve Shape_Aspect, connected to Representation_Item from Derived_Shape_Aspect
- if (theSA->IsKind(STANDARD_TYPE(StepRepr_DerivedShapeAspect))) {
- Interface_EntityIterator anIter = aGraph.Sharings(theSA);
- Handle(StepRepr_ShapeAspectDerivingRelationship) aSADR = NULL;
- for (; aSADR.IsNull() && anIter.More(); anIter.Next()) {
- aSADR = Handle(StepRepr_ShapeAspectDerivingRelationship)::DownCast(anIter.Value());
- }
- if (!aSADR.IsNull())
- collectShapeAspect(aSADR->RelatedShapeAspect(), theWS, theSAs);
- }
- else if (theSA->IsKind(STANDARD_TYPE(StepDimTol_DatumFeature))) {
- theSAs.Append(theSA);
- return;
- }
- else {
- // Find all children Shape_Aspect
- Standard_Boolean isSimple = Standard_True;
- Interface_EntityIterator anIter = aGraph.Sharings(theSA);
- for (; anIter.More(); anIter.Next()) {
- if (anIter.Value()->IsKind(STANDARD_TYPE(StepRepr_ShapeAspectRelationship)) &&
- !anIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation))) {
- Handle(StepRepr_ShapeAspectRelationship) aSAR =
- Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIter.Value());
- if (aSAR->RelatingShapeAspect() == theSA) {
- collectShapeAspect(aSAR->RelatedShapeAspect(), theWS, theSAs);
- isSimple = Standard_False;
- }
- }
- }
- // If not Composite_Shape_Aspect (or subtype) append to sequence.
- if (isSimple)
- theSAs.Append(theSA);
- }
-}
-
//=======================================================================
//function : createGeomTolObjectInXCAF
//purpose :
//=======================================================================
-static TDF_Label createGDTObjectInXCAF(const Handle(Standard_Transient)& theEnt,
- const Handle(TDocStd_Document)& theDoc,
- const Handle(XSControl_WorkSession)& theWS)
+TDF_Label STEPCAFControl_Reader::createGDTObjectInXCAF(const Handle(Standard_Transient)& theEnt,
+ const Handle(TDocStd_Document)& theDoc,
+ const Handle(XSControl_WorkSession)& theWS)
{
TDF_Label aGDTL;
if(!theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) &&
// Collect shapes
for(Standard_Integer i = aSeqRI1.Lower(); i <= aSeqRI1.Upper() ;i++)
{
- Standard_Integer anIndex = aTP->MapIndex(aSeqRI1.Value(i));
+ Standard_Integer anIndex = FindShapeIndexForDGT(aSeqRI1.Value(i), theWS);
TopoDS_Shape aSh;
if(anIndex >0) {
Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
//for dimensional location
for(Standard_Integer i = aSeqRI2.Lower(); i <= aSeqRI2.Upper() ;i++)
{
- Standard_Integer anIndex = aTP->MapIndex(aSeqRI2.Value(i));
+ Standard_Integer anIndex = FindShapeIndexForDGT(aSeqRI2.Value(i), theWS);
TopoDS_Shape aSh;
if(anIndex >0) {
Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
if(!theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance)))
{
aGDTL = aDGTTool->AddDimension();
+ myGDTMap.Bind(theEnt, aGDTL);
+ aDGTTool->Lock(aGDTL);
Handle(XCAFDoc_Dimension) aDim = XCAFDoc_Dimension::Set(aGDTL);
TCollection_AsciiString aStr("DGT:Dimensional_");
if(theEnt->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)))
else
{
aGDTL = aDGTTool->AddGeomTolerance();
+ myGDTMap.Bind(theEnt, aGDTL);
+ aDGTTool->Lock(aGDTL);
Handle(XCAFDoc_GeomTolerance) aGTol = XCAFDoc_GeomTolerance::Set(aGDTL);
TCollection_AsciiString aStr("DGT:GeomTolerance");
TDataStd_Name::Set(aGDTL, aStr);
for(anIterGRI.Start(); anIterGRI.More() && aPGISU.IsNull(); anIterGRI.Next()) {
aPRI = Handle(StepRepr_RepresentationItem)::DownCast(anIterGRI.Value());
}
- Standard_Integer anIndex = aTP->MapIndex(aPRI);
+ Standard_Integer anIndex = FindShapeIndexForDGT(aPRI, theWS);
TopoDS_Edge aSh;
if(anIndex >0) {
Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
static Standard_Boolean getTolType(const Handle(Standard_Transient)& theEnt,
XCAFDimTolObjects_GeomToleranceType& theType)
{
- if(!theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance)))
+ if(theEnt.IsNull() || !theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance)))
return Standard_False;
theType = XCAFDimTolObjects_GeomToleranceType_None;
if (theEnt->IsKind(STANDARD_TYPE(StepDimTol_GeoTolAndGeoTolWthDatRef)))
//=======================================================================
Standard_Boolean STEPCAFControl_Reader::ReadGDTs(const Handle(XSControl_WorkSession)& theWS,
- Handle(TDocStd_Document)& theDoc) const
+ Handle(TDocStd_Document)& theDoc)
{
const Handle(Interface_InterfaceModel) &aModel = theWS->Model();
+ const Interface_Graph& aGraph = theWS->Graph();
+ const Handle(XSControl_TransferReader) &aTR = theWS->TransferReader();
Handle(StepData_StepModel) aSM = Handle(StepData_StepModel)::DownCast(aModel);
Interface_EntityIterator anI = aSM->Header();
Handle(HeaderSection_FileSchema) aH;
}
}
}
+ else if (anEnt->IsKind(STANDARD_TYPE(StepVisual_DraughtingCallout)) ||
+ anEnt->IsKind(STANDARD_TYPE(StepVisual_AnnotationOccurrence)))
+ {
+ // Protection against import presentation twice
+ Handle(StepVisual_DraughtingCallout) aDC;
+ for (Interface_EntityIterator anIter = aGraph.Sharings(anEnt); anIter.More() && aDC.IsNull(); anIter.Next()) {
+ aDC = Handle(StepVisual_DraughtingCallout)::DownCast(anIter.Value());
+ }
+ if (!aDC.IsNull())
+ continue;
+ // Read presentations for PMIs without semantic data.
+ Handle(StepAP242_DraughtingModelItemAssociation) aDMIA;
+ TDF_LabelSequence aShapesL;
+ for (Interface_EntityIterator anIter = aGraph.Sharings(anEnt); anIter.More() && aDMIA.IsNull(); anIter.Next()) {
+ aDMIA = Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(anIter.Value());
+ }
+ if (!aDMIA.IsNull()) {
+ // Check entity, skip all, attached to GDTs
+ Handle(StepRepr_ShapeAspect) aDefinition = aDMIA->Definition().ShapeAspect();
+ if (!aDefinition.IsNull()) {
+ Standard_Boolean isConnectedToGDT = Standard_False;
+ // Skip if definition is a datum
+ if (aDefinition->IsKind(STANDARD_TYPE(StepDimTol_Datum)) ||
+ aDefinition->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)) ||
+ aDefinition->IsKind(STANDARD_TYPE(StepDimTol_DatumFeature)) ||
+ aDefinition->IsKind(STANDARD_TYPE(StepRepr_CompShAspAndDatumFeatAndShAsp))) {
+ isConnectedToGDT = Standard_True;
+ }
+ // Skip if any GDT is applied to definition
+ for (Interface_EntityIterator anIter = aGraph.Sharings(aDefinition); anIter.More() && !isConnectedToGDT; anIter.Next()) {
+ if (anIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) ||
+ anIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) ||
+ anIter.Value()->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
+ isConnectedToGDT = Standard_True;
+ continue;
+ }
+ Handle(StepRepr_ShapeAspectRelationship) aSAR = Handle(StepRepr_ShapeAspectRelationship)::DownCast(anIter.Value());
+ if (!aSAR.IsNull()) {
+ Handle(StepRepr_ShapeAspect) aSA = aSAR->RelatedShapeAspect();
+ if (!aSA.IsNull()) {
+ if (aSA->IsKind(STANDARD_TYPE(StepDimTol_Datum)) ||
+ aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumTarget)) ||
+ aSA->IsKind(STANDARD_TYPE(StepDimTol_DatumFeature)) ||
+ aSA->IsKind(STANDARD_TYPE(StepRepr_CompShAspAndDatumFeatAndShAsp))) {
+ isConnectedToGDT = Standard_True;
+ }
+ for (Interface_EntityIterator aDimIter = aGraph.Sharings(aSA); aDimIter.More() && !isConnectedToGDT; aDimIter.Next()) {
+ if (aDimIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalSize)) ||
+ aDimIter.Value()->IsKind(STANDARD_TYPE(StepShape_DimensionalLocation)) ||
+ aDimIter.Value()->IsKind(STANDARD_TYPE(StepDimTol_GeometricTolerance))) {
+ isConnectedToGDT = Standard_True;
+ continue;
+ }
+ }
+ }
+ }
+ }
+ if (isConnectedToGDT)
+ continue;
+ }
+ else if (aDMIA->Definition().PropertyDefinition().IsNull())
+ continue;
+
+ // Get shapes
+ NCollection_Sequence<Handle(StepRepr_ShapeAspect)> aSAs;
+ collectShapeAspect(aDefinition, theWS, aSAs);
+ for (Standard_Integer aSAIt = 1; aSAIt <= aSAs.Length(); aSAIt++) {
+ Handle(StepAP242_GeometricItemSpecificUsage) aGISU;
+ for (Interface_EntityIterator anIter = aGraph.Sharings(aSAs.Value(aSAIt)); anIter.More() && aGISU.IsNull(); anIter.Next())
+ aGISU = Handle(StepAP242_GeometricItemSpecificUsage)::DownCast(anIter.Value());
+ if (aGISU.IsNull())
+ continue;
+ for (Standard_Integer anItemIt = 1; anItemIt <= aGISU->NbIdentifiedItem(); anItemIt++) {
+ TDF_Label aLabel = getShapeLabel(aGISU->IdentifiedItemValue(anItemIt), theWS, XCAFDoc_DocumentTool::ShapeTool(theDoc->Main()));
+ if (!aLabel.IsNull())
+ aShapesL.Append(aLabel);
+ }
+ }
+ }
+ Standard_Boolean isCommonLabel = (aShapesL.Length() == 0);
+
+ // Calculate unit
+ Standard_Real aFact = 1.0;
+ if (!aDMIA.IsNull() && !aDMIA->UsedRepresentation().IsNull())
+ GetLengthConversionFactorFromContext(aDMIA->UsedRepresentation()->ContextOfItems(), aFact);
+
+ // Presentation
+ TopoDS_Shape aPresentation;
+ Handle(TCollection_HAsciiString) aPresentName;
+ Bnd_Box aBox;
+ if (!readPMIPresentation(anEnt, aTR, aFact, aPresentation, aPresentName, aBox))
+ continue;
+ // Annotation plane
+ Handle(StepVisual_AnnotationPlane) anAnPlane;
+ for (Interface_EntityIterator anIter = aGraph.Sharings(anEnt); anIter.More() && anAnPlane.IsNull(); anIter.Next())
+ anAnPlane = Handle(StepVisual_AnnotationPlane)::DownCast(anIter.Value());
+
+ // Set object to XCAF
+ TDF_Label aGDTL = aDGTTool->AddDimension();
+ myGDTMap.Bind(anEnt, aGDTL);
+ aDGTTool->Lock(aGDTL);
+ Handle(XCAFDimTolObjects_DimensionObject) aDimObj = new XCAFDimTolObjects_DimensionObject();
+ Handle(XCAFDoc_Dimension) aDim = XCAFDoc_Dimension::Set(aGDTL);
+ TCollection_AsciiString aStr("DGT:");
+ if (isCommonLabel) {
+ aStr.AssignCat("Common_label");
+ aDimObj->SetType(XCAFDimTolObjects_DimensionType_CommonLabel);
+ }
+ else {
+ aStr.AssignCat("Dimension");
+ aDimObj->SetType(XCAFDimTolObjects_DimensionType_DimensionPresentation);
+ }
+ TDataStd_Name::Set(aGDTL, aStr);
+ TDF_LabelSequence anEmptySeq2;
+ aDGTTool->SetDimension(aShapesL, anEmptySeq2, aGDTL);
+ gp_Ax2 aPlaneAxes;
+ if (!anAnPlane.IsNull()) {
+ if (readAnnotationPlane(anAnPlane, aFact, aPlaneAxes))
+ aDimObj->SetPlane(aPlaneAxes);
+ }
+ aDimObj->SetPresentation(aPresentation, aPresentName);
+ aDim->SetObject(aDimObj);
+ }
}
return Standard_True;
}
return Standard_True;
}
+//=======================================================================
+//function : collectViewShapes
+//purpose : collect all labels of representations in given representation
+//=======================================================================
+
+void collectViewShapes(const Handle(XSControl_WorkSession)& theWS,
+ const Handle(TDocStd_Document)& theDoc,
+ const Handle(StepRepr_Representation) theRepr,
+ TDF_LabelSequence& theShapes)
+{
+ Handle(XSControl_TransferReader) aTR = theWS->TransferReader();
+ Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
+ const Interface_Graph& aGraph = aTP->Graph();
+ Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
+ Standard_Integer anIndex = aTP->MapIndex(theRepr);
+ TopoDS_Shape aSh;
+ if (anIndex > 0) {
+ Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
+ aSh = TransferBRep::ShapeResult(aBinder);
+ }
+ if (!aSh.IsNull()) {
+ TDF_Label aShL;
+ aSTool->FindShape(aSh, aShL);
+ if (!aShL.IsNull())
+ theShapes.Append(aShL);
+ }
+ Interface_EntityIterator anIter = aGraph.Sharings(theRepr);
+ for (; anIter.More(); anIter.Next()) {
+ if (!anIter.Value()->IsKind(STANDARD_TYPE(StepRepr_RepresentationRelationship)))
+ continue;
+ Handle(StepRepr_RepresentationRelationship) aReprRelationship = Handle(StepRepr_RepresentationRelationship)::DownCast(anIter.Value());
+ if (aReprRelationship->Rep1() != theRepr)
+ collectViewShapes(theWS, theDoc, aReprRelationship->Rep1(), theShapes);
+ }
+}
+
+//=======================================================================
+//function : buildClippingPlanes
+//purpose :
+//=======================================================================
+Handle(TCollection_HAsciiString) buildClippingPlanes(const Handle(StepGeom_GeometricRepresentationItem)& theClippingCameraModel,
+ TDF_LabelSequence& theClippingPlanes,
+ const Handle(XCAFDoc_ClippingPlaneTool) theTool)
+{
+ Handle(TCollection_HAsciiString) anExpression = new TCollection_HAsciiString();
+ NCollection_Sequence<Handle(StepGeom_GeometricRepresentationItem)> aPlanes;
+ Handle(TCollection_HAsciiString) anOperation = new TCollection_HAsciiString("*");
+
+ // Store operands
+ if (theClippingCameraModel->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3MultiClipping))) {
+ Handle(StepVisual_CameraModelD3MultiClipping) aCameraModel =
+ Handle(StepVisual_CameraModelD3MultiClipping)::DownCast(theClippingCameraModel);
+ // Root of clipping planes tree
+ if (aCameraModel->ShapeClipping()->Length() == 1) {
+ Handle(StepVisual_CameraModelD3MultiClippingUnion) aCameraModelUnion =
+ aCameraModel->ShapeClipping()->Value(1).CameraModelD3MultiClippingUnion();
+ if (!aCameraModelUnion.IsNull())
+ return buildClippingPlanes(aCameraModelUnion, theClippingPlanes, theTool);
+ }
+ for (Standard_Integer i = 1; i <= aCameraModel->ShapeClipping()->Length(); i++) {
+ aPlanes.Append(Handle(StepGeom_GeometricRepresentationItem)::DownCast(aCameraModel->ShapeClipping()->Value(i).Value()));
+ }
+ }
+ else if (theClippingCameraModel->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3MultiClippingUnion))) {
+ Handle(StepVisual_CameraModelD3MultiClippingUnion) aCameraModel =
+ Handle(StepVisual_CameraModelD3MultiClippingUnion)::DownCast(theClippingCameraModel);
+ anOperation = new TCollection_HAsciiString("+");
+ for (Standard_Integer i = 1; i <= aCameraModel->ShapeClipping()->Length(); i++) {
+ aPlanes.Append(Handle(StepGeom_GeometricRepresentationItem)::DownCast(aCameraModel->ShapeClipping()->Value(i).Value()));
+ }
+ }
+ else if (theClippingCameraModel->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3MultiClippingIntersection))) {
+ Handle(StepVisual_CameraModelD3MultiClippingIntersection) aCameraModel =
+ Handle(StepVisual_CameraModelD3MultiClippingIntersection)::DownCast(theClippingCameraModel);
+ for (Standard_Integer i = 1; i <= aCameraModel->ShapeClipping()->Length(); i++) {
+ aPlanes.Append(Handle(StepGeom_GeometricRepresentationItem)::DownCast(aCameraModel->ShapeClipping()->Value(i).Value()));
+ }
+ }
+ // Build expression
+ anExpression->AssignCat("(");
+ for (Standard_Integer i = 1; i <= aPlanes.Length(); i++) {
+ Handle(StepGeom_Plane) aPlaneEnt = Handle(StepGeom_Plane)::DownCast(aPlanes.Value(i));
+ if (!aPlaneEnt.IsNull()) {
+ Handle(Geom_Plane) aPlane = StepToGeom::MakePlane(aPlaneEnt);
+ if (!aPlane.IsNull()) {
+ TDF_Label aPlaneL = theTool->AddClippingPlane(aPlane->Pln(), aPlaneEnt->Name());
+ theClippingPlanes.Append(aPlaneL);
+ TCollection_AsciiString anEntry;
+ TDF_Tool::Entry(aPlaneL, anEntry);
+ anExpression->AssignCat(new TCollection_HAsciiString(anEntry));
+ }
+ }
+ else {
+ anExpression->AssignCat(buildClippingPlanes(aPlanes.Value(i), theClippingPlanes, theTool));
+ }
+ anExpression->AssignCat(anOperation);
+ }
+ // Insert brace instead of operation after last operand.
+ anExpression->SetValue(anExpression->Length(), ')');
+ return anExpression;
+}
+
+
+//=======================================================================
+//function : ReadViews
+//purpose :
+//=======================================================================
+Standard_Boolean STEPCAFControl_Reader::ReadViews(const Handle(XSControl_WorkSession)& theWS, Handle(TDocStd_Document)& theDoc) const
+{
+ const Handle(Interface_InterfaceModel) &aModel = theWS->Model();
+ Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
+ Handle(XCAFDoc_DimTolTool) aDGTTool = XCAFDoc_DocumentTool::DimTolTool(theDoc->Main());
+ Handle(XCAFDoc_ViewTool) aViewTool = XCAFDoc_DocumentTool::ViewTool(theDoc->Main());
+ if (aDGTTool.IsNull()) return Standard_False;
+
+ Standard_Integer nb = aModel->NbEntities();
+ for (Standard_Integer i = 1; i <= nb; i++) {
+ Handle(Standard_Transient) anEnt = aModel->Value(i);
+ if (!anEnt->IsKind(STANDARD_TYPE(StepVisual_CameraModelD3)))
+ continue;
+ Handle(XCAFView_Object) anObj = new XCAFView_Object();
+ // Import attributes of view
+ Handle(StepVisual_CameraModelD3) aCameraModel = Handle(StepVisual_CameraModelD3)::DownCast(anEnt);
+ anObj->SetName(aCameraModel->Name());
+ Handle(Geom_Axis2Placement) anAxis = StepToGeom::MakeAxis2Placement(aCameraModel->ViewReferenceSystem());
+ anObj->SetViewDirection(anAxis->Direction());
+ anObj->SetUpDirection(anAxis->Direction() ^ anAxis->XDirection());
+ Handle(StepVisual_ViewVolume) aViewVolume = aCameraModel->PerspectiveOfVolume();
+ XCAFView_ProjectionType aType = XCAFView_ProjectionType_NoCamera;
+ if (aViewVolume->ProjectionType() == StepVisual_copCentral)
+ aType = XCAFView_ProjectionType_Central;
+ else if (aViewVolume->ProjectionType() == StepVisual_copParallel)
+ aType = XCAFView_ProjectionType_Parallel;
+ anObj->SetType(aType);
+ Handle(Geom_CartesianPoint) aPoint = StepToGeom::MakeCartesianPoint(aViewVolume->ProjectionPoint());
+ anObj->SetProjectionPoint(aPoint->Pnt());
+ anObj->SetZoomFactor(aViewVolume->ViewPlaneDistance());
+ anObj->SetWindowHorizontalSize(aViewVolume->ViewWindow()->SizeInX());
+ anObj->SetWindowVerticalSize(aViewVolume->ViewWindow()->SizeInY());
+ if (aViewVolume->FrontPlaneClipping())
+ anObj->SetFrontPlaneDistance(aViewVolume->FrontPlaneDistance());
+ if (aViewVolume->BackPlaneClipping())
+ anObj->SetBackPlaneDistance(aViewVolume->BackPlaneDistance());
+ anObj->SetViewVolumeSidesClipping(aViewVolume->ViewVolumeSidesClipping());
+ // Clipping plane
+ Handle(StepVisual_CameraModelD3MultiClipping) aClippingCameraModel =
+ Handle(StepVisual_CameraModelD3MultiClipping)::DownCast(aCameraModel);
+ TDF_LabelSequence aClippingPlanes;
+ if (!aClippingCameraModel.IsNull()) {
+ Handle(TCollection_HAsciiString) aClippingExpression;
+ Handle(XCAFDoc_ClippingPlaneTool) aClippingPlaneTool = XCAFDoc_DocumentTool::ClippingPlaneTool(theDoc->Main());
+ aClippingExpression = buildClippingPlanes(aClippingCameraModel, aClippingPlanes, aClippingPlaneTool);
+ anObj->SetClippingExpression(aClippingExpression);
+ }
+ // Collect shapes and GDTs
+ TDF_LabelSequence aShapes, aGDTs;
+ Handle(XSControl_TransferReader) aTR = theWS->TransferReader();
+ Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
+ const Interface_Graph& aGraph = aTP->Graph();
+ Handle(StepVisual_DraughtingModel) aDModel;
+ Interface_EntityIterator anIter = aGraph.Sharings(aCameraModel);
+ for (; anIter.More() && aDModel.IsNull(); anIter.Next()) {
+ aDModel = Handle(StepVisual_DraughtingModel)::DownCast(anIter.Value());
+ }
+ if (aDModel.IsNull())
+ return Standard_False;
+
+ anIter = aGraph.Shareds(aDModel);
+ for (; anIter.More(); anIter.Next()) {
+ if (anIter.Value()->IsKind(STANDARD_TYPE(StepRepr_MappedItem))) {
+ Handle(StepRepr_MappedItem) anItem = Handle(StepRepr_MappedItem)::DownCast(anIter.Value());
+ Handle(StepRepr_Representation) aRepr = anItem->MappingSource()->MappedRepresentation();
+ collectViewShapes(theWS, theDoc, aRepr, aShapes);
+ }
+ else if (anIter.Value()->IsKind(STANDARD_TYPE(StepVisual_AnnotationOccurrence)) ||
+ anIter.Value()->IsKind(STANDARD_TYPE(StepVisual_DraughtingCallout))) {
+ Interface_EntityIterator aDMIAIter = aGraph.Sharings(anIter.Value());
+ for (; aDMIAIter.More(); aDMIAIter.Next()) {
+ if (!aDMIAIter.Value()->IsKind(STANDARD_TYPE(StepAP242_DraughtingModelItemAssociation)))
+ continue;
+ Handle(StepAP242_DraughtingModelItemAssociation) aDMIA =
+ Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(aDMIAIter.Value());
+ TDF_Label aGDTL;
+ Standard_Boolean isFind = myGDTMap.Find(aDMIA->Definition().Value(), aGDTL);
+ if (isFind)
+ aGDTs.Append(aGDTL);
+ }
+ }
+ else if (anIter.Value()->IsKind(STANDARD_TYPE(StepVisual_AnnotationPlane))) {
+ Handle(StepVisual_AnnotationPlane) aPlane = Handle(StepVisual_AnnotationPlane)::DownCast(anIter.Value());
+ for (Standard_Integer j = 1; j <= aPlane->NbElements(); j++) {
+ Interface_EntityIterator aDMIAIter = aGraph.Sharings(anIter.Value());
+ for (; aDMIAIter.More(); aDMIAIter.Next()) {
+ if (!aDMIAIter.Value()->IsKind(STANDARD_TYPE(StepAP242_DraughtingModelItemAssociation)))
+ continue;
+ Handle(StepAP242_DraughtingModelItemAssociation) aDMIA =
+ Handle(StepAP242_DraughtingModelItemAssociation)::DownCast(aDMIAIter.Value());
+ TDF_Label aGDTL;
+ Standard_Boolean isFind = myGDTMap.Find(aDMIA->Definition().Value(), aGDTL);
+ if (isFind)
+ aGDTs.Append(aGDTL);
+ }
+ }
+ }
+ }
+ TDF_Label aViewL = aViewTool->AddView();
+ Handle(XCAFDoc_View) aView = XCAFDoc_View::Set(aViewL);
+ aView->SetObject(anObj);
+ aViewTool->SetView(aShapes, aGDTs, aClippingPlanes, aViewL);
+ aViewTool->Lock(aViewL);
+ }
+ return Standard_True;
+}
+
//=======================================================================
//function : SettleShapeData
//purpose :
{
return myMatMode;
}
+
+//=======================================================================
+//function : SetViewMode
+//purpose :
+//=======================================================================
+
+void STEPCAFControl_Reader::SetViewMode(const Standard_Boolean viewmode)
+{
+ myViewMode = viewmode;
+}
+
+//=======================================================================
+//function : GetViewMode
+//purpose :
+//=======================================================================
+
+Standard_Boolean STEPCAFControl_Reader::GetViewMode() const
+{
+ return myViewMode;
+}