3 #include "GEOM_SubShapeDriver.hxx"
4 #include "GEOM_ISubShape.hxx"
5 #include "GEOM_Function.hxx"
6 #include "GEOM_Object.hxx"
8 #include <BRep_Tool.hxx>
9 #include <BRep_Builder.hxx>
10 #include <BRepGProp.hxx>
15 #include <TopoDS_Shape.hxx>
16 #include <TopoDS_Edge.hxx>
17 #include <TopoDS_Wire.hxx>
18 #include <TopoDS_Solid.hxx>
19 #include <TopoDS_Compound.hxx>
20 #include <TopoDS_Iterator.hxx>
21 #include <TopExp_Explorer.hxx>
22 #include <TopTools_MapOfShape.hxx>
23 #include <TopTools_SequenceOfShape.hxx>
24 #include <TopTools_Array1OfShape.hxx>
25 #include <TopTools_IndexedMapOfShape.hxx>
27 #include <GProp_GProps.hxx>
29 #include <TColStd_Array1OfReal.hxx>
31 #include <Precision.hxx>
32 #include <Standard_NullObject.hxx>
33 #include <Standard_TypeMismatch.hxx>
36 //=======================================================================
37 //function : GEOM_SubShapeDriver
39 //=======================================================================
40 GEOM_SubShapeDriver::GEOM_SubShapeDriver()
44 //=======================================================================
47 //=======================================================================
48 Standard_Integer GEOM_SubShapeDriver::Execute(TFunction_Logbook& log) const
50 if (Label().IsNull()) return 0;
51 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
53 GEOM_ISubShape aCI (aFunction);
55 TDF_Label aLabel = aCI.GetMainShape()->GetOwnerEntry();
56 if (aLabel.IsRoot()) return 0;
57 Handle(GEOM_Object) anObj = GEOM_Object::GetObject(aLabel);
58 if (anObj.IsNull()) return 0;
59 TopoDS_Shape aMainShape = anObj->GetValue();
60 if (aMainShape.IsNull()) return 0;
62 Handle(TColStd_HArray1OfInteger) anIndices = aCI.GetIndices();
63 if (anIndices.IsNull() || anIndices->Length() <= 0) return 0;
66 TopoDS_Compound aCompound;
69 if (anIndices->Length() == 1 && anIndices->Value(1) == -1) { //The empty subshape
70 B.MakeCompound(aCompound);
75 TopTools_IndexedMapOfShape aMapOfShapes;
76 TopExp::MapShapes(aMainShape, aMapOfShapes);
78 if (anIndices->Length() > 1) {
80 B.MakeCompound(aCompound);
82 for (int i = anIndices->Lower(); i<= anIndices->Upper(); i++) {
83 if (aMapOfShapes.Extent() < anIndices->Value(i))
84 Standard_NullObject::Raise("GEOM_SubShapeDriver::Execute: Index is out of range");
85 TopoDS_Shape aSubShape = aMapOfShapes.FindKey(anIndices->Value(i));
86 if (aSubShape.IsNull()) continue;
87 B.Add(aCompound,aSubShape);
94 if (aMapOfShapes.Extent() < anIndices->Value(1))
95 Standard_NullObject::Raise("GEOM_SubShapeDriver::Execute: Index is out of range");
96 aShape = aMapOfShapes.FindKey(anIndices->Value(1));
100 if (aShape.IsNull()) return 0;
102 aFunction->SetValue(aShape);
104 log.SetTouched(Label());
110 //=======================================================================
111 //function : GEOM_SubShapeDriver_Type_
113 //=======================================================================
114 Standard_EXPORT Handle_Standard_Type& GEOM_SubShapeDriver_Type_()
117 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
118 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
119 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
120 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
121 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
122 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
125 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
126 static Handle_Standard_Type _aType = new Standard_Type("GEOM_SubShapeDriver",
127 sizeof(GEOM_SubShapeDriver),
129 (Standard_Address)_Ancestors,
130 (Standard_Address)NULL);
135 //=======================================================================
136 //function : DownCast
138 //=======================================================================
139 const Handle(GEOM_SubShapeDriver) Handle(GEOM_SubShapeDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
141 Handle(GEOM_SubShapeDriver) _anOtherObject;
143 if (!AnObject.IsNull()) {
144 if (AnObject->IsKind(STANDARD_TYPE(GEOM_SubShapeDriver))) {
145 _anOtherObject = Handle(GEOM_SubShapeDriver)((Handle(GEOM_SubShapeDriver)&)AnObject);
149 return _anOtherObject ;