3 #include "GEOMImpl_IGroupOperations.hxx"
7 #include "Utils_ExceptHandlers.hxx"
9 #include <TFunction_DriverTable.hxx>
10 #include <TFunction_Driver.hxx>
11 #include <TFunction_Logbook.hxx>
12 #include <TDF_Tool.hxx>
13 #include <TDataStd_Integer.hxx>
15 #include "GEOM_Function.hxx"
16 #include "GEOMImpl_Types.hxx"
17 #include "GEOM_ISubShape.hxx"
20 #include <TopTools_IndexedMapOfShape.hxx>
21 #include <TColStd_HArray1OfInteger.hxx>
23 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
25 //=============================================================================
29 //=============================================================================
30 GEOMImpl_IGroupOperations::GEOMImpl_IGroupOperations (GEOM_Engine* theEngine, int theDocID)
31 : GEOM_IOperations(theEngine, theDocID)
33 MESSAGE("GEOMImpl_IGroupOperations::GEOMImpl_IGroupOperations");
36 //=============================================================================
40 //=============================================================================
41 GEOMImpl_IGroupOperations::~GEOMImpl_IGroupOperations()
43 MESSAGE("GEOMImpl_IGroupOperations::~GEOMImpl_IGroupOperations");
47 //=============================================================================
51 //=============================================================================
52 Handle(GEOM_Object) GEOMImpl_IGroupOperations::CreateGroup(Handle(GEOM_Object) theMainShape, TopAbs_ShapeEnum theShapeType)
56 Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1,1);
57 anArray->SetValue(1, -1);
59 //Add a new Fillet object
60 Handle(GEOM_Object) aGroup = GetEngine()->AddSubShape(theMainShape, anArray);
63 aGroup->SetType(GEOM_GROUP);
65 //Set a sub shape type
66 TDF_Label aFreeLabel = aGroup->GetFreeLabel();
67 TDataStd_Integer::Set(aFreeLabel, (Standard_Integer)theShapeType);
69 //Make a Python command
70 TCollection_AsciiString anEntry, aDescr("");
71 TDF_Tool::Entry(aGroup->GetEntry(), anEntry);
72 aDescr = anEntry + " = IGroupOperations.CreateGroup(";
73 TDF_Tool::Entry(theMainShape->GetEntry(), anEntry);
74 aDescr += (anEntry+", ");
75 aDescr += (TCollection_AsciiString((int)theShapeType)+")");
77 Handle(GEOM_Function) aFunction = aGroup->GetFunction(1);
78 aFunction->SetDescription(aDescr);
84 //=============================================================================
88 //=============================================================================
89 void GEOMImpl_IGroupOperations::AddObject(Handle(GEOM_Object) theGroup, int theSubShapeID)
92 if(theGroup.IsNull()) return;
94 Handle(GEOM_Function) aFunction = theGroup->GetFunction(1);
95 if(aFunction.IsNull()) return;
97 GEOM_ISubShape aSSI(aFunction);
98 Handle(TColStd_HArray1OfInteger) aSeq = aSSI.GetIndices();
99 if(aSeq.IsNull()) return;
100 if(aSeq->Length() == 1 && aSeq->Value(1) == -1) {
101 aSeq->SetValue(1, theSubShapeID);
104 Standard_Integer aLength = aSeq->Length();
105 Handle(TColStd_HArray1OfInteger) aNewSeq = new TColStd_HArray1OfInteger(1, aLength+1);
106 for(Standard_Integer i = 1; i<=aLength; i++) {
107 aNewSeq->SetValue(i, aSeq->Value(i));
108 if(aSeq->Value(i) == theSubShapeID) {
109 SetErrorCode(ALREADY_PRESENT);
113 aNewSeq->SetValue(aLength+1, theSubShapeID);
114 aSSI.SetIndices(aNewSeq);
121 //=============================================================================
125 //=============================================================================
126 void GEOMImpl_IGroupOperations::RemoveObject(Handle(GEOM_Object) theGroup, int theSubShapeID)
129 if(theGroup.IsNull()) return;
132 Handle(GEOM_Function) aFunction = theGroup->GetFunction(1);
133 if(aFunction.IsNull()) return;
136 GEOM_ISubShape aSSI(aFunction);
137 Handle(TColStd_HArray1OfInteger) aSeq = aSSI.GetIndices();
138 if(aSeq.IsNull()) return;
139 if(aSeq->Length() == 1 && aSeq->Value(1) == -1) {
140 SetErrorCode(NOT_EXISTS);
144 Handle(TColStd_HArray1OfInteger) aNewSeq;
145 Standard_Integer aLength = aSeq->Length();
147 if(aSeq->Value(1) != theSubShapeID) {
148 SetErrorCode(NOT_EXISTS);
151 aNewSeq = new TColStd_HArray1OfInteger(1,1);
152 aNewSeq->SetValue(1, -1);
155 aNewSeq = new TColStd_HArray1OfInteger(1, aLength-1);
156 Standard_Boolean isFound = Standard_False;
157 for(Standard_Integer i = 1, k=1; i<=aLength; i++) {
158 if(i == aLength && !isFound) {
159 SetErrorCode(NOT_EXISTS);
162 if(aSeq->Value(i) == theSubShapeID) {
163 isFound = Standard_True;
166 aNewSeq->SetValue(k, aSeq->Value(i));
171 SetErrorCode(NOT_EXISTS);
176 aSSI.SetIndices(aNewSeq);
184 //=============================================================================
188 //=============================================================================
189 TopAbs_ShapeEnum GEOMImpl_IGroupOperations::GetType(Handle(GEOM_Object) theGroup)
193 TDF_Label aFreeLabel = theGroup->GetFreeLabel();
194 Handle(TDataStd_Integer) anAttrib;
195 if(!aFreeLabel.FindAttribute(TDataStd_Integer::GetID(), anAttrib)) return TopAbs_SHAPE;
198 return (TopAbs_ShapeEnum) anAttrib->Get();
201 //=============================================================================
205 //=============================================================================
206 Handle(GEOM_Object) GEOMImpl_IGroupOperations::GetMainShape(Handle(GEOM_Object) theGroup)
210 if(theGroup.IsNull()) return NULL;
212 Handle(GEOM_Function) aFunction = theGroup->GetFunction(1);
213 if(aFunction.IsNull()) return NULL;
215 GEOM_ISubShape aSSI(aFunction);
216 aFunction = aSSI.GetMainShape();
217 if(aFunction.IsNull()) return NULL;
219 TDF_Label aLabel = aFunction->GetOwnerEntry();
220 Handle(GEOM_Object) aMainShape = GEOM_Object::GetObject(aLabel);
221 if(aMainShape.IsNull()) return NULL;
227 //=============================================================================
231 //=============================================================================
232 Handle(TColStd_HArray1OfInteger) GEOMImpl_IGroupOperations::GetObjects(Handle(GEOM_Object) theGroup)
236 if(theGroup.IsNull()) return NULL;
238 Handle(GEOM_Function) aFunction = theGroup->GetFunction(1);
239 if(aFunction.IsNull()) return NULL;
241 GEOM_ISubShape aSSI(aFunction);
242 Handle(TColStd_HArray1OfInteger) aSeq = aSSI.GetIndices();
243 if(aSeq.IsNull()) return NULL;
245 if(aSeq->Length() == 1 && aSeq->Value(1) == -1) {