X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGEOMImpl%2FGEOMImpl_IGroupOperations.cxx;h=09658a18b6b24f4c338c9a92db93c211dcdc79e1;hb=af9f05e2cf3b94e80eb4161a611d6c9e4e47283a;hp=353ac3530a1036dd16832a27e8167763ca8dcf6b;hpb=438f4b0922bde24be526d18c3cee98bdaea52642;p=modules%2Fgeom.git diff --git a/src/GEOMImpl/GEOMImpl_IGroupOperations.cxx b/src/GEOMImpl/GEOMImpl_IGroupOperations.cxx index 353ac3530..09658a18b 100644 --- a/src/GEOMImpl/GEOMImpl_IGroupOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IGroupOperations.cxx @@ -1,22 +1,24 @@ -// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// 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. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. +// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // -// See http://www.salome-platform.org/ +// 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. // +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// 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 #include @@ -38,6 +40,7 @@ #include #include +#include #include #include @@ -45,14 +48,12 @@ #include #include -#include // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC - //============================================================================= /*! * constructor: */ //============================================================================= -GEOMImpl_IGroupOperations::GEOMImpl_IGroupOperations (GEOM_Engine* theEngine, int theDocID) +GEOMImpl_IGroupOperations::GEOMImpl_IGroupOperations (GEOM_Engine* theEngine, int theDocID) : GEOM_IOperations(theEngine, theDocID) { MESSAGE("GEOMImpl_IGroupOperations::GEOMImpl_IGroupOperations"); @@ -82,7 +83,7 @@ Handle(GEOM_Object) GEOMImpl_IGroupOperations::CreateGroup Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1,1); anArray->SetValue(1, -1); - //Add a new Fillet object + //Add a new Sub-shape object Handle(GEOM_Object) aGroup = GetEngine()->AddSubShape(theMainShape, anArray); //Set a GROUP type @@ -120,9 +121,9 @@ void GEOMImpl_IGroupOperations::AddObject(Handle(GEOM_Object) theGroup, int theS // Check sub-shape index validity TDF_Label aLabel = aSSI.GetMainShape()->GetOwnerEntry(); if (aLabel.IsRoot()) return; - Handle(GEOM_Object) anObj = GEOM_Object::GetObject(aLabel); - if (anObj.IsNull()) return; - TopoDS_Shape aMainShape = anObj->GetValue(); + Handle(GEOM_Object) aMainObj = GEOM_Object::GetObject(aLabel); + if (aMainObj.IsNull()) return; + TopoDS_Shape aMainShape = aMainObj->GetValue(); if (aMainShape.IsNull()) return; TopTools_IndexedMapOfShape aMapOfShapes; @@ -145,14 +146,18 @@ void GEOMImpl_IGroupOperations::AddObject(Handle(GEOM_Object) theGroup, int theS for(Standard_Integer i = 1; i<=aLength; i++) { aNewSeq->SetValue(i, aSeq->Value(i)); if(aSeq->Value(i) == theSubShapeID) { - SetErrorCode(ALREADY_PRESENT); - return; // + SetErrorCode(ALREADY_PRESENT); + return; // } } aNewSeq->SetValue(aLength+1, theSubShapeID); aSSI.SetIndices(aNewSeq); } + // As we do not recompute here our group, lets mark it as Modified + Standard_Integer aTic = aMainObj->GetTic(); // tic of main shape + theGroup->SetTic(aTic - 1); + //Make a Python command GEOM::TPythonDump(aFunction, /*append=*/true) << "geompy.AddObject(" << theGroup << ", " << theSubShapeID << ")"; @@ -177,52 +182,58 @@ void GEOMImpl_IGroupOperations::RemoveObject (Handle(GEOM_Object) theGroup, int GEOM_ISubShape aSSI(aFunction); Handle(TColStd_HArray1OfInteger) aSeq = aSSI.GetIndices(); if(aSeq.IsNull()) return; + if(aSeq->Length() == 1 && aSeq->Value(1) == -1) { SetErrorCode(NOT_EXISTS); return; } + + Handle(TColStd_HArray1OfInteger) aNewSeq; + Standard_Integer aLength = aSeq->Length(); + if(aLength == 1) { + if(aSeq->Value(1) != theSubShapeID) { + SetErrorCode(NOT_EXISTS); + return; + } + aNewSeq = new TColStd_HArray1OfInteger(1,1); + aNewSeq->SetValue(1, -1); + } else { - Handle(TColStd_HArray1OfInteger) aNewSeq; - Standard_Integer aLength = aSeq->Length(); - if(aLength == 1) { - if(aSeq->Value(1) != theSubShapeID) { - SetErrorCode(NOT_EXISTS); - return; + aNewSeq = new TColStd_HArray1OfInteger(1, aLength-1); + Standard_Boolean isFound = Standard_False; + for (Standard_Integer i = 1, k = 1; i <= aLength; i++) { + if (aSeq->Value(i) == theSubShapeID) { + isFound = Standard_True; + } else { + if (k < aLength) { // this check is to avoid sequence overflow + aNewSeq->SetValue(k, aSeq->Value(i)); + k++; + } } - aNewSeq = new TColStd_HArray1OfInteger(1,1); - aNewSeq->SetValue(1, -1); } - else { - aNewSeq = new TColStd_HArray1OfInteger(1, aLength-1); - Standard_Boolean isFound = Standard_False; - for(Standard_Integer i = 1, k=1; i<=aLength; i++) { - if(i == aLength && !isFound) { - SetErrorCode(NOT_EXISTS); - return; - } - if(aSeq->Value(i) == theSubShapeID) { - isFound = Standard_True; - continue; - } - aNewSeq->SetValue(k, aSeq->Value(i)); - k++; - } - if(!isFound) { - SetErrorCode(NOT_EXISTS); - return; - } + if (!isFound) { + SetErrorCode(NOT_EXISTS); + return; } - - aSSI.SetIndices(aNewSeq); } - //Make a Python command + aSSI.SetIndices(aNewSeq); + + // As we do not recompute here our group, lets mark it as Modified + TDF_Label aLabel = aSSI.GetMainShape()->GetOwnerEntry(); + if (aLabel.IsRoot()) return; + Handle(GEOM_Object) aMainObj = GEOM_Object::GetObject(aLabel); + if (aMainObj.IsNull()) return; + Standard_Integer aTic = aMainObj->GetTic(); // tic of main shape + theGroup->SetTic(aTic - 1); + + //Make a Python command GEOM::TPythonDump(aFunction, /*append=*/true) << "geompy.RemoveObject(" << theGroup << ", " << theSubShapeID << ")"; SetErrorCode(OK); - return; + return; } //============================================================================= @@ -238,7 +249,8 @@ void GEOMImpl_IGroupOperations::UnionList (Handle(GEOM_Object) theGroup, Standard_Integer aLen = theSubShapes->Length(); if (aLen < 1) { - SetErrorCode("The list is empty"); + //SetErrorCode("The list is empty"); + SetErrorCode(OK); return; } @@ -276,80 +288,68 @@ void GEOMImpl_IGroupOperations::UnionList (Handle(GEOM_Object) theGroup, TopTools_IndexedMapOfShape mapIndices; TopExp::MapShapes(aMainShape, mapIndices); + // Get group type + TopAbs_ShapeEnum aType = GetType(theGroup); + // Get IDs of sub-shapes to add Standard_Integer i, new_id; for (i = 1; i <= aLen; i++) { Handle(GEOM_Object) anObj_i = Handle(GEOM_Object)::DownCast(theSubShapes->Value(i)); + TopoDS_Shape aShape_i = anObj_i->GetValue(); + TopAbs_ShapeEnum aType_i = aShape_i.ShapeType(); + + // 1. If aShape_i is sub-shape of aMainShape - add it if (anObj_i->IsMainShape()) { - TopoDS_Shape aShape_i = anObj_i->GetValue(); - if (mapIndices.Contains(aShape_i)) { - new_id = mapIndices.FindIndex(aShape_i); - if (mapIDs.Add(new_id)) { - aNewIDs.Append(new_id); - } - } else { - SetErrorCode("One of given objects can not be added to the group, because it is not a sub-shape of the group's main shape"); + if (aType_i != aType && aType != TopAbs_SHAPE && aType != TopAbs_COMPOUND) { + SetErrorCode("Operation aborted: one of given objects has a wrong type"); return; } - } else { - // Check main shape of sub-shape to add - Handle(GEOM_Function) aFunc_i = anObj_i->GetFunction(1); - if (aFunc_i.IsNull()) return; - - GEOM_ISubShape aSSI_i (aFunc_i); - - Handle(GEOM_Function) aMainShapeFunc_i = aSSI_i.GetMainShape(); - if (aMainShapeFunc_i.IsNull()) return; - TDF_Label aLabel_i = aMainShapeFunc_i->GetOwnerEntry(); - if (aLabel_i.IsRoot()) return; - Handle(GEOM_Object) aMainObj_i = GEOM_Object::GetObject(aLabel); - if (aMainObj_i.IsNull()) return; - TopoDS_Shape aMainShape_i = aMainObj_i->GetValue(); - if (aMainShape_i.IsNull()) return; - - if (aMainShape_i.IsSame(aMainShape)) { - // add all sub-shape IDs to the list - - // Get IDs - Handle(TColStd_HArray1OfInteger) aSeq_i = aSSI_i.GetIndices(); - if (aSeq_i.IsNull()) return; - Standard_Integer aLength_i = aSeq_i->Length(); - - for (Standard_Integer i_j = 1; i_j <= aLength_i; i_j++) { - new_id = aSeq_i->Value(i_j); - if (new_id > 0) { - if (mapIDs.Add(new_id)) { - aNewIDs.Append(new_id); - } - } - } - - } else if (mapIndices.Contains(aMainShape_i)) { - // compute new IDs and add them to the list - TopTools_IndexedMapOfShape mapIndices_i; - TopExp::MapShapes(aMainShape_i, mapIndices_i); - - // Get IDs - Handle(TColStd_HArray1OfInteger) aSeq_i = aSSI_i.GetIndices(); - if (aSeq_i.IsNull()) return; - Standard_Integer aLength_i = aSeq_i->Length(); - - for (Standard_Integer i_j = 1; i_j <= aLength_i; i_j++) { - if (aSeq_i->Value(i_j) > 0) { - TopoDS_Shape aShape_i_j = mapIndices_i.FindKey(i_j); - new_id = mapIndices.FindIndex(aShape_i_j); - if (mapIDs.Add(new_id)) { - aNewIDs.Append(new_id); - } + if (!mapIndices.Contains(aShape_i)) { + SetErrorCode("Operation aborted: not a sub-shape given"); + return; + } + new_id = mapIndices.FindIndex(aShape_i); + if (mapIDs.Add(new_id)) { + aNewIDs.Append(new_id); + } + } + // 2. If type of group is not defined - add all sub-shapes of aShape_i + else if (aType == TopAbs_SHAPE || aType == TopAbs_COMPOUND) { + TopTools_IndexedMapOfShape mapIndices_i; + TopExp::MapShapes(aShape_i, mapIndices_i); + Standard_Integer ii = 1, nbSubSh = mapIndices_i.Extent(); + Standard_Boolean someGood = Standard_False; + for (; ii <= nbSubSh; ii++) { + TopoDS_Shape aSubShape_i = mapIndices_i.FindKey(ii); + if (mapIndices.Contains(aSubShape_i)) { + someGood = Standard_True; + new_id = mapIndices.FindIndex(aSubShape_i); + if (mapIDs.Add(new_id)) { + aNewIDs.Append(new_id); } } - - } else { - SetErrorCode("One of given objects can not be added to the group, because it is not a sub-shape of the group's main shape"); + } + if (!someGood) { + SetErrorCode("Operation aborted: not a sub-shape given"); return; } } + // 3. If type of group is defined - add all sub-shapes of aShape_i of that type + else { + TopExp_Explorer aSubShapes_i (aShape_i, aType); + for (; aSubShapes_i.More(); aSubShapes_i.Next()) { + TopoDS_Shape aSubShape_i = aSubShapes_i.Current(); + if (!mapIndices.Contains(aSubShape_i)) { + SetErrorCode("Operation aborted: not a sub-shape given"); + return; + } + new_id = mapIndices.FindIndex(aSubShape_i); + if (mapIDs.Add(new_id)) { + aNewIDs.Append(new_id); + } + } + } } if (aNewIDs.Extent() > 0) { @@ -361,6 +361,10 @@ void GEOMImpl_IGroupOperations::UnionList (Handle(GEOM_Object) theGroup, } aSSI.SetIndices(aNewSeq); + + // As we do not recompute here our group, lets mark it as Modified + Standard_Integer aTic = aMainObj->GetTic(); // tic of main shape + theGroup->SetTic(aTic - 1); } //Make a Python command @@ -431,78 +435,50 @@ void GEOMImpl_IGroupOperations::DifferenceList (Handle(GEOM_Object) theGroup, TopTools_IndexedMapOfShape mapIndices; TopExp::MapShapes(aMainShape, mapIndices); + // Get group type + TopAbs_ShapeEnum aType = GetType(theGroup); + // Get IDs of sub-shapes to be removed Standard_Integer i, rem_id; for (i = 1; i <= aLen; i++) { Handle(GEOM_Object) anObj_i = Handle(GEOM_Object)::DownCast(theSubShapes->Value(i)); - if (anObj_i->IsMainShape()) { - TopoDS_Shape aShape_i = anObj_i->GetValue(); - if (mapIndices.Contains(aShape_i)) { - rem_id = mapIndices.FindIndex(aShape_i); - if (mapIDsCurrent.Contains(rem_id)) { - mapIDsToRemove.Add(rem_id); - } - } else { - SetErrorCode("One of given objects can not be removed from the group, because it is not a sub-shape of the group's main shape"); - return; + TopoDS_Shape aShape_i = anObj_i->GetValue(); + + // 1. If aShape_i is sub-shape of aMainShape - remove it + if (mapIndices.Contains(aShape_i)) { + rem_id = mapIndices.FindIndex(aShape_i); + if (mapIDsCurrent.Contains(rem_id)) { + mapIDsToRemove.Add(rem_id); } - } else { - // Check main shape of sub-shape to be removed - Handle(GEOM_Function) aFunc_i = anObj_i->GetFunction(1); - if (aFunc_i.IsNull()) return; - - GEOM_ISubShape aSSI_i (aFunc_i); - - Handle(GEOM_Function) aMainShapeFunc_i = aSSI_i.GetMainShape(); - if (aMainShapeFunc_i.IsNull()) return; - TDF_Label aLabel_i = aMainShapeFunc_i->GetOwnerEntry(); - if (aLabel_i.IsRoot()) return; - Handle(GEOM_Object) aMainObj_i = GEOM_Object::GetObject(aLabel); - if (aMainObj_i.IsNull()) return; - TopoDS_Shape aMainShape_i = aMainObj_i->GetValue(); - if (aMainShape_i.IsNull()) return; - - if (aMainShape_i.IsSame(aMainShape)) { - // remove all sub-shapes - - // Get IDs - Handle(TColStd_HArray1OfInteger) aSeq_i = aSSI_i.GetIndices(); - if (aSeq_i.IsNull()) return; - Standard_Integer aLength_i = aSeq_i->Length(); - - for (Standard_Integer i_j = 1; i_j <= aLength_i; i_j++) { - rem_id = aSeq_i->Value(i_j); - if (rem_id > 0) { - if (mapIDsCurrent.Contains(rem_id)) { - mapIDsToRemove.Add(rem_id); - } + } + // 2. If type of group is not defined - remove all sub-shapes of aShape_i + else if (aType == TopAbs_SHAPE || aType == TopAbs_COMPOUND) { + TopTools_IndexedMapOfShape mapIndices_i; + TopExp::MapShapes(aShape_i, mapIndices_i); + Standard_Integer nbSubSh = mapIndices_i.Extent(); + Standard_Integer ii = 1; + for (; ii <= nbSubSh; ii++) { + TopoDS_Shape aSubShape_i = mapIndices_i.FindKey(ii); + if (mapIndices.Contains(aSubShape_i)) { + rem_id = mapIndices.FindIndex(aSubShape_i); + if (mapIDsCurrent.Contains(rem_id)) { + mapIDsToRemove.Add(rem_id); } } - - } else if (mapIndices.Contains(aMainShape_i)) { - // compute new IDs and add them to the map of ids to be removed - TopTools_IndexedMapOfShape mapIndices_i; - TopExp::MapShapes(aMainShape_i, mapIndices_i); - - // Get IDs - Handle(TColStd_HArray1OfInteger) aSeq_i = aSSI_i.GetIndices(); - if (aSeq_i.IsNull()) return; - Standard_Integer aLength_i = aSeq_i->Length(); - - for (Standard_Integer i_j = 1; i_j <= aLength_i; i_j++) { - if (aSeq_i->Value(i_j) > 0) { - TopoDS_Shape aShape_i_j = mapIndices_i.FindKey(i_j); - rem_id = mapIndices.FindIndex(aShape_i_j); - if (mapIDsCurrent.Contains(rem_id)) { - mapIDsToRemove.Add(rem_id); - } + } + } + // 3. If type of group is defined - remove all sub-shapes of aShape_i of that type + else { + TopExp_Explorer aSubShapes_i (aShape_i, aType); + for (; aSubShapes_i.More(); aSubShapes_i.Next()) { + TopoDS_Shape aSubShape_i = aSubShapes_i.Current(); + if (mapIndices.Contains(aSubShape_i)) { + rem_id = mapIndices.FindIndex(aSubShape_i); + if (mapIDsCurrent.Contains(rem_id)) { + mapIDsToRemove.Add(rem_id); } } - - } else { - SetErrorCode("One of given objects can not be removed from the group, because it is not a sub-shape of the group's main shape"); - return; } } } @@ -519,6 +495,10 @@ void GEOMImpl_IGroupOperations::DifferenceList (Handle(GEOM_Object) theGroup, } aSSI.SetIndices(aNewSeq); + + // As we do not recompute here our group, lets mark it as Modified + Standard_Integer aTic = aMainObj->GetTic(); // tic of main shape + theGroup->SetTic(aTic - 1); } //Make a Python command @@ -588,13 +568,17 @@ void GEOMImpl_IGroupOperations::UnionIDs (Handle(GEOM_Object) theGroup, TopTools_IndexedMapOfShape mapIndices; TopExp::MapShapes(aMainShape, mapIndices); + // Get group type + TopAbs_ShapeEnum aType = GetType(theGroup); + // Get IDs of sub-shapes to add Standard_Integer i, new_id; for (i = 1; i <= aLen; i++) { new_id = theSubShapes->Value(i); if (0 < new_id && new_id <= mapIndices.Extent()) { - if (mapIDs.Add(new_id)) { + //if (mapIDs.Add(new_id)) { IPAL21297. Why we ignore invalid ids silently? + if (mapIDs.Add(new_id) && mapIndices(new_id).ShapeType()==aType ) { aNewIDs.Append(new_id); } } @@ -609,6 +593,10 @@ void GEOMImpl_IGroupOperations::UnionIDs (Handle(GEOM_Object) theGroup, } aSSI.SetIndices(aNewSeq); + + // As we do not recompute here our group, lets mark it as Modified + Standard_Integer aTic = aMainObj->GetTic(); // tic of main shape + theGroup->SetTic(aTic - 1); } //Make a Python command @@ -694,6 +682,10 @@ void GEOMImpl_IGroupOperations::DifferenceIDs (Handle(GEOM_Object) theGroup, } aSSI.SetIndices(aNewSeq); + + // As we do not recompute here our group, lets mark it as Modified + Standard_Integer aTic = aMainObj->GetTic(); // tic of main shape + theGroup->SetTic(aTic - 1); } //Make a Python command @@ -718,9 +710,9 @@ TopAbs_ShapeEnum GEOMImpl_IGroupOperations::GetType(Handle(GEOM_Object) theGroup TDF_Label aFreeLabel = theGroup->GetFreeLabel(); Handle(TDataStd_Integer) anAttrib; if(!aFreeLabel.FindAttribute(TDataStd_Integer::GetID(), anAttrib)) return TopAbs_SHAPE; - + SetErrorCode(OK); - return (TopAbs_ShapeEnum) anAttrib->Get(); + return (TopAbs_ShapeEnum) anAttrib->Get(); } //============================================================================= @@ -746,11 +738,11 @@ Handle(GEOM_Object) GEOMImpl_IGroupOperations::GetMainShape (Handle(GEOM_Object) if (aMainShape.IsNull()) return NULL; //Make a Python command - GEOM::TPythonDump(aGroupFunction, /*append=*/true) - << aMainShape << " = geompy.GetMainShape(" << theGroup << ")"; + //GEOM::TPythonDump(aGroupFunction, /*append=*/true) + // << aMainShape << " = geompy.GetMainShape(" << theGroup << ")"; SetErrorCode(OK); - return aMainShape; + return aMainShape; } //=============================================================================