../GeomAPI
../GeomAlgoAPI
../Events
- ${CAS_INCLUDE_DIRS}
)
SET(PROJECT_LIBRARIES
ModelAPI
GeomAPI
GeomAlgoAPI
- ${CAS_KERNEL}
- ${CAS_SHAPE}
)
ADD_DEFINITIONS(-DFEATURESPLUGIN_EXPORTS ${BOOST_DEFINITIONS})
#include <ModelAPI_AttributeBoolean.h>
#include <Events_Error.h>
#include <GeomAlgoAPI_Extrusion.h>
-#include <TopoDS_Shape.hxx>
-#include <TopTools_DataMapOfShapeShape.hxx>
-#include <TopExp_Explorer.hxx>
-#include <TopTools_MapOfShape.hxx>
+
using namespace std;
#define _LATERAL_TAG 1
#define _FIRST_TAG 2
#include <iostream>
#include <ostream>
#endif
+
FeaturesPlugin_Extrusion::FeaturesPlugin_Extrusion()
{
}
void FeaturesPlugin_Extrusion::execute()
{
boost::shared_ptr<ModelAPI_AttributeSelection> aFaceRef = boost::dynamic_pointer_cast<
- ModelAPI_AttributeSelection>(data()->attribute(FeaturesPlugin_Extrusion::FACE_ID()));
+ ModelAPI_AttributeSelection>(data()->attribute(FeaturesPlugin_Extrusion::FACE_ID()));
if (!aFaceRef)
return;
if (!aFace)
return;
- boost::shared_ptr<GeomAPI_Shape> aContext =
- boost::dynamic_pointer_cast<GeomAPI_Shape>(aFaceRef->context());
+ boost::shared_ptr<GeomAPI_Shape> aContext;
+ ResultPtr aContextRes = aFaceRef->context();
+ if (aContextRes) {
+ if (aContextRes->groupName() == ModelAPI_ResultBody::group())
+ aContext = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(aContextRes)->shape();
+ else if (aContextRes->groupName() == ModelAPI_ResultConstruction::group())
+ aContext = boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(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())
//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<TopoDS_Shape>().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);
setResult(aResultBody);
}
- //============================================================================
+//============================================================================
void FeaturesPlugin_Extrusion::LoadNamingDS(GeomAlgoAPI_Extrusion& theFeature,
- boost::shared_ptr<ModelAPI_ResultBody> theResultBody,
- boost::shared_ptr<GeomAPI_Shape> theBasis,
- boost::shared_ptr<GeomAPI_Shape> theContext)
+ boost::shared_ptr<ModelAPI_ResultBody> theResultBody,
+ boost::shared_ptr<GeomAPI_Shape> theBasis,
+ boost::shared_ptr<GeomAPI_Shape> theContext)
{
-
- //load result
- if(theBasis->impl<TopoDS_Shape>().IsEqual(theContext->impl<TopoDS_Shape>()))
- theResultBody->store(theFeature.shape());
- else
- theResultBody->storeGenerated(theContext, theFeature.shape());
- TopTools_DataMapOfShapeShape aSubShapes;
- for (TopExp_Explorer Exp(theFeature.shape()->impl<TopoDS_Shape>(),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<TopoDS_Shape>(),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;
for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
if (!aView.Add(aRoot)) continue;
- boost::shared_ptr<GeomAPI_Shape> aRootG(new GeomAPI_Shape());
- aRootG->setImpl((void *)&aRoot);
- const ListOfShape& aShapes = theFeature.generated(aRootG);
- std::list<boost::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = aShapes.begin(), aLast = aShapes.end();
- for (; anIt != aLast; anIt++) {
+ boost::shared_ptr<GeomAPI_Shape> aRootG(new GeomAPI_Shape());
+ aRootG->setImpl((void *)&aRoot);
+ const ListOfShape& aShapes = theFeature.generated(aRootG);
+ std::list<boost::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = aShapes.begin(), aLast = aShapes.end();
+ for (; anIt != aLast; anIt++) {
TopoDS_Shape aNewShape = (*anIt)->impl<TopoDS_Shape>();
if (aSubShapes.IsBound(aNewShape)) {
aNewShape.Orientation((aSubShapes(aNewShape)).Orientation());
}
- if (!aRoot.IsSame (aNewShape)) {
- boost::shared_ptr<GeomAPI_Shape> aNew(new GeomAPI_Shape());
- aNew->setImpl((void *)&aNewShape);
- theResultBody->generated(aRootG, aNew,_LATERAL_TAG);
- }
- }
+ if (!aRoot.IsSame (aNewShape)) {
+ boost::shared_ptr<GeomAPI_Shape> aNew(new GeomAPI_Shape());
+ aNew->setImpl((void *)&aNewShape);
+ theResultBody->generated(aRootG, aNew,_LATERAL_TAG);
+ }
+ }
}
-
//Insert bottom face
const boost::shared_ptr<GeomAPI_Shape>& aBottomFace = theFeature.firstShape();
- if (!aBottomFace->impl<TopoDS_Shape>().IsNull()) {
- if (aSubShapes.IsBound(aBottomFace->impl<TopoDS_Shape>())) {
- aBottomFace->setImpl((void *)&aSubShapes(aBottomFace->impl<TopoDS_Shape>()));
- }
- theResultBody->generated(aBottomFace, _FIRST_TAG);
+ if (!aBottomFace->isNull()) {
+ if (aSubShapes.IsBound(aBottomFace->impl<TopoDS_Shape>())) {
+ aBottomFace->setImpl((void *)&aSubShapes(aBottomFace->impl<TopoDS_Shape>()));
+ }
+ theResultBody->generated(aBottomFace, _FIRST_TAG);
}
-
- //Insert top face
+
+ //Insert top face
boost::shared_ptr<GeomAPI_Shape> aTopFace = theFeature.lastShape();
- if (!aTopFace->impl<TopoDS_Shape>().IsNull()) {
- if (aSubShapes.IsBound(aTopFace->impl<TopoDS_Shape>())) {
- aTopFace->setImpl((void *)&aSubShapes(aTopFace->impl<TopoDS_Shape>()));
- }
+ if (!aTopFace->isNull()) {
+ if (aSubShapes.IsBound(aTopFace->impl<TopoDS_Shape>())) {
+ aTopFace->setImpl((void *)&aSubShapes(aTopFace->impl<TopoDS_Shape>()));
+ }
theResultBody->generated(aTopFace, _FIRST_TAG);
}
+ */
}
icon=":icons/cut_shape.png"
tooltip="Select an object to cut"
shape_types="solid shell"
+ concealment="true"
/>
<shape_selector id="tool_object"
label="Tool object"
icon=":icons/cut_tool.png"
tooltip="Select a tool"
shape_types="solid"
+ concealment="true"
/>
<choice id="bool_type"
label="Type"
activate="true"
shape_types="face"
use_subshapes="true"
- concealment="true"
/>
<doublevalue id="extrusion_size" label="Size" min="0" step="1.0" default="1" icon=":icons/dimension_v.png" tooltip="Set size of extrusion">
<validator id="GeomValidators_Positive"/>
};
//! Pointer on list of shapes
-typedef std::list<boost::shared_ptr<GeomAPI_Shape>> ListOfShape;
+typedef std::list<boost::shared_ptr<GeomAPI_Shape> > ListOfShape;
//! Pointer on attribute object
typedef boost::shared_ptr<GeomAPI_Shape> GeomShapePtr;
#include <Precision.hxx>
#include <TDF_TagSource.hxx>
#include <boost/shared_ptr.hpp>
+#include <BRepPrimAPI_MakePrism.hxx>
+#include <TopoDS_Shape.hxx>
const double tolerance = Precision::Angular();
- // Constructor
-GeomAlgoAPI_Extrusion::GeomAlgoAPI_Extrusion (boost::shared_ptr<GeomAPI_Shape> theBasis, double theSize)
- : mySize(theSize), myBuilder(NULL), myDone(false), myShape(new GeomAPI_Shape())
- {
- myBasis = theBasis->impl<TopoDS_Shape>();
- build();
- }
-
- //============================================================================
- void GeomAlgoAPI_Extrusion::build()
- {
- bool isFirstNorm = true;
- gp_Dir aShapeNormal;
-
- //const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
- 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<GeomAPI_Shape> 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<GeomAPI_Shape>& theBasis)
+{
+ bool isFirstNorm = true;
+ gp_Dir aShapeNormal;
+
+ //const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
+ TopoDS_Face aBasis = TopoDS::Face(theBasis->impl<TopoDS_Shape>());
+ 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<TopoDS_Shape>();
+ GProp_GProps aGProp;
+ BRepGProp::VolumeProperties(aRShape, aGProp);
+ if(aGProp.Mass() > Precision::Confusion())
+ hasVolume = true;
}
+ return hasVolume;
+}
- //============================================================================
+//============================================================================
const boost::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::shape () const
{return myShape;}
- //============================================================================
- const ListOfShape& GeomAlgoAPI_Extrusion::generated(const boost::shared_ptr<GeomAPI_Shape> theShape)
- {
- myHistory.clear();
- if(myDone) {
- const TopTools_ListOfShape& aList = myBuilder->Generated(theShape->impl<TopoDS_Shape>());
+//============================================================================
+void GeomAlgoAPI_Extrusion::generated(
+ const boost::shared_ptr<GeomAPI_Shape> theShape, ListOfShape& theHistory)
+{
+ theHistory.clear();
+ if(myDone) {
+ const TopTools_ListOfShape& aList = implPtr<BRepPrimAPI_MakePrism>()
+ ->Generated(theShape->impl<TopoDS_Shape>());
TopTools_ListIteratorOfListOfShape it(aList);
- for(;it.More();it.Next()) {
- boost::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
- aShape->setImpl(&(it.Value()));
- myHistory.push_back(aShape);
- }
- }
- return myHistory;
+ for(;it.More();it.Next()) {
+ boost::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
+ aShape->setImpl(&(it.Value()));
+ theHistory.push_back(aShape);
+ }
}
-
- //============================================================================
- const boost::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::firstShape()
- {
- return myFirst;
- }
-
- //============================================================================
- const boost::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::lastShape()
- {
- return myLast;
- }
-
- //============================================================================
- /*
- void GeomAlgoAPI_Extrusion::LoadNamingDS(boost::shared_ptr<ModelAPI_ResultBody> theResultBody,
- boost::shared_ptr<GeomAPI_Shape> theContext)
+}
+
+//============================================================================
+const boost::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::firstShape()
{
- if(isValid()) {
- const TopoDS_Shape& aShape = myBuilder->Shape();
- TopoDS_Shape aResult = GeomAlgoAPI_DFLoader::refineResult(aShape);
- boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(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<TopoDS_Shape>()))
- aBuilder.Generated(aResult);
- else
- aBuilder.Generated(theContext->impl<TopoDS_Shape>(), 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<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::lastShape()
+{
+ return myLast;
+}
+
+//============================================================================
+/*
+void GeomAlgoAPI_Extrusion::LoadNamingDS(boost::shared_ptr<ModelAPI_ResultBody> theResultBody,
+boost::shared_ptr<GeomAPI_Shape> theContext)
+{
+if(isValid()) {
+const TopoDS_Shape& aShape = myBuilder->Shape();
+TopoDS_Shape aResult = GeomAlgoAPI_DFLoader::refineResult(aShape);
+boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(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<TopoDS_Shape>()))
+aBuilder.Generated(aResult);
+else
+aBuilder.Generated(theContext->impl<TopoDS_Shape>(), 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
#include <GeomAPI_Dir.h>
#include <ModelAPI_ResultBody.h>
#include <boost/shared_ptr.hpp>
-#include <BRepPrimAPI_MakePrism.hxx>
-#include <TopoDS_Shape.hxx>
/**\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:
boost::shared_ptr<GeomAPI_Shape> theContext,
double theSize); */
/// Constructor
- GeomAlgoAPI_Extrusion (boost::shared_ptr<GeomAPI_Shape> theBasis, double theSize);
+ GEOMALGOAPI_EXPORT GeomAlgoAPI_Extrusion (boost::shared_ptr<GeomAPI_Shape> 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<GeomAPI_Shape>& shape () const;
+ GEOMALGOAPI_EXPORT const boost::shared_ptr<GeomAPI_Shape>& shape () const;
/// Returns list of shapes generated from theShape
- const ListOfShape& generated(const boost::shared_ptr<GeomAPI_Shape> theShape);
+ GEOMALGOAPI_EXPORT void generated(const boost::shared_ptr<GeomAPI_Shape> theShape,
+ ListOfShape& theHistory);
/// Returns the first shape
- const boost::shared_ptr<GeomAPI_Shape>& firstShape();
+ GEOMALGOAPI_EXPORT const boost::shared_ptr<GeomAPI_Shape>& firstShape();
/// returns last shape
- const boost::shared_ptr<GeomAPI_Shape>& lastShape();
+ GEOMALGOAPI_EXPORT const boost::shared_ptr<GeomAPI_Shape>& lastShape();
private:
/// builds resulting shape
- void build();
+ void build(const boost::shared_ptr<GeomAPI_Shape>& theBasis);
- BRepPrimAPI_MakePrism * myBuilder;
- TopoDS_Shape myBasis;
double mySize;
bool myDone;
- TopoDS_Shape myResult;
- ListOfShape myHistory;
boost::shared_ptr<GeomAPI_Shape> myShape;
boost::shared_ptr<GeomAPI_Shape> myFirst;
boost::shared_ptr<GeomAPI_Shape> myLast;
#include <GeomAlgoAPI_MakeShape.h>
#include <TopTools_ListOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
-GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape(BRepBuilderAPI_MakeShape * theMkShape)
-{ myBuilder = theMkShape;}
+GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape(void* theMkShape)
+ : GeomAPI_Interface(theMkShape)
+{}
-const boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_MakeShape::shape() const
+const boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_MakeShape::shape() const
{
- boost::shared_ptr<GeomAPI_Shape> 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 <theShape>
-const ListOfShape& GeomAlgoAPI_MakeShape::generated(const boost::shared_ptr<GeomAPI_Shape> theShape)
+/// Returns the list of shapes generated from the shape <theShape>
+void GeomAlgoAPI_MakeShape::generated(
+ const boost::shared_ptr<GeomAPI_Shape> theShape, ListOfShape& theHistory)
{
- myHistory.clear();
- if(myBuilder != NULL) {
- const TopTools_ListOfShape& aList = myBuilder->Generated(theShape->impl<TopoDS_Shape>());
+ BRepBuilderAPI_MakeShape* aBuilder = implPtr<BRepBuilderAPI_MakeShape>();
+ if(aBuilder) {
+ const TopTools_ListOfShape& aList = aBuilder->Generated(theShape->impl<TopoDS_Shape>());
TopTools_ListIteratorOfListOfShape it(aList);
- for(;it.More();it.Next()) {
- boost::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
- aShape->setImpl(&(it.Value()));
- myHistory.push_back(aShape);
- }
+ for(;it.More();it.Next()) {
+ boost::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
+ aShape->setImpl(&(it.Value()));
+ theHistory.push_back(aShape);
+ }
}
- return myHistory;
}
- /// Returns the list of shapes modified from the shape <theShape>
-const ListOfShape& GeomAlgoAPI_MakeShape::modified(const boost::shared_ptr<GeomAPI_Shape> theShape)
+/// Returns the list of shapes modified from the shape <theShape>
+void GeomAlgoAPI_MakeShape::modified(
+ const boost::shared_ptr<GeomAPI_Shape> theShape, ListOfShape& theHistory)
{
- myHistory.clear();
- if(myBuilder != NULL) {
- const TopTools_ListOfShape& aList = myBuilder->Modified(theShape->impl<TopoDS_Shape>());
- TopTools_ListIteratorOfListOfShape it(aList);
- for(;it.More();it.Next()) {
- boost::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
- aShape->setImpl(&(it.Value()));
- myHistory.push_back(aShape);
- }
+ BRepBuilderAPI_MakeShape* aBuilder = implPtr<BRepBuilderAPI_MakeShape>();
+ if(aBuilder) {
+ const TopTools_ListOfShape& aList = aBuilder->Modified(theShape->impl<TopoDS_Shape>());
+ TopTools_ListIteratorOfListOfShape it(aList);
+ for(;it.More();it.Next()) {
+ boost::shared_ptr<GeomAPI_Shape> 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<GeomAPI_Shape> theShape)
{
bool isDeleted(false);
- if (myBuilder != NULL)
- isDeleted = (bool) myBuilder->IsDeleted(theShape->impl<TopoDS_Shape>());
+ BRepBuilderAPI_MakeShape* aBuilder = implPtr<BRepBuilderAPI_MakeShape>();
+ if(aBuilder) {
+ isDeleted = aBuilder->IsDeleted(theShape->impl<TopoDS_Shape>()) == Standard_True;
+ }
return isDeleted;
-}
\ No newline at end of file
+}
* \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<GeomAPI_Shape> shape() const;
+ GEOMALGOAPI_EXPORT const boost::shared_ptr<GeomAPI_Shape> shape() const;
/// Returns the list of shapes generated from the shape <theShape>
- virtual const ListOfShape& generated(const boost::shared_ptr<GeomAPI_Shape> theShape);
+ GEOMALGOAPI_EXPORT virtual void generated(
+ const boost::shared_ptr<GeomAPI_Shape> theShape, ListOfShape& theHistory);
/// Returns the list of shapes modified from the shape <theShape>
- virtual const ListOfShape& modified(const boost::shared_ptr<GeomAPI_Shape> theShape);
+ GEOMALGOAPI_EXPORT virtual void modified(
+ const boost::shared_ptr<GeomAPI_Shape> theShape, ListOfShape& theHistory);
/// Returns whether the shape is an edge
- virtual bool isDeleted(const boost::shared_ptr<GeomAPI_Shape> theShape);
+ GEOMALGOAPI_EXPORT virtual bool isDeleted(const boost::shared_ptr<GeomAPI_Shape> theShape);
protected:
boost::shared_ptr<GeomAPI_Shape> myShape;
- ListOfShape myHistory;
- BRepBuilderAPI_MakeShape * myBuilder;
};
-#endif
\ No newline at end of file
+#endif
}
}
}
- if (aNewSelected) { // store this new selection
- selectConstruction(aContext, aNewSelected);
- return true;
- }
+ }
+ if (aNewSelected) { // store this new selection
+ selectConstruction(aContext, aNewSelected);
+ return true;
}
}
}
#include <Model_Events.h>
#include <ModelAPI_Feature.h>
#include <ModelAPI_Result.h>
+#include <ModelAPI_Validator.h>
#include <GeomData_Point.h>
#include <GeomData_Point2D.h>
return myLab.Father().Tag(); // tag of the feature label
}
+void Model_Data::eraseBackReferences()
+{
+ myRefsToMe.clear();
+ boost::shared_ptr<ModelAPI_Result> aRes =
+ boost::dynamic_pointer_cast<ModelAPI_Result>(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<ModelAPI_Result> aRes =
+ boost::dynamic_pointer_cast<ModelAPI_Result>(myObject);
+ if (aRes) {
+ aRes->setIsConcealed(true);
+ }
+ }
}
void Model_Data::referencesToObjects(
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
myIsEmptyTr[myTransactionsAfterSave] = !myDoc->CommitCommand(); // && (myNestedNum == -1);
myTransactionsAfterSave++;
}
-
}
void Model_Document::abortOperation()
void Model_Document::synchronizeBackRefs()
{
+ boost::shared_ptr<ModelAPI_Document> aThis =
+ Model_Application::getApplication()->getDocument(myID);
+ // keeps the concealed flags of result to catch the change and create created/deleted events
+ std::list<std::pair<ResultPtr, bool> > aConcealed;
// first cycle: erase all data about back-references
NCollection_DataMap<TDF_Label, FeaturePtr>::Iterator aFeatures(myObjs);
for(; aFeatures.More(); aFeatures.Next()) {
boost::shared_ptr<Model_Data> aResData =
boost::dynamic_pointer_cast<Model_Data>((*aRIter)->data());
if (aResData) {
+ aConcealed.push_back(std::pair<ResultPtr, bool>(*aRIter, (*aRIter)->isConcealed()));
aResData->eraseBackReferences();
}
}
}
}
}
+ std::list<std::pair<ResultPtr, bool> >::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(
void Model_ValidatorsFactory::registerConcealment(std::string theFeature, std::string theAttribute)
{
-
+ std::map<std::string, std::set<std::string> >::iterator aFind = myConcealed.find(theFeature);
+ if (aFind == myConcealed.end()) {
+ std::set<std::string> aNewSet;
+ aNewSet.insert(theAttribute);
+ myConcealed[theFeature] = aNewSet;
+ } else {
+ aFind->second.insert(theAttribute);
+ }
}
-
+bool Model_ValidatorsFactory::isConcealed(std::string theFeature, std::string theAttribute)
+{
+ std::map<std::string, std::set<std::string> >::iterator aFind = myConcealed.find(theFeature);
+ return aFind != myConcealed.end() && aFind->second.find(theAttribute) != aFind->second.end();
+}
std::map<std::string, AttrValidators> myFeatures;
/// validators IDs and arguments by feature and attribute IDs
std::map<std::string, std::map<std::string, AttrValidators> > 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<std::string, std::set<std::string> > myConcealed;
+
public:
/// Registers the instance of the validator by the ID
MODEL_EXPORT virtual void registerValidator(const std::string& theID,
/// 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<ModelAPI_Validator*>& theValidators) const;
/// Get instance from Session
/// 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()