From ba8a9c21c83e3ab7e65e5a1aa961bbd1df6850a2 Mon Sep 17 00:00:00 2001 From: mpv Date: Tue, 28 Oct 2014 10:53:24 +0300 Subject: [PATCH] Fixed problems with OCCT dependencies and extrusion crashes --- src/FeaturesPlugin/CMakeLists.txt | 3 - .../FeaturesPlugin_Extrusion.cpp | 119 ++++--- src/FeaturesPlugin/boolean_widget.xml | 2 + src/FeaturesPlugin/extrusion_widget.xml | 1 - src/GeomAPI/GeomAPI_Shape.h | 2 +- src/GeomAlgoAPI/GeomAlgoAPI_Extrusion.cpp | 313 +++++++++--------- src/GeomAlgoAPI/GeomAlgoAPI_Extrusion.h | 27 +- src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp | 68 ++-- src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.h | 18 +- src/Model/Model_AttributeSelection.cpp | 8 +- src/Model/Model_Data.cpp | 18 +- src/Model/Model_Data.h | 2 +- src/Model/Model_Document.cpp | 17 +- src/Model/Model_Validator.cpp | 15 +- src/Model/Model_Validator.h | 7 + src/ModelAPI/ModelAPI_Validator.h | 3 + 16 files changed, 342 insertions(+), 281 deletions(-) diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index ab966dff6..a0886cbb1 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -27,7 +27,6 @@ INCLUDE_DIRECTORIES( ../GeomAPI ../GeomAlgoAPI ../Events - ${CAS_INCLUDE_DIRS} ) SET(PROJECT_LIBRARIES @@ -35,8 +34,6 @@ SET(PROJECT_LIBRARIES ModelAPI GeomAPI GeomAlgoAPI - ${CAS_KERNEL} - ${CAS_SHAPE} ) ADD_DEFINITIONS(-DFEATURESPLUGIN_EXPORTS ${BOOST_DEFINITIONS}) diff --git a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp index b49f58854..b32f2e97a 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp @@ -13,10 +13,7 @@ #include #include #include -#include -#include -#include -#include + using namespace std; #define _LATERAL_TAG 1 #define _FIRST_TAG 2 @@ -25,6 +22,7 @@ using namespace std; #include #include #endif + FeaturesPlugin_Extrusion::FeaturesPlugin_Extrusion() { } @@ -39,7 +37,7 @@ void FeaturesPlugin_Extrusion::initAttributes() void FeaturesPlugin_Extrusion::execute() { boost::shared_ptr aFaceRef = boost::dynamic_pointer_cast< - ModelAPI_AttributeSelection>(data()->attribute(FeaturesPlugin_Extrusion::FACE_ID())); + ModelAPI_AttributeSelection>(data()->attribute(FeaturesPlugin_Extrusion::FACE_ID())); if (!aFaceRef) return; @@ -48,8 +46,19 @@ void FeaturesPlugin_Extrusion::execute() if (!aFace) return; - boost::shared_ptr aContext = - boost::dynamic_pointer_cast(aFaceRef->context()); + boost::shared_ptr aContext; + ResultPtr aContextRes = aFaceRef->context(); + if (aContextRes) { + if (aContextRes->groupName() == ModelAPI_ResultBody::group()) + aContext = boost::dynamic_pointer_cast(aContextRes)->shape(); + else if (aContextRes->groupName() == ModelAPI_ResultConstruction::group()) + aContext = boost::dynamic_pointer_cast(aContextRes)->shape(); + } + if (!aContext) { + std::string aContextError = "The selection context is bad"; + Events_Error::send(aContextError, this); + return; + } double aSize = data()->real(FeaturesPlugin_Extrusion::SIZE_ID())->value(); if (data()->boolean(FeaturesPlugin_Extrusion::REVERSE_ID())->value()) @@ -59,24 +68,24 @@ void FeaturesPlugin_Extrusion::execute() //TCollection_AsciiString anError; GeomAlgoAPI_Extrusion aFeature(aFace, aSize); if(!aFeature.isDone()) { - std::string aFeatureError = "Extrusion algorithm failed"; + std::string aFeatureError = "Extrusion algorithm failed"; Events_Error::send(aFeatureError, this); - return; + return; } - // Check if shape is valid - if (!aFeature.shape()->impl().IsNull()) { + // Check if shape is valid + if (aFeature.shape()->isNull()) { std::string aShapeError = "Resulting shape is Null"; Events_Error::send(aShapeError, this); - #ifdef _DEBUG +#ifdef _DEBUG std::cerr << aShapeError << std::endl; - #endif +#endif return; } - if(!aFeature.isValid()) { - std::string aFeatureError = "Warning: resulting shape is not valid"; + if(!aFeature.isValid()) { + std::string aFeatureError = "Warning: resulting shape is not valid"; Events_Error::send(aFeatureError, this); - return; + return; } //LoadNamingDS LoadNamingDS(aFeature, aResultBody, aFace, aContext); @@ -84,27 +93,27 @@ void FeaturesPlugin_Extrusion::execute() setResult(aResultBody); } - //============================================================================ +//============================================================================ void FeaturesPlugin_Extrusion::LoadNamingDS(GeomAlgoAPI_Extrusion& theFeature, - boost::shared_ptr theResultBody, - boost::shared_ptr theBasis, - boost::shared_ptr theContext) + boost::shared_ptr theResultBody, + boost::shared_ptr theBasis, + boost::shared_ptr theContext) { - - //load result - if(theBasis->impl().IsEqual(theContext->impl())) - theResultBody->store(theFeature.shape()); - else - theResultBody->storeGenerated(theContext, theFeature.shape()); - TopTools_DataMapOfShapeShape aSubShapes; - for (TopExp_Explorer Exp(theFeature.shape()->impl(),TopAbs_FACE); Exp.More(); Exp.Next()) { - aSubShapes.Bind(Exp.Current(),Exp.Current()); - } + //load result + if(theBasis->isEqual(theContext)) + theResultBody->store(theFeature.shape()); + else + theResultBody->storeGenerated(theContext, theFeature.shape()); + /* + TopTools_DataMapOfShapeShape aSubShapes; + for (TopExp_Explorer Exp(theFeature.shape()->impl(),TopAbs_FACE); Exp.More(); Exp.Next()) { + aSubShapes.Bind(Exp.Current(),Exp.Current()); + } - //Insert lateral face : Face from Edge - //GeomAlgoAPI_DFLoader::loadAndOrientGeneratedShapes(*myBuilder, myBasis, TopAbs_EDGE, aLateralFaceBuilder, aSubShapes); + //Insert lateral face : Face from Edge + //GeomAlgoAPI_DFLoader::loadAndOrientGeneratedShapes(*myBuilder, myBasis, TopAbs_EDGE, aLateralFaceBuilder, aSubShapes); TopTools_MapOfShape aView; @@ -112,42 +121,42 @@ void FeaturesPlugin_Extrusion::LoadNamingDS(GeomAlgoAPI_Extrusion& theFeature, for (; aShapeExplorer.More(); aShapeExplorer.Next ()) { const TopoDS_Shape& aRoot = aShapeExplorer.Current (); if (!aView.Add(aRoot)) continue; - boost::shared_ptr aRootG(new GeomAPI_Shape()); - aRootG->setImpl((void *)&aRoot); - const ListOfShape& aShapes = theFeature.generated(aRootG); - std::list >::const_iterator anIt = aShapes.begin(), aLast = aShapes.end(); - for (; anIt != aLast; anIt++) { + boost::shared_ptr aRootG(new GeomAPI_Shape()); + aRootG->setImpl((void *)&aRoot); + const ListOfShape& aShapes = theFeature.generated(aRootG); + std::list >::const_iterator anIt = aShapes.begin(), aLast = aShapes.end(); + for (; anIt != aLast; anIt++) { TopoDS_Shape aNewShape = (*anIt)->impl(); if (aSubShapes.IsBound(aNewShape)) { aNewShape.Orientation((aSubShapes(aNewShape)).Orientation()); } - if (!aRoot.IsSame (aNewShape)) { - boost::shared_ptr aNew(new GeomAPI_Shape()); - aNew->setImpl((void *)&aNewShape); - theResultBody->generated(aRootG, aNew,_LATERAL_TAG); - } - } + if (!aRoot.IsSame (aNewShape)) { + boost::shared_ptr aNew(new GeomAPI_Shape()); + aNew->setImpl((void *)&aNewShape); + theResultBody->generated(aRootG, aNew,_LATERAL_TAG); + } + } } - //Insert bottom face const boost::shared_ptr& aBottomFace = theFeature.firstShape(); - if (!aBottomFace->impl().IsNull()) { - if (aSubShapes.IsBound(aBottomFace->impl())) { - aBottomFace->setImpl((void *)&aSubShapes(aBottomFace->impl())); - } - theResultBody->generated(aBottomFace, _FIRST_TAG); + if (!aBottomFace->isNull()) { + if (aSubShapes.IsBound(aBottomFace->impl())) { + aBottomFace->setImpl((void *)&aSubShapes(aBottomFace->impl())); + } + theResultBody->generated(aBottomFace, _FIRST_TAG); } - - //Insert top face + + //Insert top face boost::shared_ptr aTopFace = theFeature.lastShape(); - if (!aTopFace->impl().IsNull()) { - if (aSubShapes.IsBound(aTopFace->impl())) { - aTopFace->setImpl((void *)&aSubShapes(aTopFace->impl())); - } + if (!aTopFace->isNull()) { + if (aSubShapes.IsBound(aTopFace->impl())) { + aTopFace->setImpl((void *)&aSubShapes(aTopFace->impl())); + } theResultBody->generated(aTopFace, _FIRST_TAG); } + */ } diff --git a/src/FeaturesPlugin/boolean_widget.xml b/src/FeaturesPlugin/boolean_widget.xml index cdf8e195e..af4822c2c 100644 --- a/src/FeaturesPlugin/boolean_widget.xml +++ b/src/FeaturesPlugin/boolean_widget.xml @@ -4,12 +4,14 @@ icon=":icons/cut_shape.png" tooltip="Select an object to cut" shape_types="solid shell" + concealment="true" /> diff --git a/src/GeomAPI/GeomAPI_Shape.h b/src/GeomAPI/GeomAPI_Shape.h index 9c903d682..03f75d745 100644 --- a/src/GeomAPI/GeomAPI_Shape.h +++ b/src/GeomAPI/GeomAPI_Shape.h @@ -33,7 +33,7 @@ class GEOMAPI_EXPORT GeomAPI_Shape : public GeomAPI_Interface }; //! Pointer on list of shapes -typedef std::list> ListOfShape; +typedef std::list > ListOfShape; //! Pointer on attribute object typedef boost::shared_ptr GeomShapePtr; diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Extrusion.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Extrusion.cpp index d5f2c4379..b81b0f5fe 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Extrusion.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Extrusion.cpp @@ -20,173 +20,180 @@ #include #include #include +#include +#include const double tolerance = Precision::Angular(); - // Constructor -GeomAlgoAPI_Extrusion::GeomAlgoAPI_Extrusion (boost::shared_ptr theBasis, double theSize) - : mySize(theSize), myBuilder(NULL), myDone(false), myShape(new GeomAPI_Shape()) - { - myBasis = theBasis->impl(); - build(); - } - - //============================================================================ - void GeomAlgoAPI_Extrusion::build() - { - bool isFirstNorm = true; - gp_Dir aShapeNormal; - - //const TopoDS_Shape& aShape = theShape->impl(); - Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(TopoDS::Face(myBasis))); - if (aPlane.IsNull()) // non-planar shapes is not supported for extrusion yet - return; - - const gp_Dir& aNormal = aPlane->Pln().Axis().Direction(); - gp_Vec aVec(aNormal); - aVec = aVec * mySize; - - myBuilder = new BRepPrimAPI_MakePrism(myBasis, aVec); - if(myBuilder != NULL) { - myDone = myBuilder->IsDone(); - if(myDone) { - if(myBuilder->Shape().ShapeType() == TopAbs_COMPOUND) - myResult = GeomAlgoAPI_DFLoader::refineResult(myBuilder->Shape()); - else - myResult = myBuilder->Shape(); - myShape->setImpl((void *)&myResult); - myFirst->setImpl((void *)&(myBuilder->FirstShape())); - myLast->setImpl((void *)&(myBuilder-> LastShape())); - } - } - } +// Constructor +GeomAlgoAPI_Extrusion::GeomAlgoAPI_Extrusion( + boost::shared_ptr theBasis, double theSize) +: mySize(theSize), myDone(false), + myShape(new GeomAPI_Shape()), myFirst(new GeomAPI_Shape()), myLast(new GeomAPI_Shape()) +{ + build(theBasis); +} - //============================================================================ +//============================================================================ +void GeomAlgoAPI_Extrusion::build(const boost::shared_ptr& theBasis) +{ + bool isFirstNorm = true; + gp_Dir aShapeNormal; + + //const TopoDS_Shape& aShape = theShape->impl(); + TopoDS_Face aBasis = TopoDS::Face(theBasis->impl()); + Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( + BRep_Tool::Surface(aBasis)); + if (aPlane.IsNull()) // non-planar shapes is not supported for extrusion yet + return; + + const gp_Dir& aNormal = aPlane->Pln().Axis().Direction(); + gp_Vec aVec(aNormal); + aVec = aVec * mySize; + + BRepPrimAPI_MakePrism* aBuilder = new BRepPrimAPI_MakePrism(aBasis, aVec); + if(aBuilder) { + setImpl(aBuilder); + myDone = aBuilder->IsDone() == Standard_True; + if (myDone) { + BRepCheck_Analyzer aChecker(aBuilder->Shape()); + myDone = aChecker.IsValid() == Standard_True; + } + if(myDone) { + TopoDS_Shape aResult; + if(aBuilder->Shape().ShapeType() == TopAbs_COMPOUND) + aResult = GeomAlgoAPI_DFLoader::refineResult(aBuilder->Shape()); + else + aResult = aBuilder->Shape(); + myShape->setImpl(new TopoDS_Shape(aResult)); + myFirst->setImpl(new TopoDS_Shape(aBuilder->FirstShape())); + myLast->setImpl(new TopoDS_Shape(aBuilder-> LastShape())); + } + } +} + +//============================================================================ const bool GeomAlgoAPI_Extrusion::isDone() const {return myDone;} - //============================================================================ +//============================================================================ const bool GeomAlgoAPI_Extrusion::isValid() const { - bool isValid(false); - if(myDone && !myBuilder->Shape().IsNull()) { - BRepCheck_Analyzer aChecker(myBuilder->Shape()); - isValid = aChecker.IsValid(); - } - return isValid; - } + return myDone; +} - //============================================================================ - const bool GeomAlgoAPI_Extrusion::hasVolume() const - { - bool hasVolume(false); - if(isValid()) { - const TopoDS_Shape& aRShape = myBuilder->Shape(); - GProp_GProps aGProp; - BRepGProp::VolumeProperties(aRShape, aGProp); - if(aGProp.Mass() > Precision::Confusion()) - hasVolume = true; - } - return hasVolume; +//============================================================================ +const bool GeomAlgoAPI_Extrusion::hasVolume() const +{ + bool hasVolume(false); + if(isValid()) { + const TopoDS_Shape& aRShape = myShape->impl(); + GProp_GProps aGProp; + BRepGProp::VolumeProperties(aRShape, aGProp); + if(aGProp.Mass() > Precision::Confusion()) + hasVolume = true; } + return hasVolume; +} - //============================================================================ +//============================================================================ const boost::shared_ptr& GeomAlgoAPI_Extrusion::shape () const {return myShape;} - //============================================================================ - const ListOfShape& GeomAlgoAPI_Extrusion::generated(const boost::shared_ptr theShape) - { - myHistory.clear(); - if(myDone) { - const TopTools_ListOfShape& aList = myBuilder->Generated(theShape->impl()); +//============================================================================ +void GeomAlgoAPI_Extrusion::generated( + const boost::shared_ptr theShape, ListOfShape& theHistory) +{ + theHistory.clear(); + if(myDone) { + const TopTools_ListOfShape& aList = implPtr() + ->Generated(theShape->impl()); TopTools_ListIteratorOfListOfShape it(aList); - for(;it.More();it.Next()) { - boost::shared_ptr aShape(new GeomAPI_Shape()); - aShape->setImpl(&(it.Value())); - myHistory.push_back(aShape); - } - } - return myHistory; + for(;it.More();it.Next()) { + boost::shared_ptr aShape(new GeomAPI_Shape()); + aShape->setImpl(&(it.Value())); + theHistory.push_back(aShape); + } } - - //============================================================================ - const boost::shared_ptr& GeomAlgoAPI_Extrusion::firstShape() - { - return myFirst; - } - - //============================================================================ - const boost::shared_ptr& GeomAlgoAPI_Extrusion::lastShape() - { - return myLast; - } - - //============================================================================ - /* - void GeomAlgoAPI_Extrusion::LoadNamingDS(boost::shared_ptr theResultBody, - boost::shared_ptr theContext) +} + +//============================================================================ +const boost::shared_ptr& GeomAlgoAPI_Extrusion::firstShape() { - if(isValid()) { - const TopoDS_Shape& aShape = myBuilder->Shape(); - TopoDS_Shape aResult = GeomAlgoAPI_DFLoader::refineResult(aShape); - boost::shared_ptr aData = boost::dynamic_pointer_cast(theResultBody->data()); - if (aData) { - const TDF_Label& aShapeLab = aData->shapeLab(); - const Handle(TDF_TagSource)& Tagger = TDF_TagSource::Set(aShapeLab); - if (Tagger.IsNull()) return; - Tagger->Set(0); - - TNaming_Builder aBuilder (aShapeLab); - if(myBasis.IsEqual(theContext->impl())) - aBuilder.Generated(aResult); - else - aBuilder.Generated(theContext->impl(), aResult); - - TopTools_DataMapOfShapeShape aSubShapes; - for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) { - aSubShapes.Bind(Exp.Current(),Exp.Current()); - } - - //Insert lateral face : Face from Edge - TNaming_Builder aLateralFaceBuilder(aShapeLab.NewChild()); - GeomAlgoAPI_DFLoader::loadAndOrientGeneratedShapes(*myBuilder, myBasis, TopAbs_EDGE, aLateralFaceBuilder, aSubShapes); - - //Insert bottom face - TopoDS_Shape aBottomFace = myBuilder->FirstShape(); - if (!aBottomFace.IsNull()) { - if (aBottomFace.ShapeType() != TopAbs_COMPOUND) { - TNaming_Builder aBottomBuilder(aShapeLab.NewChild()); //2 - if (aSubShapes.IsBound(aBottomFace)) { - aBottomFace = aSubShapes(aBottomFace); - } - aBottomBuilder.Generated(aBottomFace); - } else { - TopoDS_Iterator itr(aBottomFace); - for (; itr.More(); itr.Next()) { - TNaming_Builder aBottomBuilder(aShapeLab.NewChild()); - aBottomBuilder.Generated(itr.Value()); - } - } - - } - - //Insert top face - TopoDS_Shape aTopFace = myBuilder->LastShape(); - if (!aTopFace.IsNull()) { - if (aTopFace.ShapeType() != TopAbs_COMPOUND) { - TNaming_Builder aTopBuilder(aShapeLab.NewChild()); //3 - if (aSubShapes.IsBound(aTopFace)) { - aTopFace = aSubShapes(aTopFace); - } - aTopBuilder.Generated(aTopFace); - } else { - TopoDS_Iterator itr(aTopFace); - for (; itr.More(); itr.Next()) { - TNaming_Builder aTopBuilder(aShapeLab.NewChild()); - aTopBuilder.Generated(itr.Value()); - } - } - } - } - } - */ \ No newline at end of file + return myFirst; +} + +//============================================================================ +const boost::shared_ptr& GeomAlgoAPI_Extrusion::lastShape() +{ + return myLast; +} + +//============================================================================ +/* +void GeomAlgoAPI_Extrusion::LoadNamingDS(boost::shared_ptr theResultBody, +boost::shared_ptr theContext) +{ +if(isValid()) { +const TopoDS_Shape& aShape = myBuilder->Shape(); +TopoDS_Shape aResult = GeomAlgoAPI_DFLoader::refineResult(aShape); +boost::shared_ptr aData = boost::dynamic_pointer_cast(theResultBody->data()); +if (aData) { +const TDF_Label& aShapeLab = aData->shapeLab(); +const Handle(TDF_TagSource)& Tagger = TDF_TagSource::Set(aShapeLab); +if (Tagger.IsNull()) return; +Tagger->Set(0); + +TNaming_Builder aBuilder (aShapeLab); +if(myBasis.IsEqual(theContext->impl())) +aBuilder.Generated(aResult); +else +aBuilder.Generated(theContext->impl(), aResult); + +TopTools_DataMapOfShapeShape aSubShapes; +for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) { +aSubShapes.Bind(Exp.Current(),Exp.Current()); +} + +//Insert lateral face : Face from Edge +TNaming_Builder aLateralFaceBuilder(aShapeLab.NewChild()); +GeomAlgoAPI_DFLoader::loadAndOrientGeneratedShapes(*myBuilder, myBasis, TopAbs_EDGE, aLateralFaceBuilder, aSubShapes); + +//Insert bottom face +TopoDS_Shape aBottomFace = myBuilder->FirstShape(); +if (!aBottomFace.IsNull()) { +if (aBottomFace.ShapeType() != TopAbs_COMPOUND) { +TNaming_Builder aBottomBuilder(aShapeLab.NewChild()); //2 +if (aSubShapes.IsBound(aBottomFace)) { +aBottomFace = aSubShapes(aBottomFace); +} +aBottomBuilder.Generated(aBottomFace); +} else { +TopoDS_Iterator itr(aBottomFace); +for (; itr.More(); itr.Next()) { +TNaming_Builder aBottomBuilder(aShapeLab.NewChild()); +aBottomBuilder.Generated(itr.Value()); +} +} + +} + +//Insert top face +TopoDS_Shape aTopFace = myBuilder->LastShape(); +if (!aTopFace.IsNull()) { +if (aTopFace.ShapeType() != TopAbs_COMPOUND) { +TNaming_Builder aTopBuilder(aShapeLab.NewChild()); //3 +if (aSubShapes.IsBound(aTopFace)) { +aTopFace = aSubShapes(aTopFace); +} +aTopBuilder.Generated(aTopFace); +} else { +TopoDS_Iterator itr(aTopFace); +for (; itr.More(); itr.Next()) { +TNaming_Builder aTopBuilder(aShapeLab.NewChild()); +aTopBuilder.Generated(itr.Value()); +} +} +} +} +} +*/ \ No newline at end of file diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Extrusion.h b/src/GeomAlgoAPI/GeomAlgoAPI_Extrusion.h index 03d704d5d..bebeb35f5 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Extrusion.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Extrusion.h @@ -10,14 +10,12 @@ #include #include #include -#include -#include /**\class GeomAlgoAPI_Extrusion * \ingroup DataAlgo * \brief Allows to create the prism based on a given face and a direction */ -class GEOMALGOAPI_EXPORT GeomAlgoAPI_Extrusion +class GeomAlgoAPI_Extrusion : public GeomAPI_Interface { public: @@ -31,39 +29,36 @@ class GEOMALGOAPI_EXPORT GeomAlgoAPI_Extrusion boost::shared_ptr theContext, double theSize); */ /// Constructor - GeomAlgoAPI_Extrusion (boost::shared_ptr theBasis, double theSize); + GEOMALGOAPI_EXPORT GeomAlgoAPI_Extrusion (boost::shared_ptr theBasis, double theSize); /// Returns True if algorithm succeed - const bool isDone() const; + GEOMALGOAPI_EXPORT const bool isDone() const; /// Returns True if resulting shape is valid - const bool isValid() const; + GEOMALGOAPI_EXPORT const bool isValid() const; /// Returns True if resulting shape has volume - const bool hasVolume() const; + GEOMALGOAPI_EXPORT const bool hasVolume() const; /// Returns result of the Extrusion algorithm which may be a Solid or a Face - const boost::shared_ptr& shape () const; + GEOMALGOAPI_EXPORT const boost::shared_ptr& shape () const; /// Returns list of shapes generated from theShape - const ListOfShape& generated(const boost::shared_ptr theShape); + GEOMALGOAPI_EXPORT void generated(const boost::shared_ptr theShape, + ListOfShape& theHistory); /// Returns the first shape - const boost::shared_ptr& firstShape(); + GEOMALGOAPI_EXPORT const boost::shared_ptr& firstShape(); /// returns last shape - const boost::shared_ptr& lastShape(); + GEOMALGOAPI_EXPORT const boost::shared_ptr& lastShape(); private: /// builds resulting shape - void build(); + void build(const boost::shared_ptr& theBasis); - BRepPrimAPI_MakePrism * myBuilder; - TopoDS_Shape myBasis; double mySize; bool myDone; - TopoDS_Shape myResult; - ListOfShape myHistory; boost::shared_ptr myShape; boost::shared_ptr myFirst; boost::shared_ptr myLast; diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp index d743b567a..679526bef 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.cpp @@ -5,54 +5,54 @@ #include #include #include -GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape(BRepBuilderAPI_MakeShape * theMkShape) -{ myBuilder = theMkShape;} +GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape(void* theMkShape) + : GeomAPI_Interface(theMkShape) +{} -const boost::shared_ptr GeomAlgoAPI_MakeShape::shape() const +const boost::shared_ptr GeomAlgoAPI_MakeShape::shape() const { - boost::shared_ptr aShape(new GeomAPI_Shape()); - if(myBuilder != NULL) - aShape->setImpl(new TopoDS_Shape(myBuilder->Shape())); - return aShape; + return myShape; } - /// Returns the list of shapes generated from the shape -const ListOfShape& GeomAlgoAPI_MakeShape::generated(const boost::shared_ptr theShape) +/// Returns the list of shapes generated from the shape +void GeomAlgoAPI_MakeShape::generated( + const boost::shared_ptr theShape, ListOfShape& theHistory) { - myHistory.clear(); - if(myBuilder != NULL) { - const TopTools_ListOfShape& aList = myBuilder->Generated(theShape->impl()); + BRepBuilderAPI_MakeShape* aBuilder = implPtr(); + if(aBuilder) { + const TopTools_ListOfShape& aList = aBuilder->Generated(theShape->impl()); TopTools_ListIteratorOfListOfShape it(aList); - for(;it.More();it.Next()) { - boost::shared_ptr aShape(new GeomAPI_Shape()); - aShape->setImpl(&(it.Value())); - myHistory.push_back(aShape); - } + for(;it.More();it.Next()) { + boost::shared_ptr aShape(new GeomAPI_Shape()); + aShape->setImpl(&(it.Value())); + theHistory.push_back(aShape); + } } - return myHistory; } - /// Returns the list of shapes modified from the shape -const ListOfShape& GeomAlgoAPI_MakeShape::modified(const boost::shared_ptr theShape) +/// Returns the list of shapes modified from the shape +void GeomAlgoAPI_MakeShape::modified( + const boost::shared_ptr theShape, ListOfShape& theHistory) { - myHistory.clear(); - if(myBuilder != NULL) { - const TopTools_ListOfShape& aList = myBuilder->Modified(theShape->impl()); - TopTools_ListIteratorOfListOfShape it(aList); - for(;it.More();it.Next()) { - boost::shared_ptr aShape(new GeomAPI_Shape()); - aShape->setImpl(&(it.Value())); - myHistory.push_back(aShape); - } + BRepBuilderAPI_MakeShape* aBuilder = implPtr(); + if(aBuilder) { + const TopTools_ListOfShape& aList = aBuilder->Modified(theShape->impl()); + TopTools_ListIteratorOfListOfShape it(aList); + for(;it.More();it.Next()) { + boost::shared_ptr aShape(new GeomAPI_Shape()); + aShape->setImpl(&(it.Value())); + theHistory.push_back(aShape); + } } - return myHistory; } - /// Returns whether the shape is an edge +/// Returns whether the shape is an edge bool GeomAlgoAPI_MakeShape::isDeleted(const boost::shared_ptr theShape) { bool isDeleted(false); - if (myBuilder != NULL) - isDeleted = (bool) myBuilder->IsDeleted(theShape->impl()); + BRepBuilderAPI_MakeShape* aBuilder = implPtr(); + if(aBuilder) { + isDeleted = aBuilder->IsDeleted(theShape->impl()) == Standard_True; + } return isDeleted; -} \ No newline at end of file +} diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.h b/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.h index 9357ff432..89dae08a5 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.h @@ -12,27 +12,27 @@ * \ingroup DataModel * \Interface to the root class of all topological shapes constructions */ -class GEOMALGOAPI_EXPORT GeomAlgoAPI_MakeShape +class GeomAlgoAPI_MakeShape : GeomAPI_Interface { public: /// Constructor - GeomAlgoAPI_MakeShape(BRepBuilderAPI_MakeShape * theBuilder); + GEOMALGOAPI_EXPORT GeomAlgoAPI_MakeShape(void* theBuilder); /// Returns a shape built by the shape construction algorithm - const boost::shared_ptr shape() const; + GEOMALGOAPI_EXPORT const boost::shared_ptr shape() const; /// Returns the list of shapes generated from the shape - virtual const ListOfShape& generated(const boost::shared_ptr theShape); + GEOMALGOAPI_EXPORT virtual void generated( + const boost::shared_ptr theShape, ListOfShape& theHistory); /// Returns the list of shapes modified from the shape - virtual const ListOfShape& modified(const boost::shared_ptr theShape); + GEOMALGOAPI_EXPORT virtual void modified( + const boost::shared_ptr theShape, ListOfShape& theHistory); /// Returns whether the shape is an edge - virtual bool isDeleted(const boost::shared_ptr theShape); + GEOMALGOAPI_EXPORT virtual bool isDeleted(const boost::shared_ptr theShape); protected: boost::shared_ptr myShape; - ListOfShape myHistory; - BRepBuilderAPI_MakeShape * myBuilder; }; -#endif \ No newline at end of file +#endif diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index 54a52a22a..f502aee03 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -168,10 +168,10 @@ bool Model_AttributeSelection::update() } } } - if (aNewSelected) { // store this new selection - selectConstruction(aContext, aNewSelected); - return true; - } + } + if (aNewSelected) { // store this new selection + selectConstruction(aContext, aNewSelected); + return true; } } } diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index cc3ed5ef3..fe65a751d 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -356,10 +357,25 @@ int Model_Data::featureId() const return myLab.Father().Tag(); // tag of the feature label } +void Model_Data::eraseBackReferences() +{ + myRefsToMe.clear(); + boost::shared_ptr aRes = + boost::dynamic_pointer_cast(myObject); + if (aRes) + aRes->setIsConcealed(false); +} + void Model_Data::addBackReference(FeaturePtr theFeature, std::string theAttrID) { - // TODO: the concealment state update myRefsToMe.insert(theFeature->data()->attribute(theAttrID)); + if (ModelAPI_Session::get()->validators()->isConcealed(theFeature->getKind(), theAttrID)) { + boost::shared_ptr aRes = + boost::dynamic_pointer_cast(myObject); + if (aRes) { + aRes->setIsConcealed(true); + } + } } void Model_Data::referencesToObjects( diff --git a/src/Model/Model_Data.h b/src/Model/Model_Data.h index 46d50acc0..cb7158b75 100644 --- a/src/Model/Model_Data.h +++ b/src/Model/Model_Data.h @@ -154,7 +154,7 @@ class Model_Data : public ModelAPI_Data private: // removes all information about back references - inline void eraseBackReferences() {myRefsToMe.clear();} + void eraseBackReferences(); // adds a back reference (with identifier which attribute references to this object void addBackReference(FeaturePtr theFeature, std::string theAttrID); // returns all objects referenced to this diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index 05452239c..cb05a7fbb 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -288,7 +288,6 @@ void Model_Document::finishOperation() myIsEmptyTr[myTransactionsAfterSave] = !myDoc->CommitCommand(); // && (myNestedNum == -1); myTransactionsAfterSave++; } - } void Model_Document::abortOperation() @@ -793,6 +792,10 @@ void Model_Document::synchronizeFeatures(const bool theMarkUpdated, const bool t void Model_Document::synchronizeBackRefs() { + boost::shared_ptr aThis = + Model_Application::getApplication()->getDocument(myID); + // keeps the concealed flags of result to catch the change and create created/deleted events + std::list > aConcealed; // first cycle: erase all data about back-references NCollection_DataMap::Iterator aFeatures(myObjs); for(; aFeatures.More(); aFeatures.Next()) { @@ -808,6 +811,7 @@ void Model_Document::synchronizeBackRefs() boost::shared_ptr aResData = boost::dynamic_pointer_cast((*aRIter)->data()); if (aResData) { + aConcealed.push_back(std::pair(*aRIter, (*aRIter)->isConcealed())); aResData->eraseBackReferences(); } } @@ -835,6 +839,17 @@ void Model_Document::synchronizeBackRefs() } } } + std::list >::iterator aCIter = aConcealed.begin(); + for(; aCIter != aConcealed.end(); aCIter++) { + if (aCIter->first->isConcealed() != aCIter->second) { // somethign is changed => produce event + if (aCIter->second) { // was concealed become not => creation event + static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED); + ModelAPI_EventCreator::get()->sendUpdated(aCIter->first, anEvent); + } else { // was not concealed become concealed => delete event + ModelAPI_EventCreator::get()->sendDeleted(aThis, aCIter->first->groupName()); + } + } + } } TDF_Label Model_Document::resultLabel( diff --git a/src/Model/Model_Validator.cpp b/src/Model/Model_Validator.cpp index d1adbbbe9..eecd08b33 100644 --- a/src/Model/Model_Validator.cpp +++ b/src/Model/Model_Validator.cpp @@ -224,7 +224,18 @@ void Model_ValidatorsFactory::registerNotObligatory(std::string theFeature, std: void Model_ValidatorsFactory::registerConcealment(std::string theFeature, std::string theAttribute) { - + std::map >::iterator aFind = myConcealed.find(theFeature); + if (aFind == myConcealed.end()) { + std::set aNewSet; + aNewSet.insert(theAttribute); + myConcealed[theFeature] = aNewSet; + } else { + aFind->second.insert(theAttribute); + } } - +bool Model_ValidatorsFactory::isConcealed(std::string theFeature, std::string theAttribute) +{ + std::map >::iterator aFind = myConcealed.find(theFeature); + return aFind != myConcealed.end() && aFind->second.find(theAttribute) != aFind->second.end(); +} diff --git a/src/Model/Model_Validator.h b/src/Model/Model_Validator.h index cfaeb89c5..5fa3a8a90 100644 --- a/src/Model/Model_Validator.h +++ b/src/Model/Model_Validator.h @@ -32,6 +32,10 @@ class Model_ValidatorsFactory : public ModelAPI_ValidatorsFactory std::map myFeatures; /// validators IDs and arguments by feature and attribute IDs std::map > myAttrs; + /// Stores the registered attributes that leads to the concealment of referenced objects in + /// data tree. Map from feature kind to set of attribute IDs. + std::map > myConcealed; + public: /// Registers the instance of the validator by the ID MODEL_EXPORT virtual void registerValidator(const std::string& theID, @@ -76,6 +80,9 @@ class Model_ValidatorsFactory : public ModelAPI_ValidatorsFactory /// all referenced features after execution virtual void registerConcealment(std::string theFeature, std::string theAttribute); + /// Returns true that it was registered that attribute conceals the referenced result + virtual bool isConcealed(std::string theFeature, std::string theAttribute); + protected: void addDefaultValidators(std::list& theValidators) const; /// Get instance from Session diff --git a/src/ModelAPI/ModelAPI_Validator.h b/src/ModelAPI/ModelAPI_Validator.h index 940be4c4d..cd73508d5 100644 --- a/src/ModelAPI/ModelAPI_Validator.h +++ b/src/ModelAPI/ModelAPI_Validator.h @@ -87,6 +87,9 @@ class MODELAPI_EXPORT ModelAPI_ValidatorsFactory /// all referenced features after execution virtual void registerConcealment(std::string theFeature, std::string theAttribute) = 0; + /// Returns true that it was registered that attribute conceals the referenced result + virtual bool isConcealed(std::string theFeature, std::string theAttribute) = 0; + protected: /// Get instance from Session ModelAPI_ValidatorsFactory() -- 2.39.2