]> SALOME platform Git repositories - modules/geom.git/blobdiff - src/GEOMImpl/GEOMImpl_IGroupOperations.cxx
Salome HOME
Remove unnecessary includes
[modules/geom.git] / src / GEOMImpl / GEOMImpl_IGroupOperations.cxx
index dc47e1f0e5e0581cc7803a5ff45175fbeb2f23e6..7c2b185700993b16b952ef3b8ca0d79e4b3019c7 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -18,6 +18,7 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 
 #include <Standard_Stream.hxx>
 
 #include <GEOM_PythonDump.hxx>
 
 #include "utilities.h"
-#include <OpUtil.hxx>
 #include <Utils_ExceptHandlers.hxx>
 
 #include <TFunction_DriverTable.hxx>
 #include <TFunction_Driver.hxx>
-#include <TFunction_Logbook.hxx>
 #include <TDF_Tool.hxx>
 #include <TDataStd_Integer.hxx>
 
@@ -53,8 +52,8 @@
  *   constructor:
  */
 //=============================================================================
-GEOMImpl_IGroupOperations::GEOMImpl_IGroupOperations (GEOM_Engine* theEngine, int theDocID)
-: GEOM_IOperations(theEngine, theDocID)
+GEOMImpl_IGroupOperations::GEOMImpl_IGroupOperations (GEOM_Engine* theEngine)
+: GEOM_IOperations(theEngine)
 {
   MESSAGE("GEOMImpl_IGroupOperations::GEOMImpl_IGroupOperations");
 }
@@ -80,6 +79,12 @@ Handle(GEOM_Object) GEOMImpl_IGroupOperations::CreateGroup
 {
   SetErrorCode(KO);
 
+  if ( theShapeType != TopAbs_VERTEX && theShapeType != TopAbs_EDGE &&
+       theShapeType != TopAbs_FACE && theShapeType != TopAbs_SOLID ) {
+    SetErrorCode( "Error: You could create group of only next type: vertex, edge, face or solid" );
+    return NULL;
+  }
+
   Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1,1);
   anArray->SetValue(1, -1);
 
