2 #include <Standard_Stream.hxx>
4 #include <GEOM_SubShapeDriver.hxx>
5 #include <GEOM_ISubShape.hxx>
6 #include <GEOM_Function.hxx>
7 #include <GEOM_Object.hxx>
9 #include <BRep_Tool.hxx>
10 #include <BRep_Builder.hxx>
11 #include <BRepGProp.hxx>
16 #include <TopoDS_Shape.hxx>
17 #include <TopoDS_Edge.hxx>
18 #include <TopoDS_Wire.hxx>
19 #include <TopoDS_Solid.hxx>
20 #include <TopoDS_Compound.hxx>
21 #include <TopoDS_Iterator.hxx>
22 #include <TopExp_Explorer.hxx>
23 #include <TopTools_MapOfShape.hxx>
24 #include <TopTools_SequenceOfShape.hxx>
25 #include <TopTools_Array1OfShape.hxx>
26 #include <TopTools_IndexedMapOfShape.hxx>
28 #include <GProp_GProps.hxx>
30 #include <TColStd_Array1OfReal.hxx>
32 #include <Precision.hxx>
33 #include <Standard_NullObject.hxx>
34 #include <Standard_TypeMismatch.hxx>
37 //=======================================================================
38 //function : GEOM_SubShapeDriver
40 //=======================================================================
41 GEOM_SubShapeDriver::GEOM_SubShapeDriver()
45 //=======================================================================
48 //=======================================================================
49 Standard_Integer GEOM_SubShapeDriver::Execute(TFunction_Logbook& log) const
51 if (Label().IsNull()) return 0;
52 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
54 GEOM_ISubShape aCI (aFunction);
56 TDF_Label aLabel = aCI.GetMainShape()->GetOwnerEntry();
57 if (aLabel.IsRoot()) return 0;
58 Handle(GEOM_Object) anObj = GEOM_Object::GetObject(aLabel);
59 if (anObj.IsNull()) return 0;
60 TopoDS_Shape aMainShape = anObj->GetValue();
61 if (aMainShape.IsNull()) return 0;
63 Handle(TColStd_HArray1OfInteger) anIndices = aCI.GetIndices();
64 if (anIndices.IsNull() || anIndices->Length() <= 0) return 0;
67 TopoDS_Compound aCompound;
70 if (anIndices->Length() == 1 && anIndices->Value(1) == -1) { //The empty subshape
71 B.MakeCompound(aCompound);
76 TopTools_IndexedMapOfShape aMapOfShapes;
77 TopExp::MapShapes(aMainShape, aMapOfShapes);
79 if (anIndices->Length() > 1) {
81 B.MakeCompound(aCompound);
83 for (int i = anIndices->Lower(); i<= anIndices->Upper(); i++) {
84 if (aMapOfShapes.Extent() < anIndices->Value(i))
85 Standard_NullObject::Raise("GEOM_SubShapeDriver::Execute: Index is out of range");
86 TopoDS_Shape aSubShape = aMapOfShapes.FindKey(anIndices->Value(i));
87 if (aSubShape.IsNull()) continue;
88 B.Add(aCompound,aSubShape);
95 if (aMapOfShapes.Extent() < anIndices->Value(1))
96 Standard_NullObject::Raise("GEOM_SubShapeDriver::Execute: Index is out of range");
97 aShape = aMapOfShapes.FindKey(anIndices->Value(1));
101 if (aShape.IsNull()) return 0;
103 aFunction->SetValue(aShape);
105 log.SetTouched(Label());
111 //=======================================================================
112 //function : GEOM_SubShapeDriver_Type_
114 //=======================================================================
115 Standard_EXPORT Handle_Standard_Type& GEOM_SubShapeDriver_Type_()
118 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
119 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
120 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
121 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
122 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
123 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
126 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
127 static Handle_Standard_Type _aType = new Standard_Type("GEOM_SubShapeDriver",
128 sizeof(GEOM_SubShapeDriver),
130 (Standard_Address)_Ancestors,
131 (Standard_Address)NULL);
136 //=======================================================================
137 //function : DownCast
139 //=======================================================================
140 const Handle(GEOM_SubShapeDriver) Handle(GEOM_SubShapeDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
142 Handle(GEOM_SubShapeDriver) _anOtherObject;
144 if (!AnObject.IsNull()) {
145 if (AnObject->IsKind(STANDARD_TYPE(GEOM_SubShapeDriver))) {
146 _anOtherObject = Handle(GEOM_SubShapeDriver)((Handle(GEOM_SubShapeDriver)&)AnObject);
150 return _anOtherObject ;