1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include <Standard_Stream.hxx>
23 #include <GEOM_SubShapeDriver.hxx>
24 #include <GEOM_ISubShape.hxx>
25 #include <GEOM_Function.hxx>
26 #include <GEOM_Object.hxx>
28 #include <BRep_Tool.hxx>
29 #include <BRep_Builder.hxx>
30 #include <BRepGProp.hxx>
35 #include <TopoDS_Shape.hxx>
36 #include <TopoDS_Edge.hxx>
37 #include <TopoDS_Wire.hxx>
38 #include <TopoDS_Solid.hxx>
39 #include <TopoDS_Compound.hxx>
40 #include <TopoDS_Iterator.hxx>
41 #include <TopExp_Explorer.hxx>
42 #include <TopTools_MapOfShape.hxx>
43 #include <TopTools_SequenceOfShape.hxx>
44 #include <TopTools_Array1OfShape.hxx>
45 #include <TopTools_IndexedMapOfShape.hxx>
47 #include <GProp_GProps.hxx>
49 #include <TColStd_Array1OfReal.hxx>
51 #include <Precision.hxx>
52 #include <Standard_NullObject.hxx>
53 #include <Standard_TypeMismatch.hxx>
56 //=======================================================================
57 //function : GEOM_SubShapeDriver
59 //=======================================================================
60 GEOM_SubShapeDriver::GEOM_SubShapeDriver()
64 //=======================================================================
67 //=======================================================================
68 Standard_Integer GEOM_SubShapeDriver::Execute(TFunction_Logbook& log) const
70 if (Label().IsNull()) return 0;
71 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
73 GEOM_ISubShape aCI (aFunction);
75 TDF_Label aLabel = aCI.GetMainShape()->GetOwnerEntry();
76 if (aLabel.IsRoot()) return 0;
77 Handle(GEOM_Object) anObj = GEOM_Object::GetObject(aLabel);
78 if (anObj.IsNull()) return 0;
79 TopoDS_Shape aMainShape = anObj->GetValue();
80 if (aMainShape.IsNull()) return 0;
82 Handle(TColStd_HArray1OfInteger) anIndices = aCI.GetIndices();
83 if (anIndices.IsNull() || anIndices->Length() <= 0) return 0;
86 TopoDS_Compound aCompound;
89 if (anIndices->Length() == 1 && anIndices->Value(1) == -1) { //The empty subshape
90 B.MakeCompound(aCompound);
95 TopTools_IndexedMapOfShape aMapOfShapes;
96 TopExp::MapShapes(aMainShape, aMapOfShapes);
98 if (anIndices->Length() > 1) {
100 B.MakeCompound(aCompound);
102 for (int i = anIndices->Lower(); i<= anIndices->Upper(); i++) {
103 if (aMapOfShapes.Extent() < anIndices->Value(i))
104 Standard_NullObject::Raise("GEOM_SubShapeDriver::Execute: Index is out of range");
105 TopoDS_Shape aSubShape = aMapOfShapes.FindKey(anIndices->Value(i));
106 if (aSubShape.IsNull()) continue;
107 B.Add(aCompound,aSubShape);
114 if (aMapOfShapes.Extent() < anIndices->Value(1))
115 Standard_NullObject::Raise("GEOM_SubShapeDriver::Execute: Index is out of range");
116 aShape = aMapOfShapes.FindKey(anIndices->Value(1));
120 if (aShape.IsNull()) return 0;
122 aFunction->SetValue(aShape);
124 log.SetTouched(Label());
130 //=======================================================================
131 //function : GEOM_SubShapeDriver_Type_
133 //=======================================================================
134 Standard_EXPORT Handle_Standard_Type& GEOM_SubShapeDriver_Type_()
137 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
138 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
139 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
140 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
141 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
142 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
145 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
146 static Handle_Standard_Type _aType = new Standard_Type("GEOM_SubShapeDriver",
147 sizeof(GEOM_SubShapeDriver),
149 (Standard_Address)_Ancestors,
150 (Standard_Address)NULL);
155 //=======================================================================
156 //function : DownCast
158 //=======================================================================
159 const Handle(GEOM_SubShapeDriver) Handle(GEOM_SubShapeDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
161 Handle(GEOM_SubShapeDriver) _anOtherObject;
163 if (!AnObject.IsNull()) {
164 if (AnObject->IsKind(STANDARD_TYPE(GEOM_SubShapeDriver))) {
165 _anOtherObject = Handle(GEOM_SubShapeDriver)((Handle(GEOM_SubShapeDriver)&)AnObject);
169 return _anOtherObject ;