1 // Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "GEOM_SubShapeDriver.hxx"
25 #include "GEOM_ISubShape.hxx"
26 #include "GEOM_Function.hxx"
27 #include "GEOM_Object.hxx"
29 #include <BRep_Builder.hxx>
31 #include <TopTools_IndexedMapOfShape.hxx>
32 #include <TopTools_MapOfShape.hxx>
33 #include <TopoDS_Compound.hxx>
34 #include <TopoDS_Shape.hxx>
35 #include <TDataStd_Integer.hxx>
37 #include <Standard_NullObject.hxx>
39 //=======================================================================
40 //function : GEOM_SubShapeDriver
42 //=======================================================================
43 GEOM_SubShapeDriver::GEOM_SubShapeDriver()
47 //=======================================================================
50 //=======================================================================
51 Standard_Integer GEOM_SubShapeDriver::Execute(Handle(TFunction_Logbook)& log) const
53 if (Label().IsNull()) return 0;
54 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
56 GEOM_ISubShape aCI (aFunction);
58 TDF_Label aLabel = aCI.GetMainShape()->GetOwnerEntry();
59 if (aLabel.IsRoot()) return 0;
60 Handle(GEOM_Object) anObj = GEOM_Object::GetObject(aLabel);
61 if (anObj.IsNull()) return 0;
62 TopoDS_Shape aMainShape = anObj->GetValue();
63 if (aMainShape.IsNull()) return 0;
65 Handle(TColStd_HArray1OfInteger) anIndices = aCI.GetIndices();
66 if (anIndices.IsNull() || anIndices->Length() <= 0) return 0;
69 TopoDS_Compound aCompound;
72 if (anIndices->Length() == 1 && anIndices->Value(1) == -1) { //The empty sub-shape
73 B.MakeCompound(aCompound);
77 TopTools_IndexedMapOfShape aMapOfShapes;
78 TopExp::MapShapes(aMainShape, aMapOfShapes);
80 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);
94 int i = anIndices->Lower();
95 if (aMapOfShapes.Extent() < anIndices->Value(i))
96 Standard_NullObject::Raise("GEOM_SubShapeDriver::Execute: Index is out of range");
97 aShape = aMapOfShapes.FindKey(anIndices->Value(i));
101 if (aShape.IsNull()) return 0;
103 aFunction->SetValue(aShape);
104 log->SetTouched(Label());
109 //================================================================================
111 * \brief Returns a name of creation operation and names and values of creation parameters
113 //================================================================================
115 bool GEOM_SubShapeDriver::
116 GetCreationInformation(std::string& theOperationName,
117 std::vector<GEOM_Param>& theParams)
119 if (Label().IsNull()) return 0;
120 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
121 GEOM_ISubShape aCI( function );
123 enum { GEOM_SUBSHAPE = 28, GEOM_GROUP = 37 };
125 TDF_Label aLabel = function->GetOwnerEntry();
126 if (aLabel.IsRoot()) return false;
127 Handle(GEOM_Object) obj = GEOM_Object::GetObject( aLabel );
128 if ( obj.IsNull() ) return false;
130 switch ( obj->GetType() ) {
132 theOperationName = "EXPLODE";
133 AddParam( theParams, "Main Object", aCI.GetMainShape() );
134 AddParam( theParams, "Index", aCI.GetIndices() );
138 theOperationName = "GROUP_CREATE";
139 TopAbs_ShapeEnum type = TopAbs_SHAPE;
141 TDF_Label aFreeLabel = obj->GetFreeLabel();
142 Handle(TDataStd_Integer) anAttrib;
143 if(aFreeLabel.FindAttribute(TDataStd_Integer::GetID(), anAttrib))
144 type = (TopAbs_ShapeEnum) anAttrib->Get();
146 AddParam( theParams, "Shape Type", type );
147 AddParam( theParams, "Main Shape", aCI.GetMainShape() );
148 AddParam( theParams, "Indices", aCI.GetIndices() );
158 IMPLEMENT_STANDARD_RTTIEXT (GEOM_SubShapeDriver,GEOM_BaseDriver)