]> SALOME platform Git repositories - modules/geom.git/blobdiff - src/GEOMImpl/GEOMImpl_IGroupOperations.cxx
Salome HOME
Fix error in creation information - wrong operation type in case of MakeEdge
[modules/geom.git] / src / GEOMImpl / GEOMImpl_IGroupOperations.cxx
index dc47e1f0e5e0581cc7803a5ff45175fbeb2f23e6..e603adc90ad2a5fbf72d70075ffa1f0d93e401f6 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2014  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>
 
@@ -80,6 +81,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 +120,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 +141,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 +203,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 +287,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 +442,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 +592,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 +696,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 +804,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 +915,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 +1026,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);
@@ -1092,7 +1151,10 @@ 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)
@@ -1204,7 +1266,10 @@ 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)
@@ -1342,7 +1407,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,7 +1461,10 @@ 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)
@@ -1512,7 +1583,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 +1619,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;