From: skv Date: Fri, 13 Nov 2015 12:43:38 +0000 (+0300) Subject: 0023197: [CEA] Extract and rebuild: engine (ecxept algorithm) X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=553dce807d65aa7f7a5833f0ad012d884e098aa0;p=modules%2Fgeom.git 0023197: [CEA] Extract and rebuild: engine (ecxept algorithm) --- diff --git a/src/GEOMAlgo/CMakeLists.txt b/src/GEOMAlgo/CMakeLists.txt index d2b6024ab..38126e94b 100755 --- a/src/GEOMAlgo/CMakeLists.txt +++ b/src/GEOMAlgo/CMakeLists.txt @@ -59,6 +59,7 @@ SET(GEOMAlgo_HEADERS GEOMAlgo_DataMapOfPassKeyInteger.hxx GEOMAlgo_DataMapOfShapeMapOfShape.hxx GEOMAlgo_DataMapOfShapePnt.hxx + GEOMAlgo_Extractor.hxx GEOMAlgo_FinderShapeOn.hxx GEOMAlgo_FinderShapeOn1.hxx GEOMAlgo_FinderShapeOn2.hxx @@ -123,6 +124,7 @@ SET(GEOMAlgo_SOURCES GEOMAlgo_ClsfSurf.cxx GEOMAlgo_CoupleOfShapes.cxx GEOMAlgo_FinderShapeOn2.cxx + GEOMAlgo_Extractor.cxx GEOMAlgo_GetInPlace.cxx GEOMAlgo_GetInPlace_1.cxx GEOMAlgo_GetInPlace_2.cxx diff --git a/src/GEOMAlgo/GEOMAlgo_Extractor.cxx b/src/GEOMAlgo/GEOMAlgo_Extractor.cxx new file mode 100644 index 000000000..34d92d0ab --- /dev/null +++ b/src/GEOMAlgo/GEOMAlgo_Extractor.cxx @@ -0,0 +1,159 @@ +// Copyright (C) 2007-2015 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 +// +// 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, 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 +// 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 +// + +// File: GEOMAlgo_Extractor.cxx +// Created: +// Author: Sergey KHROMOV +// + + +#include + +#include +#include +#include + + +//======================================================================= +//function : GEOMAlgo_Extractor +//purpose : +//======================================================================= +GEOMAlgo_Extractor::GEOMAlgo_Extractor() +{ +} + +//======================================================================= +//function : ~GEOMAlgo_Extractor +//purpose : +//======================================================================= +GEOMAlgo_Extractor::~GEOMAlgo_Extractor() +{ +} + +//======================================================================= +//function : SetShape +//purpose : +//======================================================================= +void GEOMAlgo_Extractor::SetShape(const TopoDS_Shape &theShape) +{ + myShape = theShape; + clear(); +} + +//======================================================================= +//function : SetShapesToRemove +//purpose : +//======================================================================= +void GEOMAlgo_Extractor::SetShapesToRemove + (const TopTools_ListOfShape &theSubShapes) +{ + mySubShapes.Assign(theSubShapes); + clear(); +} + +//======================================================================= +//function : Perform +//purpose : +//======================================================================= +void GEOMAlgo_Extractor::Perform() +{ + clear(); + myErrorStatus = 0; + // + checkData(); + + if(myErrorStatus) { + return; + } + + if (myWarningStatus == 10) { + // The result is the same shape. Nothing is modified. + myResult = myShape; + return; + } +} + +//======================================================================= +//function : GetResult +//purpose : +//======================================================================= +const TopoDS_Shape &GEOMAlgo_Extractor::GetResult() const +{ + return myResult; +} + +//======================================================================= +//function : clear +//purpose : +//======================================================================= +void GEOMAlgo_Extractor::clear() +{ + myErrorStatus = 1; + myWarningStatus = 0; + myResult.Nullify(); + myRemoved.Clear(); + myModified.Clear(); + myNew.Clear(); +} + +//======================================================================= +//function : checkData +//purpose : +//======================================================================= +void GEOMAlgo_Extractor::checkData() +{ + if (myShape.IsNull()) { + myErrorStatus = 10; + return; + } + + if (mySubShapes.IsEmpty()) { + myWarningStatus = 10; + return; + } + + TopTools_ListIteratorOfListOfShape anIter(mySubShapes); + TopTools_IndexedMapOfShape anIndices; + + TopExp::MapShapes(myShape, anIndices); + + for (; anIter.More(); anIter.Next()) { + const TopoDS_Shape &aSubShape = anIter.Value(); + + if (!anIndices.Contains(aSubShape)) { + myErrorStatus = 11; + return; + } + } +} + + +// +// myErrorStatus : +// +// 10 -myShape=NULL +// 11 -mySubShapes contains not only sub-shapes of myShape. +// +// myWarningStatus : +// +// 10 -mySubShapes is empty +// diff --git a/src/GEOMAlgo/GEOMAlgo_Extractor.hxx b/src/GEOMAlgo/GEOMAlgo_Extractor.hxx new file mode 100644 index 000000000..2b9696ad1 --- /dev/null +++ b/src/GEOMAlgo/GEOMAlgo_Extractor.hxx @@ -0,0 +1,147 @@ +// Copyright (C) 2007-2015 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 +// +// 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, 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 +// 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 +// + +// File: GEOMAlgo_Extractor.hxx +// Author: Sergey KHROMOV + +#ifndef _GEOMAlgo_Extractor_HeaderFile +#define _GEOMAlgo_Extractor_HeaderFile + + +#include + +#include +#include + + +/** + * \brief This class encapsulates an algorithm of extraction of sub-shapes + * from the main shape. + */ +class GEOMAlgo_Extractor : public GEOMAlgo_Algo +{ +public: + + /** + * \brief Empty constructor. + */ + Standard_EXPORT GEOMAlgo_Extractor(); + + /** + * \brief Virtual destructor. + */ + Standard_EXPORT virtual ~GEOMAlgo_Extractor(); + + /** + * \brief This method sets the main shape. + * + * \param theShape the main shape. + */ + Standard_EXPORT void SetShape(const TopoDS_Shape &theShape); + + /** + * \brief This method returns the main shape. + * + * \return the main shape. + */ + const TopoDS_Shape &GetShape() const + { return myShape; } + + /** + * \brief This method sets the list of sub-shapes to be removed + * from the main shape. + * + * \param theSubShapes the sub-shapes to be removed. + */ + Standard_EXPORT void SetShapesToRemove + (const TopTools_ListOfShape &theSubShapes); + + /** + * \brief This method returns the list of sub-shapes to be removed + * from the main shape. + * + * \return the list of sub-shapes to be removed. + */ + const TopTools_ListOfShape &GetShapesToRemove() const + { return mySubShapes; } + + /** + * This method performs computation of the extracted shape. + */ + Standard_EXPORT virtual void Perform(); + + /** + * This method returns the result of the algorithm. + * + * \return the result of the operation. + */ + Standard_EXPORT const TopoDS_Shape &GetResult() const; + + /** + * \brief This method returns the sub-shapes removed from the main shape. + * + * \return the list of removed sub-shapes. + */ + const TopTools_ListOfShape &GetRemoved() const + { return myRemoved; } + + /** + * \brief This method returns the sub-shapes modified in the main shape. + * + * \return the list of modified sub-shapes. + */ + const TopTools_ListOfShape &GetModified() const + { return myModified; } + + /** + * \brief This method returns the newly created sub-shapes in the result + * shape. + * + * \return the list of new sub-shapes in result. + */ + const TopTools_ListOfShape &GetNew() const + { return myNew; } + +private: + + /** + * This method reinitializes the shape. + */ + void clear(); + + /** + * This method checks the input data. + */ + void checkData(); + +protected: + + TopoDS_Shape myShape; + TopoDS_Shape myResult; + TopTools_ListOfShape mySubShapes; + TopTools_ListOfShape myRemoved; + TopTools_ListOfShape myModified; + TopTools_ListOfShape myNew; + +}; + +#endif diff --git a/src/GEOMImpl/CMakeLists.txt b/src/GEOMImpl/CMakeLists.txt index 5c59b2e72..9bdce7d48 100755 --- a/src/GEOMImpl/CMakeLists.txt +++ b/src/GEOMImpl/CMakeLists.txt @@ -79,6 +79,7 @@ SET(GEOMImpl_HEADERS GEOMImpl_ICircle.hxx GEOMImpl_ISpline.hxx GEOMImpl_IEllipse.hxx + GEOMImpl_IExtract.hxx GEOMImpl_IFillet.hxx GEOMImpl_IFillet1d.hxx GEOMImpl_IFillet2d.hxx diff --git a/src/GEOMImpl/GEOMImpl_IExtract.hxx b/src/GEOMImpl/GEOMImpl_IExtract.hxx new file mode 100644 index 000000000..35a2799e4 --- /dev/null +++ b/src/GEOMImpl/GEOMImpl_IExtract.hxx @@ -0,0 +1,73 @@ +// Copyright (C) 2007-2015 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 +// +// 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, 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 +// 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 +// + +//NOTE: This is an intreface to a function for the Offset creation. +// +#include "GEOM_Function.hxx" +#include + +#define EXTRACT_SHAPE 1 +#define EXTRACT_IDS 2 +#define EXTRACT_REMOVED_IDS 3 +#define EXTRACT_MODIFIED_IDS 4 +#define EXTRACT_ADDED_IDS 5 + +class GEOMImpl_IExtract +{ + public: + + GEOMImpl_IExtract(Handle(GEOM_Function) theFunction): _func(theFunction) {} + + void SetShape(Handle(GEOM_Function) theShape) + { _func->SetReference(EXTRACT_SHAPE, theShape); } + + Handle(GEOM_Function) GetShape() + { return _func->GetReference(EXTRACT_SHAPE); } + + void SetSubShapeIDs(const Handle(TColStd_HArray1OfInteger)& theSubShapeIDs) + { _func->SetIntegerArray(EXTRACT_IDS, theSubShapeIDs); } + + Handle(TColStd_HArray1OfInteger) GetSubShapeIDs() + { return _func->GetIntegerArray(EXTRACT_IDS); } + + void SetRemovedIDs(const Handle(TColStd_HArray1OfInteger)& theRemovedIDs) + { _func->SetIntegerArray(EXTRACT_REMOVED_IDS, theRemovedIDs); } + + Handle(TColStd_HArray1OfInteger) GetRemovedIDs() + { return _func->GetIntegerArray(EXTRACT_REMOVED_IDS); } + + void SetModifiedIDs(const Handle(TColStd_HArray1OfInteger)& theModifiedIDs) + { _func->SetIntegerArray(EXTRACT_MODIFIED_IDS, theModifiedIDs); } + + Handle(TColStd_HArray1OfInteger) GetModifiedIDs() + { return _func->GetIntegerArray(EXTRACT_MODIFIED_IDS); } + + void SetAddedIDs(const Handle(TColStd_HArray1OfInteger)& theAddedIDs) + { _func->SetIntegerArray(EXTRACT_ADDED_IDS, theAddedIDs); } + + Handle(TColStd_HArray1OfInteger) GetAddedIDs() + { return _func->GetIntegerArray(EXTRACT_ADDED_IDS); } + + private: + + Handle(GEOM_Function) _func; +}; diff --git a/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx b/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx index 11bd57a44..cfb8a9742 100644 --- a/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx @@ -36,6 +36,7 @@ #include "GEOMImpl_GlueDriver.hxx" #include "GEOMImpl_FillingDriver.hxx" +#include "GEOMImpl_IExtract.hxx" #include "GEOMImpl_IVector.hxx" #include "GEOMImpl_IShapes.hxx" #include "GEOMImpl_IShapeExtend.hxx" @@ -3172,11 +3173,95 @@ Handle(GEOM_Object) GEOMImpl_IShapesOperations::MakeExtraction const Handle(TColStd_HArray1OfInteger) &theSubShapeIDs, std::list &theStats) { + SetErrorCode(KO); + + if (theShape.IsNull()) { + return NULL; + } + + //Add a new Result object + Handle(GEOM_Object) aResult = + GetEngine()->AddObject(GetDocID(), GEOM_EXTRACTION); + + //Add a new Extraction function + Handle(GEOM_Function) aFunction = + aResult->AddFunction(GEOMImpl_ShapeDriver::GetID(), EXTRACTION); + + //Check if the function is set correctly + if (aFunction->GetDriverGUID() != GEOMImpl_ShapeDriver::GetID()) { + return NULL; + } + + Handle(GEOM_Function) aShape = theShape->GetLastFunction(); + + if (aShape.IsNull()) { + return NULL; + } + + GEOMImpl_IExtract aCI (aFunction); + + aCI.SetShape(aShape); + aCI.SetSubShapeIDs(theSubShapeIDs); + + //Compute the Edge value + try { + OCC_CATCH_SIGNALS; + if (!GetSolver()->ComputeFunction(aFunction)) { + SetErrorCode("Shape driver failed"); + + return NULL; + } + } + catch (Standard_Failure) { + Handle(Standard_Failure) aFail = Standard_Failure::Caught(); + SetErrorCode(aFail->GetMessageString()); + + return NULL; + } + + // Fill in statistics. theStats.clear(); + Handle(TColStd_HArray1OfInteger) aStatIDsArray[3] = + { aCI.GetRemovedIDs(), aCI.GetModifiedIDs(), aCI.GetAddedIDs() }; + int i; + int j; + + for (j = 0; j < 3; ++j) { + if (!aStatIDsArray[j].IsNull()) { + const int anUpperID = aStatIDsArray[j]->Upper(); + ExtractionStat aStat; + + for (i = aStatIDsArray[j]->Lower(); i <= anUpperID; ++i) { + aStat.indices.push_back(aStatIDsArray[j]->Value(i)); + } + + aStat.type = (ExtractionStatType) j; + theStats.push_back(aStat); + } + } + + //Make a Python command + GEOM::TPythonDump pd(aFunction); + + pd << aResult << " = geompy.MakeExtraction(" << theShape << ", ["; + + if (!theSubShapeIDs.IsNull()) { + const int aNbIDs = theSubShapeIDs->Upper(); + + for (i = theSubShapeIDs->Lower(); i < aNbIDs; ++i) { + pd << theSubShapeIDs->Value(i) << ", "; + } + + // Dump the last value without a comma. + pd << theSubShapeIDs->Value(i); + } + + pd << "])"; + SetErrorCode(OK); - return theShape; + return aResult; } //======================================================================= diff --git a/src/GEOMImpl/GEOMImpl_ShapeDriver.cxx b/src/GEOMImpl/GEOMImpl_ShapeDriver.cxx index 8b585f83e..71e3c7042 100644 --- a/src/GEOMImpl/GEOMImpl_ShapeDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_ShapeDriver.cxx @@ -22,6 +22,7 @@ #include +#include #include #include #include @@ -32,6 +33,7 @@ #include #include #include +#include // OCCT Includes #include @@ -73,6 +75,7 @@ #include #include +#include #include #include @@ -107,6 +110,39 @@ #include +/** + * \brief This static function converts the list of shapes into an array + * of their IDs. If the input list is empty, null handle will be returned. + * this method doesn't check if a shape presents in theIndices map. + * + * \param theListOfShapes the list of shapes. + * \param theIndices the indexed map of shapes. + * \return the array of shape IDs. + */ +static Handle(TColStd_HArray1OfInteger) GetShapeIDs + (const TopTools_ListOfShape &theListOfShapes, + const TopTools_IndexedMapOfShape &theIndices) +{ + Handle(TColStd_HArray1OfInteger) aResult; + + if (!theListOfShapes.IsEmpty()) { + const Standard_Integer aNbShapes = theListOfShapes.Extent(); + TopTools_ListIteratorOfListOfShape anIter(theListOfShapes); + Standard_Integer i; + + aResult = new TColStd_HArray1OfInteger(1, aNbShapes); + + for (i = 1; anIter.More(); anIter.Next(), ++i) { + const TopoDS_Shape &aShape = anIter.Value(); + const Standard_Integer anIndex = theIndices.FindIndex(aShape); + + aResult->SetValue(i, anIndex); + } + } + + return aResult; +} + namespace { // check that compound includes only shapes of expected type @@ -784,6 +820,86 @@ Standard_Integer GEOMImpl_ShapeDriver::Execute(TFunction_Logbook& log) const } } } + } else if (aType == EXTRACTION) { + allowCompound = true; + + GEOMImpl_IExtract aCI(aFunction); + Handle(GEOM_Function) aRefShape = aCI.GetShape(); + TopoDS_Shape aShapeBase = aRefShape->GetValue(); + + if (aShapeBase.IsNull()) { + Standard_NullObject::Raise("Argument Shape is null"); + return 0; + } + + Handle(TColStd_HArray1OfInteger) anIDs = aCI.GetSubShapeIDs(); + TopTools_ListOfShape aListSubShapes; + TopTools_IndexedMapOfShape anIndices; + int i; + + TopExp::MapShapes(aShapeBase, anIndices); + + if (!anIDs.IsNull()) { + const int anUpperID = anIDs->Upper(); + + for (i = anIDs->Lower(); i <= anUpperID; ++i) { + const Standard_Integer anIndex = anIDs->Value(i); + const TopoDS_Shape &aSubShape = anIndices.FindKey(anIndex); + aListSubShapes.Append(aSubShape); + } + } + + // Compute extraction. + GEOMAlgo_Extractor anExtractor; + + anExtractor.SetShape(aShapeBase); + anExtractor.SetShapesToRemove(aListSubShapes); + + anExtractor.Perform(); + + // Interprete results + Standard_Integer iErr = anExtractor.ErrorStatus(); + + // The detailed description of error codes is in GEOMAlgo_Extractor.cxx + if (iErr) { + TCollection_AsciiString aMsg(" iErr : "); + + aMsg += TCollection_AsciiString(iErr); + StdFail_NotDone::Raise(aMsg.ToCString()); + return 0; + } + + aShape = anExtractor.GetResult(); + + // Get statistics. + const TopTools_ListOfShape &aRemoved = anExtractor.GetRemoved(); + const TopTools_ListOfShape &aModified = anExtractor.GetModified(); + const TopTools_ListOfShape &aNew = anExtractor.GetNew(); + Handle(TColStd_HArray1OfInteger) aRemovedIDs = + GetShapeIDs(aRemoved, anIndices); + Handle(TColStd_HArray1OfInteger) aModifiedIDs = + GetShapeIDs(aModified, anIndices); + Handle(TColStd_HArray1OfInteger) aNewIDs; + + if (!aShape.IsNull()) { + // Get newly created sub-shapes + TopTools_IndexedMapOfShape aNewIndices; + + TopExp::MapShapes(aShape, aNewIndices); + aNewIDs = GetShapeIDs(aNew, aNewIndices); + } + + if (!aRemovedIDs.IsNull()) { + aCI.SetRemovedIDs(aRemovedIDs); + } + + if (!aModifiedIDs.IsNull()) { + aCI.SetModifiedIDs(aModifiedIDs); + } + + if (!aNewIDs.IsNull()) { + aCI.SetAddedIDs(aNewIDs); + } } else { } @@ -1746,6 +1862,15 @@ GetCreationInformation(std::string& theOperationName, AddParam(theParams, "Face", aSE.GetShape()); break; } + case EXTRACTION: + { + GEOMImpl_IExtract aCI (function); + + theOperationName = "EXTRACTION"; + AddParam(theParams, "Main Shape", aCI.GetShape()); + AddParam(theParams, "Sub-shape IDs", aCI.GetSubShapeIDs()); + break; + } default: return false; } diff --git a/src/GEOMImpl/GEOMImpl_Types.hxx b/src/GEOMImpl/GEOMImpl_Types.hxx index 393b4303c..2e58443ac 100644 --- a/src/GEOMImpl/GEOMImpl_Types.hxx +++ b/src/GEOMImpl/GEOMImpl_Types.hxx @@ -119,6 +119,8 @@ #define GEOM_TRANSFER_DATA 57 +#define GEOM_EXTRACTION 58 + //GEOM_Function types #define COPY_WITH_REF 1 @@ -316,6 +318,7 @@ #define FACE_UV 17 #define SURFACE_FROM_FACE 18 #define SOLID_FACES 19 +#define EXTRACTION 20 #define ARCHIMEDE_TYPE 1