@@ -113,6 +118,11 @@ void GEOMImpl_IGroupOperations::AddObject(Handle(GEOM_Object) theGroup, int theS
   SetErrorCode(KO);
   if(theGroup.IsNull()) return;
 
+  if ( theGroup->GetType() != GEOM_GROUP ) {
+    SetErrorCode( "Error: You could perform this operation only with group. Please select a group." );
+    return;
+  }
+
   Handle(GEOM_Function) aFunction = theGroup->GetLastFunction();
   if(aFunction.IsNull()) return;
 
@@ -129,6 +139,13 @@ void GEOMImpl_IGroupOperations::AddObject(Handle(GEOM_Object) theGroup, int theS
   TopTools_IndexedMapOfShape aMapOfShapes;
   TopExp::MapShapes(aMainShape, aMapOfShapes);
 
+  TopAbs_ShapeEnum aGroupType = GetType(theGroup);
+  TopAbs_ShapeEnum aShapeType = aMapOfShapes.FindKey(theSubShapeID).ShapeType();
+  if ( aGroupType != aShapeType ) {
+    SetErrorCode( "Error: You could perform this operation only with object the same type as the type of group." );
+    return;
+  }
+
   if (theSubShapeID < 1 || aMapOfShapes.Extent() < theSubShapeID) {
     SetErrorCode("Invalid sub-shape index: out of range");
     return;
@@ -184,6 +201,11 @@ void GEOMImpl_IGroupOperations::RemoveObject (Handle(GEOM_Object) theGroup, int
   SetErrorCode(KO);
   if(theGroup.IsNull()) return;
 
+  if ( theGroup->GetType() != GEOM_GROUP ) {
+    SetErrorCode( "Error: You could perform this operation only with group. Please select a group." );
+    return;
+  }
+
   Handle(GEOM_Function) aFunction = theGroup->GetLastFunction();
   if(aFunction.IsNull()) return;
 
@@ -263,6 +285,11 @@ void GEOMImpl_IGroupOperations::UnionList (Handle(GEOM_Object) theGroup,
   SetErrorCode(KO);
   if (theGroup.IsNull()) return;
 
+  if ( theGroup->GetType() != GEOM_GROUP ) {
+    SetErrorCode( "Error: You could perform this operation only with group. Please select a group." );
+    return;
+  }
+
   Standard_Integer aLen = theSubShapes->Length();
   if (aLen < 1) {
     //SetErrorCode("The list is empty");
@@ -413,6 +440,11 @@ void GEOMImpl_IGroupOperations::DifferenceList (Handle(GEOM_Object) theGroup,
   SetErrorCode(KO);
   if (theGroup.IsNull()) return;
 
+  if ( theGroup->GetType() != GEOM_GROUP ) {
+    SetErrorCode( "Error: You could perform this operation only with group. Please select a group." );
+    return;
+  }
+
   Standard_Integer aLen = theSubShapes->Length();
   if (aLen < 1) {
     //SetErrorCode("The list is empty");
@@ -558,6 +590,11 @@ void GEOMImpl_IGroupOperations::UnionIDs (Handle(GEOM_Object) theGroup,
   SetErrorCode(KO);
   if (theGroup.IsNull()) return;
 
+  if ( theGroup->GetType() != GEOM_GROUP ) {
+    SetErrorCode( "Error: You could perform this operation only with group. Please select a group." );
+    return;
+  }
+
   Standard_Integer aLen = theSubShapes->Length();
   if (aLen < 1) {
     //SetErrorCode("The list is empty");
@@ -657,6 +694,11 @@ void GEOMImpl_IGroupOperations::DifferenceIDs (Handle(GEOM_Object) theGroup,
   SetErrorCode(KO);
   if (theGroup.IsNull()) return;
 
+  if ( theGroup->GetType() != GEOM_GROUP ) {
+    SetErrorCode( "Error: You could perform this operation only with group. Please select a group." );
+    return;
+  }
+
   Standard_Integer aLen = theSubShapes->Length();
   if (aLen < 1) {
     //SetErrorCode("The list is empty");
@@ -760,6 +802,11 @@ Handle(GEOM_Object) GEOMImpl_IGroupOperations::UnionGroups (Handle(GEOM_Object)
   SetErrorCode(KO);
   if (theGroup1.IsNull() || theGroup2.IsNull()) return NULL;
 
+  if ( theGroup1->GetType() != GEOM_GROUP || theGroup2->GetType() != GEOM_GROUP ) {
+    SetErrorCode( "Error: You could perform this operation only with group. Please select a group." );
+    return NULL;
+  }
+
   // Get group type
   TopAbs_ShapeEnum aType1 = GetType(theGroup1);
   TopAbs_ShapeEnum aType2 = GetType(theGroup2);
@@ -866,6 +913,11 @@ Handle(GEOM_Object) GEOMImpl_IGroupOperations::IntersectGroups (Handle(GEOM_Obje
   SetErrorCode(KO);
   if (theGroup1.IsNull() || theGroup2.IsNull()) return NULL;
 
+  if ( theGroup1->GetType() != GEOM_GROUP || theGroup2->GetType() != GEOM_GROUP ) {
+    SetErrorCode( "Error: You could perform this operation only with group. Please select a group." );
+    return NULL;
+  }
+
   // Get group type
   TopAbs_ShapeEnum aType1 = GetType(theGroup1);
   TopAbs_ShapeEnum aType2 = GetType(theGroup2);
@@ -972,6 +1024,11 @@ Handle(GEOM_Object) GEOMImpl_IGroupOperations::CutGroups (Handle(GEOM_Object) th
   SetErrorCode(KO);
   if (theGroup1.IsNull() || theGroup2.IsNull()) return NULL;
 
+  if ( theGroup1->GetType() != GEOM_GROUP || theGroup2->GetType() != GEOM_GROUP ) {
+    SetErrorCode( "Error: You could perform this operation only with group. Please select a group." );
+    return NULL;
+  }
+
   // Get group type
   TopAbs_ShapeEnum aType1 = GetType(theGroup1);
   TopAbs_ShapeEnum aType2 = GetType(theGroup2);
@@ -1084,7 +1141,7 @@ Handle(GEOM_Object) GEOMImpl_IGroupOperations::UnionListOfGroups
     return NULL;
   }
 
-  TopAbs_ShapeEnum aType, aType_i;
+  TopAbs_ShapeEnum aType = TopAbs_SHAPE, aType_i;   // todo: refactor: aType must be initialized to avoid warning (see below)
   TDF_Label aLabel, aLabel_i;
   TColStd_ListOfInteger aNewIDs;
   TColStd_MapOfInteger mapIDs;
@@ -1092,14 +1149,17 @@ Handle(GEOM_Object) GEOMImpl_IGroupOperations::UnionListOfGroups
   // Iterate on the initial groups
   for (i = 1; i <= aLen; i++) {
     Handle(GEOM_Object) aGr_i = Handle(GEOM_Object)::DownCast(theGList->Value(i));
-
+    if ( aGr_i->GetType() != GEOM_GROUP ) {
+      SetErrorCode( "Error: You could perform this operation only with group. Please select a group." );
+      return NULL;
+    }
     // Get group type
     aType_i = GetType(aGr_i);
     if (i == 1)
       aType = aType_i;
     else {
       if (aType_i != aType) {
-        if (aType != TopAbs_SHAPE && aType != TopAbs_COMPOUND) {
+        if (aType != TopAbs_SHAPE && aType != TopAbs_COMPOUND) { // todo: refactor: aType must be initialized to avoid warning (see above)
           if (aType_i == TopAbs_SHAPE || aType_i == TopAbs_COMPOUND)
             aType = aType_i;
           else {
@@ -1196,7 +1256,7 @@ Handle(GEOM_Object) GEOMImpl_IGroupOperations::IntersectListOfGroups
     return NULL;
   }
 
-  TopAbs_ShapeEnum aType, aType_i;
+  TopAbs_ShapeEnum aType = TopAbs_SHAPE, aType_i; // todo: refactor: aType must be initialized to avoid warning (see below)
   TDF_Label aLabel, aLabel_i;
   TColStd_ListOfInteger aNewIDs;
   TColStd_MapOfInteger mapIDs;
@@ -1204,14 +1264,17 @@ Handle(GEOM_Object) GEOMImpl_IGroupOperations::IntersectListOfGroups
   // Iterate on the initial groups
   for (i = 1; i <= aLen; i++) {
     Handle(GEOM_Object) aGr_i = Handle(GEOM_Object)::DownCast(theGList->Value(i));
-
+    if ( aGr_i->GetType() != GEOM_GROUP ) {
+      SetErrorCode( "Error: You could perform this operation only with group. Please select a group." );
+      return NULL;
+    }
     // Get group type
     aType_i = GetType(aGr_i);
     if (i == 1)
       aType = aType_i;
     else {
       if (aType_i != aType) {
-        if (aType != TopAbs_SHAPE && aType != TopAbs_COMPOUND) {
+        if (aType != TopAbs_SHAPE && aType != TopAbs_COMPOUND) { // todo: refactor: aType must be initialized to avoid warning (see above)
           if (aType_i == TopAbs_SHAPE || aType_i == TopAbs_COMPOUND)
             aType = aType_i;
           else {
@@ -1334,7 +1397,7 @@ Handle(GEOM_Object) GEOMImpl_IGroupOperations::CutListOfGroups
     return NULL;
   }
 
-  TopAbs_ShapeEnum aType, aType_i;
+  TopAbs_ShapeEnum aType = TopAbs_SHAPE, aType_i; // todo: refactor: aType must be initialized to avoid warning (see below)
   TDF_Label aLabel, aLabel_i;
   TColStd_ListOfInteger aNewIDs;
   TColStd_MapOfInteger mapIDs;
@@ -1342,7 +1405,10 @@ Handle(GEOM_Object) GEOMImpl_IGroupOperations::CutListOfGroups
   // 1. Collect indices to be excluded (from theGList2) into the mapIDs
   for (i = 1; i <= aLen2; i++) {
     Handle(GEOM_Object) aGr_i = Handle(GEOM_Object)::DownCast(theGList2->Value(i));
-
+    if ( aGr_i->GetType() != GEOM_GROUP ) {
+      SetErrorCode( "Error: You could perform this operation only with group. Please select a group." );
+      return NULL;
+    }
     // Get group type
     aType_i = GetType(aGr_i);
     if (i == 1)
@@ -1393,14 +1459,17 @@ Handle(GEOM_Object) GEOMImpl_IGroupOperations::CutListOfGroups
   // 2. Collect indices from theGList1, avoiding indices from theGList2 (mapIDs)
   for (i = 1; i <= aLen1; i++) {
     Handle(GEOM_Object) aGr_i = Handle(GEOM_Object)::DownCast(theGList1->Value(i));
-
+    if ( aGr_i->GetType() != GEOM_GROUP ) {
+      SetErrorCode( "Error: You could perform this operation only with group. Please select a group." );
+      return NULL;
+    }
     // Get group type
     aType_i = GetType(aGr_i);
     if (i == 1 && aLen2 < 1)
       aType = aType_i;
     else {
       if (aType_i != aType) {
-        if (aType != TopAbs_SHAPE && aType != TopAbs_COMPOUND) {
+        if (aType != TopAbs_SHAPE && aType != TopAbs_COMPOUND) { // todo: refactor: aType must be initialized to avoid warning (see above)
           if (aType_i == TopAbs_SHAPE || aType_i == TopAbs_COMPOUND)
             aType = aType_i;
           else {
@@ -1512,7 +1581,12 @@ Handle(GEOM_Object) GEOMImpl_IGroupOperations::GetMainShape (Handle(GEOM_Object)
 {
   SetErrorCode(KO);
 
-  if(theGroup.IsNull()) return NULL;
+  if (theGroup.IsNull()) return NULL;
+  if (theGroup->GetType() != GEOM_GROUP &&
+      theGroup->GetType() != GEOM_SUBSHAPE) {
+    SetErrorCode("Error: You could perform this operation only with a group or a sub-shape.");
+    return NULL;
+  }
 
   Handle(GEOM_Function) aGroupFunction = theGroup->GetFunction(1);
   if (aGroupFunction.IsNull()) return NULL;
@@ -1543,7 +1617,10 @@ Handle(TColStd_HArray1OfInteger) GEOMImpl_IGroupOperations::GetObjects(Handle(GE
   SetErrorCode(KO);
 
   if(theGroup.IsNull()) return NULL;
-
+  if ( theGroup->GetType() != GEOM_GROUP ) {
+    SetErrorCode( "Error: You could perform this operation only with group. Please select a group." );
+    return NULL;
+  }
   Handle(GEOM_Function) aFunction = theGroup->GetLastFunction();
   if(aFunction.IsNull()) return NULL;