bool Config_FeatureReader::isInternalFeature(xmlNodePtr theNode)
{
- std::string prop = getProperty(theNode, FEATURE_INTERNAL);
+ std::string prop = getProperty(theNode, ATTRIBUTE_INTERNAL);
std::transform(prop.begin(), prop.end(), prop.begin(), ::tolower);
if (prop.empty() || prop == "false" || prop == "0") {
return false;
const static char* FEATURE_TEXT = "title";
const static char* FEATURE_KEYSEQUENCE = "keysequence";
const static char* FEATURE_NESTED = "nested";
-const static char* FEATURE_INTERNAL = "internal";
-const static char* FEATURE_OBLIGATORY = "obligatory";
+
+const static char* ATTRIBUTE_INTERNAL = "internal";
+const static char* ATTRIBUTE_OBLIGATORY = "obligatory";
+const static char* ATTRIBUTE_CONCEALMENT = "concealment";
// TODO: Rename
const static char* PREVIOUS_FEATURE_PARAM = "previous_feature_param";
const static char* ANY_WDG_TOOLTIP = FEATURE_TOOLTIP;
EXCHANGEPLUGIN_EXPORT virtual bool isInHistory()
{
- return false;
+ return true;
}
protected:
../ModelAPI
../GeomAPI
../GeomAlgoAPI
+ ../Events
)
SET(PROJECT_LIBRARIES
+ Events
ModelAPI
GeomAPI
GeomAlgoAPI
- ${CAS_KERNEL}
- ${CAS_SHAPE}
)
ADD_DEFINITIONS(-DFEATURESPLUGIN_EXPORTS ${BOOST_DEFINITIONS})
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeSelection.h>
#include <ModelAPI_AttributeBoolean.h>
-
+#include <Events_Error.h>
#include <GeomAlgoAPI_Extrusion.h>
using namespace std;
+#define _LATERAL_TAG 1
+#define _FIRST_TAG 2
+#define _LAST_TAG 3
+#ifdef _DEBUG
+#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;
+
boost::shared_ptr<GeomAPI_Shape> aFace =
boost::dynamic_pointer_cast<GeomAPI_Shape>(aFaceRef->value());
if (!aFace)
return;
+ 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())
aSize = -aSize;
- boost::shared_ptr<ModelAPI_ResultBody> aResult = document()->createBody(data());
- aResult->store(GeomAlgoAPI_Extrusion::makeExtrusion(aFace, aSize));
- setResult(aResult);
+ boost::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
+ //TCollection_AsciiString anError;
+ GeomAlgoAPI_Extrusion aFeature(aFace, aSize);
+ if(!aFeature.isDone()) {
+ std::string aFeatureError = "Extrusion algorithm failed";
+ Events_Error::send(aFeatureError, this);
+ return;
+ }
+
+ // Check if shape is valid
+ if (aFeature.shape()->isNull()) {
+ std::string aShapeError = "Resulting shape is Null";
+ Events_Error::send(aShapeError, this);
+#ifdef _DEBUG
+ std::cerr << aShapeError << std::endl;
+#endif
+ return;
+ }
+ if(!aFeature.isValid()) {
+ std::string aFeatureError = "Warning: resulting shape is not valid";
+ Events_Error::send(aFeatureError, this);
+ 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)
+{
+
+
+ //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);
+
+
+ TopTools_MapOfShape aView;
+ TopExp_Explorer aShapeExplorer (theFeature.shape()->impl<TopoDS_Shape>(), TopAbs_EDGE);
+ 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++) {
+ 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);
+ }
+ }
+ }
+ //Insert bottom face
+ const boost::shared_ptr<GeomAPI_Shape>& aBottomFace = theFeature.firstShape();
+ 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
+ boost::shared_ptr<GeomAPI_Shape> aTopFace = theFeature.lastShape();
+ if (!aTopFace->isNull()) {
+ if (aSubShapes.IsBound(aTopFace->impl<TopoDS_Shape>())) {
+ aTopFace->setImpl((void *)&aSubShapes(aTopFace->impl<TopoDS_Shape>()));
+ }
+ theResultBody->generated(aTopFace, _FIRST_TAG);
+ }
+ */
+
}
#include "FeaturesPlugin.h"
#include <ModelAPI_Feature.h>
-
+#include <ModelAPI_ResultBody.h>
+#include <GeomAlgoAPI_Extrusion.h>
class FeaturesPlugin_Extrusion : public ModelAPI_Feature
{
public:
/// Use plugin manager for features creation
FeaturesPlugin_Extrusion();
+
+ /// Load Naming data structure of the feature to the document
+ void LoadNamingDS(GeomAlgoAPI_Extrusion& theFeature, boost::shared_ptr<ModelAPI_ResultBody> theResultBody,
+ boost::shared_ptr<GeomAPI_Shape> theBasis,
+ boost::shared_ptr<GeomAPI_Shape> theContext);
};
#endif
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"
GeomAPI_Pln.h
GeomAPI_Shape.h
GeomAPI_Edge.h
- GeomAPI_Wire.h
+ GeomAPI_PlanarEdges.h
GeomAPI_AISObject.h
GeomAPI_IPresentable.h
GeomAPI_Curve.h
GeomAPI_Pln.cpp
GeomAPI_Shape.cpp
GeomAPI_Edge.cpp
- GeomAPI_Wire.cpp
+ GeomAPI_PlanarEdges.cpp
GeomAPI_AISObject.cpp
GeomAPI_Curve.cpp
)
--- /dev/null
+// File: GeomAPI_PlanarEdges.cpp
+// Created: 06 Oct 2014
+// Author: Sergey BELASH
+
+#include <GeomAPI_Interface.h>
+#include <GeomAPI_PlanarEdges.h>
+
+#include <Standard_TypeDef.hxx>
+#include <TopAbs_ShapeEnum.hxx>
+
+#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Wire.hxx>
+#include <BRep_Builder.hxx>
+#include <BRepTools_WireExplorer.hxx>
+#include <TopExp_Explorer.hxx>
+
+#include <list>
+
+GeomAPI_PlanarEdges::GeomAPI_PlanarEdges() : GeomAPI_Shape()
+{
+ TopoDS_Compound aBigWireImpl;
+ BRep_Builder aBuilder;
+ aBuilder.MakeCompound(aBigWireImpl);
+ this->setImpl(new TopoDS_Shape(aBigWireImpl));
+}
+
+void GeomAPI_PlanarEdges::addEdge(boost::shared_ptr<GeomAPI_Shape> theEdge)
+{
+ const TopoDS_Edge& anEdge = theEdge->impl<TopoDS_Edge>();
+ if (anEdge.ShapeType() != TopAbs_EDGE)
+ return;
+ TopoDS_Shape& aWire = const_cast<TopoDS_Shape&>(impl<TopoDS_Shape>());
+ BRep_Builder aBuilder;
+ aBuilder.Add(aWire, anEdge);
+}
+
+std::list<boost::shared_ptr<GeomAPI_Shape> > GeomAPI_PlanarEdges::getEdges()
+{
+ TopoDS_Shape& aShape = const_cast<TopoDS_Shape&>(impl<TopoDS_Shape>());
+ //BRepTools_WireExplorer aWireExp(TopoDS::Wire(aShape));
+ TopExp_Explorer aWireExp(aShape, TopAbs_EDGE);
+ std::list<boost::shared_ptr<GeomAPI_Shape> > aResult;
+ for (; aWireExp.More(); aWireExp.Next()) {
+ boost::shared_ptr<GeomAPI_Shape> anEdge(new GeomAPI_Shape);
+ anEdge->setImpl(new TopoDS_Shape(aWireExp.Current()));
+ aResult.push_back(anEdge);
+ }
+ return aResult;
+}
--- /dev/null
+// File: GeomAPI_PlanarEdges.hxx
+// Created: 24 Jul 2014
+// Author: Artem ZHIDKOV
+
+#ifndef GEOMAPI_WIRE_H_
+#define GEOMAPI_WIRE_H_
+
+#include "GeomAPI.h"
+#include "GeomAPI_Edge.h"
+#include "GeomAPI_Pnt.h"
+#include "GeomAPI_Dir.h"
+
+#include <boost/smart_ptr/shared_ptr.hpp>
+
+#include <list>
+
+/**\class GeomAPI_PlanarEdges
+ * \ingroup DataModel
+ * \brief Interface to the edge object
+ */
+
+class GeomAPI_PlanarEdges : public GeomAPI_Shape
+{
+ public:
+ /// Creation of empty (null) shape
+ GEOMAPI_EXPORT GeomAPI_PlanarEdges();
+
+ GEOMAPI_EXPORT virtual bool isVertex() const
+ {
+ return false;
+ }
+
+ /// Returns whether the shape is an edge
+ GEOMAPI_EXPORT virtual bool isEdge() const
+ {
+ return false;
+ }
+
+ GEOMAPI_EXPORT void addEdge(boost::shared_ptr<GeomAPI_Shape> theEdge);
+ GEOMAPI_EXPORT std::list<boost::shared_ptr<GeomAPI_Shape> > getEdges();
+
+ /// Returns True if the wire is defined in a plane
+ GEOMAPI_EXPORT bool hasPlane() const { return myOrigin && myNorm && myDirX && myDirY; }
+
+ /// Set/Get origin point
+ GEOMAPI_EXPORT void setOrigin(const boost::shared_ptr<GeomAPI_Pnt>& theOrigin)
+ { myOrigin = theOrigin; }
+ GEOMAPI_EXPORT boost::shared_ptr<GeomAPI_Pnt> origin() const { return myOrigin; }
+
+ /// Set/Get X direction vector
+ GEOMAPI_EXPORT void setDirX(const boost::shared_ptr<GeomAPI_Dir>& theDirX) { myDirX = theDirX; }
+ GEOMAPI_EXPORT boost::shared_ptr<GeomAPI_Dir> dirX() const { return myDirX; }
+
+ /// Set/Get Y direction vector
+ GEOMAPI_EXPORT void setDirY(const boost::shared_ptr<GeomAPI_Dir>& theDirY) { myDirY = theDirY; }
+ GEOMAPI_EXPORT boost::shared_ptr<GeomAPI_Dir> dirY() const { return myDirY; }
+
+ /// Set/Get Normal direction vector
+ GEOMAPI_EXPORT void setNorm(const boost::shared_ptr<GeomAPI_Dir>& theNorm) { myNorm = theNorm; }
+ GEOMAPI_EXPORT boost::shared_ptr<GeomAPI_Dir> norm() const { return myNorm; }
+
+private:
+ boost::shared_ptr<GeomAPI_Pnt> myOrigin;
+ boost::shared_ptr<GeomAPI_Dir> myDirX;
+ boost::shared_ptr<GeomAPI_Dir> myDirY;
+ boost::shared_ptr<GeomAPI_Dir> myNorm;
+};
+
+#endif
+
#include <GeomAPI_Interface.h>
#include <boost/shared_ptr.hpp>
+#include <list>
/**\class GeomAPI_Shape
* \ingroup DataModel
};
+//! Pointer on list of shapes
+typedef std::list<boost::shared_ptr<GeomAPI_Shape> > ListOfShape;
+
//! Pointer on attribute object
typedef boost::shared_ptr<GeomAPI_Shape> GeomShapePtr;
+++ /dev/null
-// File: GeomAPI_Wire.cpp
-// Created: 06 Oct 2014
-// Author: Sergey BELASH
-
-#include <GeomAPI_Interface.h>
-#include <GeomAPI_Wire.h>
-
-#include <Standard_TypeDef.hxx>
-#include <TopAbs_ShapeEnum.hxx>
-
-#include <TopoDS.hxx>
-#include <TopoDS_Edge.hxx>
-#include <TopoDS_Wire.hxx>
-#include <BRep_Builder.hxx>
-#include <BRepTools_WireExplorer.hxx>
-#include <TopExp_Explorer.hxx>
-
-#include <list>
-
-GeomAPI_Wire::GeomAPI_Wire() : GeomAPI_Shape()
-{
- TopoDS_Compound aBigWireImpl;
- BRep_Builder aBuilder;
- aBuilder.MakeCompound(aBigWireImpl);
- this->setImpl(new TopoDS_Shape(aBigWireImpl));
-}
-
-void GeomAPI_Wire::addEdge(boost::shared_ptr<GeomAPI_Shape> theEdge)
-{
- const TopoDS_Edge& anEdge = theEdge->impl<TopoDS_Edge>();
- if (anEdge.ShapeType() != TopAbs_EDGE)
- return;
- TopoDS_Shape& aWire = const_cast<TopoDS_Shape&>(impl<TopoDS_Shape>());
- BRep_Builder aBuilder;
- aBuilder.Add(aWire, anEdge);
-}
-
-std::list<boost::shared_ptr<GeomAPI_Shape> > GeomAPI_Wire::getEdges()
-{
- TopoDS_Shape& aShape = const_cast<TopoDS_Shape&>(impl<TopoDS_Shape>());
- //BRepTools_WireExplorer aWireExp(TopoDS::Wire(aShape));
- TopExp_Explorer aWireExp(aShape, TopAbs_EDGE);
- std::list<boost::shared_ptr<GeomAPI_Shape> > aResult;
- for (; aWireExp.More(); aWireExp.Next()) {
- boost::shared_ptr<GeomAPI_Shape> anEdge(new GeomAPI_Shape);
- anEdge->setImpl(new TopoDS_Shape(aWireExp.Current()));
- aResult.push_back(anEdge);
- }
- return aResult;
-}
+++ /dev/null
-// File: GeomAPI_Wire.hxx
-// Created: 24 Jul 2014
-// Author: Artem ZHIDKOV
-
-#ifndef GEOMAPI_WIRE_H_
-#define GEOMAPI_WIRE_H_
-
-#include "GeomAPI.h"
-#include "GeomAPI_Edge.h"
-#include "GeomAPI_Pnt.h"
-#include "GeomAPI_Dir.h"
-
-#include <boost/smart_ptr/shared_ptr.hpp>
-
-#include <list>
-
-/**\class GeomAPI_Wire
- * \ingroup DataModel
- * \brief Interface to the edge object
- */
-
-class GeomAPI_Wire : public GeomAPI_Shape
-{
- public:
- /// Creation of empty (null) shape
- GEOMAPI_EXPORT GeomAPI_Wire();
-
- GEOMAPI_EXPORT virtual bool isVertex() const
- {
- return false;
- }
-
- /// Returns whether the shape is an edge
- GEOMAPI_EXPORT virtual bool isEdge() const
- {
- return false;
- }
-
- GEOMAPI_EXPORT void addEdge(boost::shared_ptr<GeomAPI_Shape> theEdge);
- GEOMAPI_EXPORT std::list<boost::shared_ptr<GeomAPI_Shape> > getEdges();
-
- /// Returns True if the wire is defined in a plane
- GEOMAPI_EXPORT bool hasPlane() const { return myOrigin && myNorm && myDirX && myDirY; }
-
- /// Set/Get origin point
- GEOMAPI_EXPORT void setOrigin(const boost::shared_ptr<GeomAPI_Pnt>& theOrigin)
- { myOrigin = theOrigin; }
- GEOMAPI_EXPORT boost::shared_ptr<GeomAPI_Pnt> origin() const { return myOrigin; }
-
- /// Set/Get X direction vector
- GEOMAPI_EXPORT void setDirX(const boost::shared_ptr<GeomAPI_Dir>& theDirX) { myDirX = theDirX; }
- GEOMAPI_EXPORT boost::shared_ptr<GeomAPI_Dir> dirX() const { return myDirX; }
-
- /// Set/Get Y direction vector
- GEOMAPI_EXPORT void setDirY(const boost::shared_ptr<GeomAPI_Dir>& theDirY) { myDirY = theDirY; }
- GEOMAPI_EXPORT boost::shared_ptr<GeomAPI_Dir> dirY() const { return myDirY; }
-
- /// Set/Get Normal direction vector
- GEOMAPI_EXPORT void setNorm(const boost::shared_ptr<GeomAPI_Dir>& theNorm) { myNorm = theNorm; }
- GEOMAPI_EXPORT boost::shared_ptr<GeomAPI_Dir> norm() const { return myNorm; }
-
-private:
- boost::shared_ptr<GeomAPI_Pnt> myOrigin;
- boost::shared_ptr<GeomAPI_Dir> myDirX;
- boost::shared_ptr<GeomAPI_Dir> myDirY;
- boost::shared_ptr<GeomAPI_Dir> myNorm;
-};
-
-#endif
-
GeomAlgoAPI_SketchBuilder.h
GeomAlgoAPI_Extrusion.h
GeomAlgoAPI_Boolean.h
+ GeomAlgoAPI_MakeShape.h
+ GeomAlgoAPI_DFLoader.h
)
SET(PROJECT_SOURCES
GeomAlgoAPI_SketchBuilder.cpp
GeomAlgoAPI_Extrusion.cpp
GeomAlgoAPI_Boolean.cpp
+ GeomAlgoAPI_MakeShape.cpp
+ GeomAlgoAPI_DFLoader.cpp
)
SET(PROJECT_LIBRARIES
- GeomAPI
+ GeomAPI
+ ModelAPI
${CAS_TKBool}
${CAS_TKBO}
${CAS_TKPrim}
${CAS_SHAPE}
+ ${CAS_TKTopAlgo}
)
ADD_DEFINITIONS(-DGEOMALGOAPI_EXPORTS ${CAS_DEFINITIONS})
INCLUDE_DIRECTORIES(
../GeomAPI
+ ../ModelAPI
${CAS_INCLUDE_DIRS}
)
--- /dev/null
+// File: GeomAlgoAPI_DFLoader.cpp
+// Created: 23 October 2014
+// Author: Sergey Zaritchny
+
+#include <GeomAlgoAPI_DFLoader.h>
+#include <TopoDS_Iterator.hxx>
+#include <TopTools_MapOfShape.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
+//=======================================================================
+//function : refineResult
+//purpose :
+//=======================================================================
+const TopoDS_Shape GeomAlgoAPI_DFLoader::refineResult(const TopoDS_Shape& theResult)
+{
+ TopoDS_Shape aResult;
+ if (theResult.ShapeType() == TopAbs_COMPOUND) {
+ Standard_Integer nbSubResults = 0;
+ TopoDS_Iterator itr(theResult);
+ for (; itr.More(); itr.Next()) nbSubResults++;
+ if (nbSubResults == 1) {
+ itr.Initialize(theResult);
+ if (itr.More()) aResult = itr.Value();
+ }
+ }
+ return aResult;
+}
+/*
+//=======================================================================
+//function : loadDeletedShapes
+//purpose : load deleted shapes in DF
+//=======================================================================
+void GeomAlgoAPI_DFLoader::loadDeletedShapes (BRepBuilderAPI_MakeShape& theMS,
+ const TopoDS_Shape& theShapeIn,
+ const TopAbs_ShapeEnum theKindOfShape,
+ TNaming_Builder& theBuilder)
+{
+ TopTools_MapOfShape aView;
+ TopExp_Explorer ShapeExplorer (theShapeIn, theKindOfShape);
+ for (; ShapeExplorer.More(); ShapeExplorer.Next ()) {
+ const TopoDS_Shape& aRoot = ShapeExplorer.Current ();
+ if (!aView.Add(aRoot)) continue;
+ if (theMS.IsDeleted (aRoot)) {
+ theBuilder.Delete (aRoot);
+ }
+ }
+}
+
+//=======================================================================
+//function : loadAndOrientModifiedShapes
+//purpose : load modified shapes in DF with preliminary orientation adjustment
+//=======================================================================
+void GeomAlgoAPI_DFLoader::loadAndOrientModifiedShapes (BRepBuilderAPI_MakeShape& theMS,
+ const TopoDS_Shape& theShapeIn,
+ const TopAbs_ShapeEnum theKindOfShape,
+ TNaming_Builder& theBuilder,
+ const TopTools_DataMapOfShapeShape& theSubShapes)
+{
+ TopTools_MapOfShape aView;
+ TopExp_Explorer aShapeExplorer (theShapeIn, theKindOfShape);
+ for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
+ const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
+ if (!aView.Add(aRoot)) continue;
+ const TopTools_ListOfShape& aShapes = theMS.Modified (aRoot);
+ TopTools_ListIteratorOfListOfShape aShapesIterator (aShapes);
+ for (;aShapesIterator.More (); aShapesIterator.Next ()) {
+ TopoDS_Shape aNewShape = aShapesIterator.Value ();
+ if (theSubShapes.IsBound(aNewShape)) {
+ aNewShape.Orientation((theSubShapes(aNewShape)).Orientation());
+ }
+ if (!aRoot.IsSame (aNewShape)) theBuilder.Modify (aRoot, aNewShape );
+ }
+ }
+}
+
+//=======================================================================
+//function : loadAndOrientGeneratedShapes
+//purpose : load generated shapes in DF with preliminary orientation adjustment
+//=======================================================================
+
+void GeomAlgoAPI_DFLoader::loadAndOrientGeneratedShapes (BRepBuilderAPI_MakeShape& theMS,
+ const TopoDS_Shape& theShapeIn,
+ const TopAbs_ShapeEnum theKindOfShape,
+ TNaming_Builder& theBuilder,
+ const TopTools_DataMapOfShapeShape& theSubShapes)
+{
+ TopTools_MapOfShape aView;
+ TopExp_Explorer aShapeExplorer (theShapeIn, theKindOfShape);
+ for (; aShapeExplorer.More(); aShapeExplorer.Next ()) {
+ const TopoDS_Shape& aRoot = aShapeExplorer.Current ();
+ if (!aView.Add(aRoot)) continue;
+ const TopTools_ListOfShape& aShapes = theMS.Generated (aRoot);
+ TopTools_ListIteratorOfListOfShape aShapesIterator (aShapes);
+ for (;aShapesIterator.More (); aShapesIterator.Next ()) {
+ TopoDS_Shape aNewShape = aShapesIterator.Value ();
+ if (theSubShapes.IsBound(aNewShape)) {
+ aNewShape.Orientation((theSubShapes(aNewShape)).Orientation());
+ }
+ if (!aRoot.IsSame (aNewShape)) theBuilder.Generated (aRoot,aNewShape );
+ }
+ }
+}
+*/
\ No newline at end of file
--- /dev/null
+// File: GeomAlgoAPI_DFLoader.h
+// Created: 23 October 2014
+// Author: Sergey Zaritchny
+
+#ifndef GeomAlgoAPI_DFLoader_H_
+#define GeomAlgoAPI_DFLoader_H_
+#include <GeomAlgoAPI.h>
+//#include <boost/shared_ptr.hpp>
+#include <BRepBuilderAPI_MakeShape.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TNaming_Builder.hxx>
+#include <TopAbs_ShapeEnum.hxx>
+#include <TopTools_DataMapOfShapeShape.hxx>
+
+/**\class GeomAlgoAPI_DFLoader
+ * \ingroup DataAlgo
+ * \brief Defines several static methods useful for Data Framework filling
+ */
+class GEOMALGOAPI_EXPORT GeomAlgoAPI_DFLoader
+{
+ public:
+ /*
+ /// Loads to DF deleted shapes
+ static void loadDeletedShapes (BRepBuilderAPI_MakeShape& theMS, const TopoDS_Shape& theShapeIn,
+ const TopAbs_ShapeEnum KindOfShape, TNaming_Builder& theBuilder);
+
+ /// Loads to DF generated shapes
+ static void loadAndOrientGeneratedShapes (BRepBuilderAPI_MakeShape& theMS,
+ const TopoDS_Shape& theShapeIn,
+ const TopAbs_ShapeEnum theKindOfShape,
+ TNaming_Builder& theBuilder,
+ const TopTools_DataMapOfShapeShape& theSubShapes);
+ /// Loads to DF modified shapes
+ static void loadAndOrientModifiedShapes (BRepBuilderAPI_MakeShape& theMS,
+ const TopoDS_Shape& theShapeIn,
+ const TopAbs_ShapeEnum theKindOfShape,
+ TNaming_Builder& theBuilder,
+ const TopTools_DataMapOfShapeShape& theSubShapes);
+ */
+ /// Refine result
+ static const TopoDS_Shape refineResult(const TopoDS_Shape& theShape);
+};
+
+#endif
\ No newline at end of file
// Author: Artem ZHIDKOV
#include <GeomAlgoAPI_Extrusion.h>
-
+#include <GeomAlgoAPI_MakeShape.h>
+#include <GeomAlgoAPI_DFLoader.h>
+#include <GeomAlgoAPI_DFLoader.h>
#include <gp_Pln.hxx>
-
#include <BRepPrimAPI_MakePrism.hxx>
+#include <BRepBuilderAPI_MakeShape.hxx>
#include <Geom_Plane.hxx>
#include <Geom_Surface.hxx>
#include <TopExp_Explorer.hxx>
-#include <BRep_Builder.hxx>
-
+#include <BRepCheck_Analyzer.hxx>
+#include <GProp_GProps.hxx>
+#include <BRepGProp.hxx>
+#include <TopoDS.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
#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), myDone(false),
+ myShape(new GeomAPI_Shape()), myFirst(new GeomAPI_Shape()), myLast(new GeomAPI_Shape())
+{
+ build(theBasis);
+}
-boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Extrusion::makeExtrusion(
- boost::shared_ptr<GeomAPI_Shape> theShape, boost::shared_ptr<GeomAPI_Dir> theDir,
- double theSize)
+//============================================================================
+void GeomAlgoAPI_Extrusion::build(const boost::shared_ptr<GeomAPI_Shape>& theBasis)
{
- const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
- gp_Vec aDir(theDir->impl<gp_Dir>().XYZ() * theSize);
+ bool isFirstNorm = true;
+ gp_Dir aShapeNormal;
- TopoDS_Shape aPrism = BRepPrimAPI_MakePrism(aShape, aDir);
- if (aPrism.IsNull())
- return boost::shared_ptr<GeomAPI_Shape>();
+ //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;
- boost::shared_ptr<GeomAPI_Shape> aResult(new GeomAPI_Shape());
- aResult->setImpl(new TopoDS_Shape(aPrism));
- return aResult;
+ 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()));
+ }
+ }
}
-boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Extrusion::makeExtrusion(
- boost::shared_ptr<GeomAPI_Shape> theShape, double theSize)
+//============================================================================
+const bool GeomAlgoAPI_Extrusion::isDone() const
+{return myDone;}
+
+//============================================================================
+const bool GeomAlgoAPI_Extrusion::isValid() const
{
- bool isFirstNorm = true;
- gp_Dir aShapeNormal;
+ return myDone;
+}
- const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
- TopExp_Explorer aFaceExp(aShape, TopAbs_FACE);
- TopoDS_Compound aFaces; // use only faces from the shape: make compound for this
- BRep_Builder aBuilder;
- aBuilder.MakeCompound(aFaces);
- for (; aFaceExp.More(); aFaceExp.Next()) {
- const TopoDS_Face& aFace = (const TopoDS_Face&) aFaceExp.Current();
- Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(aFace));
- if (aPlane.IsNull()) // non-planar shapes is not supported for extrusion yet
- continue;
-
- const gp_Dir& aNormal = aPlane->Pln().Axis().Direction();
- if (isFirstNorm) {
- aShapeNormal = aNormal;
- isFirstNorm = false;
- } else if (!aShapeNormal.IsEqual(aNormal, tolerance)) // non-planar shapes is not supported for extrusion yet
- return boost::shared_ptr<GeomAPI_Shape>();
- aBuilder.Add(aFaces, aFace);
+//============================================================================
+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;
}
- if (aFaces.IsNull())
- return boost::shared_ptr<GeomAPI_Shape>();
+ return hasVolume;
+}
- boost::shared_ptr<GeomAPI_Dir> aDir(
- new GeomAPI_Dir(aShapeNormal.X(), aShapeNormal.Y(), aShapeNormal.Z()));
+//============================================================================
+const boost::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Extrusion::shape () const
+{return myShape;}
- boost::shared_ptr<GeomAPI_Shape> aFacesShape(new (GeomAPI_Shape));
- aFacesShape->setImpl(new TopoDS_Shape(aFaces));
- return GeomAlgoAPI_Extrusion::makeExtrusion(aFacesShape, aDir, theSize);
+//============================================================================
+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()));
+ 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)
+{
+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
// File: GeomAlgoAPI_Extrusion.h
-// Created: 06 Jun 2014
-// Author: Artem ZHIDKOV
+// Created: 22 October 2014
+// Author: Sergey Zaritchny
#ifndef GeomAlgoAPI_Extrusion_H_
#define GeomAlgoAPI_Extrusion_H_
#include <GeomAlgoAPI.h>
#include <GeomAPI_Shape.h>
#include <GeomAPI_Dir.h>
+#include <ModelAPI_ResultBody.h>
#include <boost/shared_ptr.hpp>
-
/**\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:
- /* \brief Creates extrusion for the given shape
- * \param[in] theShape face or wire to be extruded
- * \param[in] theDir direction of extrusion
- * \param[in] theSize the length of extrusion (if the value is less than 0, the extrusion in opposite direction)
- * \return a solid or a face which is obtained from specified one
- */
- static boost::shared_ptr<GeomAPI_Shape> makeExtrusion(boost::shared_ptr<GeomAPI_Shape> theShape,
- boost::shared_ptr<GeomAPI_Dir> theDir,
- double theSize);
/* \brief Creates extrusion for the given shape along the normal for this shape
* \param[in] theShape face or wire to be extruded
* \param[in] theSize the length of extrusion (if the value is less than 0, the extrusion in opposite normal)
* \return a solid or a face which is obtained from specified one
- */
- static boost::shared_ptr<GeomAPI_Shape> makeExtrusion(boost::shared_ptr<GeomAPI_Shape> theShape,
- double theSize);
+
+ static boost::shared_ptr<GeomAPI_Shape> makeExtrusion(boost::shared_ptr<ModelAPI_ResultBody> theResult,
+ boost::shared_ptr<GeomAPI_Shape> theBasis,
+ boost::shared_ptr<GeomAPI_Shape> theContext,
+ double theSize); */
+ /// Constructor
+ GEOMALGOAPI_EXPORT GeomAlgoAPI_Extrusion (boost::shared_ptr<GeomAPI_Shape> theBasis, double theSize);
+
+ /// Returns True if algorithm succeed
+ GEOMALGOAPI_EXPORT const bool isDone() const;
+
+ /// Returns True if resulting shape is valid
+ GEOMALGOAPI_EXPORT const bool isValid() const;
+
+ /// Returns True if resulting shape has volume
+ GEOMALGOAPI_EXPORT const bool hasVolume() const;
+
+ /// Returns result of the Extrusion algorithm which may be a Solid or a Face
+ GEOMALGOAPI_EXPORT const boost::shared_ptr<GeomAPI_Shape>& shape () const;
+
+ /// Returns list of shapes generated from theShape
+ GEOMALGOAPI_EXPORT void generated(const boost::shared_ptr<GeomAPI_Shape> theShape,
+ ListOfShape& theHistory);
+
+ /// Returns the first shape
+ GEOMALGOAPI_EXPORT const boost::shared_ptr<GeomAPI_Shape>& firstShape();
+
+ /// returns last shape
+ GEOMALGOAPI_EXPORT const boost::shared_ptr<GeomAPI_Shape>& lastShape();
+
+private:
+ /// builds resulting shape
+ void build(const boost::shared_ptr<GeomAPI_Shape>& theBasis);
+
+ double mySize;
+ bool myDone;
+ boost::shared_ptr<GeomAPI_Shape> myShape;
+ boost::shared_ptr<GeomAPI_Shape> myFirst;
+ boost::shared_ptr<GeomAPI_Shape> myLast;
};
#endif
--- /dev/null
+// File: GeomAlgoAPI_MakeShape.cpp
+// Created: 20 Oct 2014
+// Author: Sergey ZARITCHNY
+
+#include <GeomAlgoAPI_MakeShape.h>
+#include <TopTools_ListOfShape.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
+GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape(void* theMkShape)
+ : GeomAPI_Interface(theMkShape)
+{}
+
+const boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_MakeShape::shape() const
+{
+ return myShape;
+}
+
+/// Returns the list of shapes generated from the shape <theShape>
+void GeomAlgoAPI_MakeShape::generated(
+ const boost::shared_ptr<GeomAPI_Shape> theShape, ListOfShape& theHistory)
+{
+ 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()));
+ theHistory.push_back(aShape);
+ }
+ }
+}
+
+/// Returns the list of shapes modified from the shape <theShape>
+void GeomAlgoAPI_MakeShape::modified(
+ const boost::shared_ptr<GeomAPI_Shape> theShape, ListOfShape& theHistory)
+{
+ 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);
+ }
+ }
+}
+
+/// Returns whether the shape is an edge
+bool GeomAlgoAPI_MakeShape::isDeleted(const boost::shared_ptr<GeomAPI_Shape> theShape)
+{
+ bool isDeleted(false);
+ BRepBuilderAPI_MakeShape* aBuilder = implPtr<BRepBuilderAPI_MakeShape>();
+ if(aBuilder) {
+ isDeleted = aBuilder->IsDeleted(theShape->impl<TopoDS_Shape>()) == Standard_True;
+ }
+ return isDeleted;
+}
--- /dev/null
+// File: GeomAlgoAPI_MakeShape.h
+// Created: 17 Oct 2014
+// Author: Sergey ZARITCHNY
+#ifndef GeomAlgoAPI_MakeShape_H_
+#define GeomAlgoAPI_MakeShape_H_
+
+#include <GeomAPI_Shape.h>
+#include <boost/shared_ptr.hpp>
+#include <GeomAlgoAPI.h>
+#include <BRepBuilderAPI_MakeShape.hxx>
+/**\class GeomAlgoAPI_MakeShape
+ * \ingroup DataModel
+ * \Interface to the root class of all topological shapes constructions
+ */
+class GeomAlgoAPI_MakeShape : GeomAPI_Interface
+{
+ public:
+ /// Constructor
+ GEOMALGOAPI_EXPORT GeomAlgoAPI_MakeShape(void* theBuilder);
+ /// Returns a shape built by the shape construction algorithm
+ GEOMALGOAPI_EXPORT const boost::shared_ptr<GeomAPI_Shape> shape() const;
+
+ /// Returns the list of shapes generated from the 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>
+ GEOMALGOAPI_EXPORT virtual void modified(
+ const boost::shared_ptr<GeomAPI_Shape> theShape, ListOfShape& theHistory);
+
+ /// Returns whether the shape is an edge
+ GEOMALGOAPI_EXPORT virtual bool isDeleted(const boost::shared_ptr<GeomAPI_Shape> theShape);
+
+ protected:
+ boost::shared_ptr<GeomAPI_Shape> myShape;
+};
+
+#endif
// Author: Artem ZHIDKOV
#include <GeomAlgoAPI_SketchBuilder.h>
-#include <GeomAPI_Wire.h>
+#include <GeomAPI_PlanarEdges.h>
#include <set>
const boost::shared_ptr<GeomAPI_Shape>& theWire,
std::list<boost::shared_ptr<GeomAPI_Shape> >& theResultFaces)
{
- boost::shared_ptr<GeomAPI_Wire> aWire = boost::dynamic_pointer_cast<GeomAPI_Wire>(theWire);
+ boost::shared_ptr<GeomAPI_PlanarEdges> aWire = boost::dynamic_pointer_cast<GeomAPI_PlanarEdges>(theWire);
if(!aWire)
return;
// Filter wires, return only faces.
boost::shared_ptr<Model_Document> aDoc =
boost::dynamic_pointer_cast<Model_Document>(owner()->document());
- if (aDoc) aDoc->objectIsNotReferenced(aDoc->object(myRef->Get()));
myRef->Set(aData->label().Father()); // references to the feature label
- boost::shared_dynamic_cast<Model_Document>(owner()->document())->objectIsReferenced(theObject);
owner()->data()->sendAttributeUpdated(this);
}
if (owner()) {
boost::shared_ptr<Model_Document> aDoc =
boost::dynamic_pointer_cast<Model_Document>(owner()->document());
- if (aDoc) aDoc->objectIsReferenced(aDoc->object(myRef->Get()));
}
}
}
ModelAPI_AttributeReference::setObject(theObject);
boost::shared_ptr<Model_Document> aDoc =
boost::dynamic_pointer_cast<Model_Document>(owner()->document());
- if (aDoc) aDoc->objectIsReferenced(aDoc->object(myRef->Get()));
}
}
boost::shared_ptr<Model_Document> aDoc =
boost::dynamic_pointer_cast<Model_Document>(owner()->document());
TDF_Label aLab = myRef->Get();
- if (aDoc && !aLab.IsNull()) aDoc->objectIsNotReferenced(aDoc->object(myRef->Get()));
}
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_CompositeFeature.h>
#include <GeomAPI_Shape.h>
-#include <GeomAPI_Wire.h>
+#include <GeomAPI_PlanarEdges.h>
#include <GeomAlgoAPI_SketchBuilder.h>
+#include <Events_Error.h>
#include <TNaming_Selector.hxx>
#include <TNaming_NamedShape.hxx>
boost::shared_ptr<GeomAPI_Shape> aResult;
if (myIsInitialized) {
Handle(TNaming_NamedShape) aSelection;
- if (myRef.myRef->Label().FindAttribute(TNaming_NamedShape::GetID(), aSelection)) {
+ if (selectionLabel().FindAttribute(TNaming_NamedShape::GetID(), aSelection)) {
TopoDS_Shape aSelShape = aSelection->Get();
aResult = boost::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape);
aResult->setImpl(new TopoDS_Shape(aSelShape));
if (!aContext) return false;
if (aContext->groupName() == ModelAPI_ResultBody::group()) {
// body: just a named shape, use selection mechanism from OCCT
- TNaming_Selector aSelector(myRef.myRef->Label());
+ TNaming_Selector aSelector(selectionLabel());
TDF_LabelMap aScope; // empty means the whole document
return aSelector.Solve(aScope) == Standard_True;
} else if (aContext->groupName() == ModelAPI_ResultConstruction::group()) {
// construction: identification by the results indexes, recompute faces and
// take the face that more close by the indexes
- boost::shared_ptr<GeomAPI_Wire> aWirePtr = boost::dynamic_pointer_cast<GeomAPI_Wire>(
+ boost::shared_ptr<GeomAPI_PlanarEdges> aWirePtr = boost::dynamic_pointer_cast<GeomAPI_PlanarEdges>(
boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext)->shape());
if (aWirePtr && aWirePtr->hasPlane()) {
// If this is a wire with plane defined thin it is a sketch-like object
for(; aRes != aResults.cend(); aRes++) {
ResultConstructionPtr aConstr =
boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aRes);
- if (aConstr->shape()) {
+ if (aConstr->shape() && aConstr->shape()->isEdge()) {
const TopoDS_Shape& aResShape = aConstr->shape()->impl<TopoDS_Shape>();
TopoDS_Edge anEdge = TopoDS::Edge(aResShape);
if (!anEdge.IsNull()) {
}
}
}
- if (aNewSelected) { // store this new selection
- selectConstruction(aContext, aNewSelected);
- return true;
- }
+ }
+ if (aNewSelected) { // store this new selection
+ selectConstruction(aContext, aNewSelected);
+ return true;
}
}
}
const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape)
{
// perform the selection
- TNaming_Selector aSel(myRef.myRef->Label());
+ TNaming_Selector aSel(selectionLabel());
TopoDS_Shape aNewShape = theSubShape ? theSubShape->impl<TopoDS_Shape>() : TopoDS_Shape();
TopoDS_Shape aContext;
aContext = aBody->shape()->impl<TopoDS_Shape>();
else {
ResultConstructionPtr aConstr = boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(myRef.value());
- if (aConstr)
+ if (aConstr) {
aContext = aConstr->shape()->impl<TopoDS_Shape>();
- else
- throw std::invalid_argument("a result with shape is expected");
+ } else {
+ Events_Error::send("A result with shape is expected");
+ return;
+ }
}
- Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(aNewShape, myRef.myRef->Label());
- TDF_Label aLab = aNS->Label();
-
aSel.Select(aNewShape, aContext);
}
for(; aRes != aResults.cend(); aRes++) {
ResultConstructionPtr aConstr =
boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aRes);
- if (aConstr->shape()) {
+ if (aConstr->shape() && aConstr->shape()->isEdge()) {
const TopoDS_Shape& aResShape = aConstr->shape()->impl<TopoDS_Shape>();
TopoDS_Edge anEdge = TopoDS::Edge(aResShape);
if (!anEdge.IsNull()) {
}
}
// store the selected as primitive
- TNaming_Builder aBuilder(myRef.myRef->Label());
+ TNaming_Builder aBuilder(selectionLabel());
aBuilder.Generated(aSubShape);
}
+
+TDF_Label Model_AttributeSelection::selectionLabel()
+{
+ return myRef.myRef->Label().FindChild(1);
+}
virtual void selectConstruction(
const ResultPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape);
+ /// Returns the label where TNaming_Selection results are stored
+ /// Note: there must be no attributes stored at the same label because Selector clears this lab
+ TDF_Label selectionLabel();
+
friend class Model_Data;
friend class Model_AttributeSelectionList;
};
void Model_AttributeSelectionList::clear()
{
if (!mySubs.empty()) {
+ mySize->Set(0);
mySubs.clear();
TDF_ChildIterator aSubIter(mySize->Label());
for(; aSubIter.More(); aSubIter.Next()) {
#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.IsAttribute(kMustBeUpdatedGUID) == Standard_True;
}
-bool Model_Data::referencesTo(const boost::shared_ptr<ModelAPI_Feature>& theFeature)
+int Model_Data::featureId() const
{
- // collect results of this feature first to check references quickly in the cycle
- std::set<ObjectPtr> aFeatureObjs;
- aFeatureObjs.insert(theFeature);
- std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRIter =
- theFeature->results().cbegin();
- for(; aRIter != theFeature->results().cend(); aRIter++) {
- if (*aRIter)
- aFeatureObjs.insert(*aRIter);
- }
+ return myLab.Father().Tag(); // tag of the feature label
+}
- std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttrsIter =
- myAttrs.begin();
- for (; anAttrsIter != myAttrs.end(); anAttrsIter++) {
- if (anAttrsIter->second->attributeType() == ModelAPI_AttributeRefAttr::type()) {
- boost::shared_ptr<ModelAPI_AttributeRefAttr> aRefAttr =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttrsIter->second);
- if (aRefAttr && aRefAttr->isObject()) { // check referenced object
- if (aFeatureObjs.find(aRefAttr->object()) != aFeatureObjs.end())
- return true;
- } else { // check object of referenced attribute
- boost::shared_ptr<ModelAPI_Attribute> anAttr = aRefAttr->attr();
- if (anAttr && aFeatureObjs.find(anAttr->owner()) != aFeatureObjs.end())
- return true;
- }
- } else if (anAttrsIter->second->attributeType() == ModelAPI_AttributeReference::type()) {
- boost::shared_ptr<ModelAPI_AttributeReference> aRef =
- boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(anAttrsIter->second);
- if (aFeatureObjs.find(aRef->value()) != aFeatureObjs.end()) {
- return true;
- }
+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)
+{
+ 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);
}
}
- return false;
}
-int Model_Data::featureId() const
+void Model_Data::referencesToObjects(
+ std::list<std::pair<std::string, std::list<ObjectPtr> > >& theRefs)
{
- return myLab.Father().Tag(); // tag of the feature label
+ std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = myAttrs.begin();
+ std::list<ObjectPtr> aReferenced; // not inside of cycle to avoid excess memory menagement
+ for(; anAttr != myAttrs.end(); anAttr++) {
+ std::string aType = anAttr->second->attributeType();
+ if (aType == ModelAPI_AttributeReference::type()) { // reference to object
+ boost::shared_ptr<ModelAPI_AttributeReference> aRef = boost::dynamic_pointer_cast<
+ ModelAPI_AttributeReference>(anAttr->second);
+ aReferenced.push_back(aRef->value());
+ theRefs.push_back(std::pair<std::string, std::list<ObjectPtr> >(anAttr->first, aReferenced));
+ } else if (aType == ModelAPI_AttributeRefAttr::type()) { // reference to attribute or object
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef = boost::dynamic_pointer_cast<
+ ModelAPI_AttributeRefAttr>(anAttr->second);
+ aReferenced.push_back(aRef->isObject() ? aRef->object() : aRef->attr()->owner());
+ } else if (aType == ModelAPI_AttributeRefList::type()) { // list of references
+ aReferenced = boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(anAttr->second)->list();
+ } else if (aType == ModelAPI_AttributeSelection::type()) { // selection attribute
+ boost::shared_ptr<ModelAPI_AttributeSelection> aRef = boost::dynamic_pointer_cast<
+ ModelAPI_AttributeSelection>(anAttr->second);
+ aReferenced.push_back(aRef->context());
+ theRefs.push_back(std::pair<std::string, std::list<ObjectPtr> >(anAttr->first, aReferenced));
+ } else if (aType == ModelAPI_AttributeSelectionList::type()) { // list of selection attributes
+ boost::shared_ptr<ModelAPI_AttributeSelectionList> aRef = boost::dynamic_pointer_cast<
+ ModelAPI_AttributeSelectionList>(anAttr->second);
+ for(int a = aRef->size() - 1; a >= 0; a--) {
+ aReferenced.push_back(aRef->value(a)->context());
+ }
+ } else
+ continue; // nothing to do, not reference
+
+ if (!aReferenced.empty()) {
+ theRefs.push_back(std::pair<std::string, std::list<ObjectPtr> >(anAttr->first, aReferenced));
+ aReferenced.clear();
+ }
+ }
}
#include <map>
#include <list>
#include <string>
+#include <set>
class ModelAPI_Attribute;
/// needed here to emit signal that object changed on change of the attribute
ObjectPtr myObject;
+ /// List of attributes referenced to owner (updated only during the transaction change)
+ std::set<AttributePtr> myRefsToMe;
+
Model_Data();
/// Returns label of this feature
}
friend class Model_Document;
+ friend class Model_Update;
friend class Model_AttributeReference;
friend class Model_AttributeRefAttr;
friend class Model_AttributeRefList;
/// Returns true if feature must be updated (re-executed) on rebuild
MODEL_EXPORT virtual bool mustBeUpdated();
- /// Returns true if this data attributes are referenced to the given feature or its results
- MODEL_EXPORT virtual bool referencesTo(const boost::shared_ptr<ModelAPI_Feature>& theFeature);
-
/// Returns the identifier of feature-owner, unique in this document
MODEL_EXPORT virtual int featureId() const;
+private:
+ // removes all information about back references
+ 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
+ const std::set<AttributePtr>& refsToMe() {return myRefsToMe;}
+ // returns all references by attributes of this data
+ // \param the returned list of pairs: id of referenced attribute and list of referenced objects
+ void referencesToObjects(std::list<std::pair<std::string, std::list<ObjectPtr> > >& theRefs);
};
#endif
#include <Model_ResultPart.h>
#include <Model_ResultConstruction.h>
#include <Model_ResultBody.h>
+#include <ModelAPI_Validator.h>
#include <Events_Loop.h>
#include <Events_Error.h>
myDoc->SetUndoLimit(UNDO_LIMIT);
// to avoid the problem that feature is created in the current, not this, document
Model_Session::get()->setActiveDocument(anApp->getDocument(myID));
- synchronizeFeatures();
+ synchronizeFeatures(false, true);
}
return !isError;
}
if (!myDoc->HasOpenCommand() && myNestedNum != -1)
boost::static_pointer_cast<Model_Session>(Model_Session::get())
->setCheckTransactions(false); // for nested transaction commit
+ synchronizeBackRefs();
Events_Loop* aLoop = Events_Loop::loop();
aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+ aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TOHIDE));
aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
if (!myDoc->HasOpenCommand() && myNestedNum != -1)
boost::static_pointer_cast<Model_Session>(Model_Session::get())
myIsEmptyTr[myTransactionsAfterSave] = !myDoc->CommitCommand(); // && (myNestedNum == -1);
myTransactionsAfterSave++;
}
-
}
void Model_Document::abortOperation()
myNestedNum = -1;
myDoc->AbortCommand();
}
- synchronizeFeatures(true);
+ synchronizeFeatures(true, false); // references were not changed since transaction start
// abort for all subs
std::set<std::string>::iterator aSubIter = mySubs.begin();
for (; aSubIter != mySubs.end(); aSubIter++)
myNestedNum--;
if (!myIsEmptyTr[myTransactionsAfterSave])
myDoc->Undo();
- synchronizeFeatures(true);
+ synchronizeFeatures(true, true);
// undo for all subs
std::set<std::string>::iterator aSubIter = mySubs.begin();
for (; aSubIter != mySubs.end(); aSubIter++)
if (!myIsEmptyTr[myTransactionsAfterSave])
myDoc->Redo();
myTransactionsAfterSave++;
- synchronizeFeatures(true);
+ synchronizeFeatures(true, true);
// redo for all subs
std::set<std::string>::iterator aSubIter = mySubs.begin();
for (; aSubIter != mySubs.end(); aSubIter++)
// check the feature: it must have no depended objects on it
std::list<ResultPtr>::const_iterator aResIter = theFeature->results().cbegin();
for(; aResIter != theFeature->results().cend(); aResIter++) {
- if (myConcealedResults.find(*aResIter) != myConcealedResults.end()) {
- Events_Error::send("Feature '" + theFeature->data()->name() + "' is used and can not be deleted");
- return;
- }
- }
- NCollection_DataMap<TDF_Label, FeaturePtr>::Iterator anObjIter(myObjs);
- for(; anObjIter.More(); anObjIter.Next()) {
- DataPtr aData = anObjIter.Value()->data();
- if (aData->referencesTo(theFeature)) {
- Events_Error::send("Feature '" + theFeature->data()->name() + "' is used and can not be deleted");
+ boost::shared_ptr<Model_Data> aData =
+ boost::dynamic_pointer_cast<Model_Data>((*aResIter)->data());
+ if (aData && !aData->refsToMe().empty()) {
+ Events_Error::send(
+ "Feature '" + theFeature->data()->name() + "' is used and can not be deleted");
return;
}
}
// erase all attributes under the label of feature
aFeatureLabel.ForgetAllAttributes();
// remove it from the references array
- RemoveFromRefArray(featuresLabel(), aFeatureLabel);
-
+ if (theFeature->isInHistory()) {
+ RemoveFromRefArray(featuresLabel(), aFeatureLabel);
+ }
// event: feature is deleted
ModelAPI_EventCreator::get()->sendDeleted(theFeature->document(), ModelAPI_Feature::group());
- /* this is in "erase"
- // results of this feature must be redisplayed
- static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
- const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = theFeature->results();
- std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
- for (; aRIter != aResults.cend(); aRIter++) {
- boost::shared_ptr<ModelAPI_Result> aRes = *aRIter;
- aRes->setData(boost::shared_ptr<ModelAPI_Data>()); // deleted flag
- ModelAPI_EventCreator::get()->sendUpdated(aRes, EVENT_DISP);
- ModelAPI_EventCreator::get()->sendDeleted(theFeature->document(), aRes->groupName());
- }
- */
}
FeaturePtr Model_Document::feature(TDF_Label& theLabel)
std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
for (; aRIter != aResults.cend(); aRIter++) {
if ((*aRIter)->groupName() != theGroupID) continue;
- bool isIn = theHidden;
+ bool isIn = theHidden && (*aRIter)->isInHistory();
if (!isIn && (*aRIter)->isInHistory()) { // check that there is nobody references this result
- isIn = myConcealedResults.find(*aRIter) == myConcealedResults.end();
+ isIn = !(*aRIter)->isConcealed();
}
if (isIn) {
if (anIndex == theIndex)
if ((*aRIter)->groupName() != theGroupID) continue;
bool isIn = theHidden;
if (!isIn && (*aRIter)->isInHistory()) { // check that there is nobody references this result
- isIn = myConcealedResults.find(*aRIter) == myConcealedResults.end();
+ isIn = !(*aRIter)->isConcealed();
}
if (isIn)
aResult++;
// check this is unique, if not, increase index by 1
for (aFIter.Initialize(myObjs); aFIter.More();) {
FeaturePtr aFeature = aFIter.Value();
- bool isSameName = aFeature->isInHistory() && aFeature->data()->name() == aName;
+ bool isSameName = aFeature->data()->name() == aName;
if (!isSameName) { // check also results to avoid same results names (actual for Parts)
const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
for (; aRIter != aResults.cend(); aRIter++) {
- isSameName = (*aRIter)->isInHistory() && (*aRIter)->data()->name() == aName;
+ isSameName = (*aRIter)->data()->name() == aName;
}
}
if (isSameName) {
}
}
-void Model_Document::synchronizeFeatures(const bool theMarkUpdated)
+void Model_Document::synchronizeFeatures(const bool theMarkUpdated, const bool theUpdateReferences)
{
boost::shared_ptr<ModelAPI_Document> aThis =
Model_Application::getApplication()->getDocument(myID);
aFIter.Next();
}
+ if (theUpdateReferences) {
+ synchronizeBackRefs();
+ }
+
myExecuteFeatures = false;
aLoop->activateFlushes(true);
aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
}
aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+ aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TOHIDE));
boost::static_pointer_cast<Model_Session>(Model_Session::get())
->setCheckTransactions(true);
myExecuteFeatures = true;
}
+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()) {
+ FeaturePtr aFeature = aFeatures.Value();
+ boost::shared_ptr<Model_Data> aFData =
+ boost::dynamic_pointer_cast<Model_Data>(aFeature->data());
+ if (aFData) {
+ aFData->eraseBackReferences();
+ }
+ const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
+ std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
+ for (; aRIter != aResults.cend(); aRIter++) {
+ 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();
+ }
+ }
+ }
+
+ // second cycle: set new back-references: only features may have reference, iterate only them
+ ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators();
+ for(aFeatures.Initialize(myObjs); aFeatures.More(); aFeatures.Next()) {
+ FeaturePtr aFeature = aFeatures.Value();
+ boost::shared_ptr<Model_Data> aFData =
+ boost::dynamic_pointer_cast<Model_Data>(aFeature->data());
+ if (aFData) {
+ std::list<std::pair<std::string, std::list<ObjectPtr> > > aRefs;
+ aFData->referencesToObjects(aRefs);
+ std::list<std::pair<std::string, std::list<ObjectPtr> > >::iterator aRefsIter = aRefs.begin();
+ for(; aRefsIter != aRefs.end(); aRefsIter++) {
+ std::list<ObjectPtr>::iterator aRefTo = aRefsIter->second.begin();
+ for(; aRefTo != aRefsIter->second.end(); aRefTo++) {
+ if (*aRefTo) {
+ boost::shared_ptr<Model_Data> aRefData =
+ boost::dynamic_pointer_cast<Model_Data>((*aRefTo)->data());
+ aRefData->addBackReference(aFeature, aRefsIter->first); // here the Concealed flag is updated
+ }
+ }
+ }
+ }
+ }
+ 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(
const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theResultIndex)
{
}
}
-void Model_Document::objectIsReferenced(const ObjectPtr& theObject)
-{
- // only bodies are concealed now
- ResultBodyPtr aResult = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(theObject);
- if (aResult) {
- if (myConcealedResults.find(aResult) != myConcealedResults.end()) {
- Events_Error::send(std::string("The object '") + aResult->data()->name() +
- "' is already referenced");
- } else {
- myConcealedResults.insert(aResult);
- boost::shared_ptr<ModelAPI_Document> aThis =
- Model_Application::getApplication()->getDocument(myID);
- ModelAPI_EventCreator::get()->sendDeleted(aThis, ModelAPI_ResultBody::group());
-
- static Events_Loop* aLoop = Events_Loop::loop();
- static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
- static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
- aECreator->sendUpdated(aResult, EVENT_DISP);
- }
- }
-}
-
-void Model_Document::objectIsNotReferenced(const ObjectPtr& theObject)
-{
- // only bodies are concealed now
- ResultBodyPtr aResult = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(theObject);
- if (aResult) {
- std::set<ResultPtr>::iterator aFind = myConcealedResults.find(aResult);
- if (aFind != myConcealedResults.end()) {
- ResultPtr aFeature = *aFind;
- myConcealedResults.erase(aFind);
- boost::shared_ptr<ModelAPI_Document> aThis =
- Model_Application::getApplication()->getDocument(myID);
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
- ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent, false);
- } else {
- Events_Error::send(std::string("The object '") + aResult->data()->name() +
- "' was not referenced '");
- }
- }
-}
-
Standard_Integer HashCode(const TDF_Label& theLab, const Standard_Integer theUpper)
{
return TDF_LabelMapHasher::HashCode(theLab, theUpper);
///! On abort, undo or redo it is not necessary: results in document are updated automatically
bool executeFeatures() {return myExecuteFeatures;}
- ///! Reutrns true is result was conecaled because of usage it by other object
- virtual bool isConcealed(const boost::shared_ptr<ModelAPI_Object>& theResult) {
- return myConcealedResults.find(boost::dynamic_pointer_cast<ModelAPI_Result>(theResult))
- != myConcealedResults.end();
- }
-
protected:
//! Returns (creates if needed) the features label
void setUniqueName(FeaturePtr theFeature);
//! Synchronizes myFeatures list with the updated document
- void synchronizeFeatures(const bool theMarkUpdated = false);
+ //! \param theMarkUpdated causes the "update" event for all features
+ //! \param theUpdateReferences causes the update of back-references
+ void synchronizeFeatures(const bool theMarkUpdated, const bool theUpdateReferences);
+ //! Synchronizes the BackReferences list in Data of Features and Results
+ void synchronizeBackRefs();
//! Creates new document with binary file format
Model_Document(const std::string theID, const std::string theKind);
//! Updates the results list of the feature basing on the current data tree
void updateResults(FeaturePtr theFeature);
- //! Stores information that there is a reference to this object
- void objectIsReferenced(const ObjectPtr& theObject);
- //! Removes information that there is a reference to this object
- void objectIsNotReferenced(const ObjectPtr& theObject);
-
//! Returns all sub documents
const std::set<std::string>& subDocuments() const {return mySubs;}
/// All features managed by this document (not only in history of OB)
/// For optimization mapped by labels
NCollection_DataMap<TDF_Label, FeaturePtr> myObjs;
- /// Results that are referenced and must be concealed for object browser
- std::set<ResultPtr> myConcealedResults;
///< set of identifiers of sub-documents of this document
std::set<std::string> mySubs;
Model_ResultBody::Model_ResultBody()
{
+ setIsConcealed(false);
}
void Model_ResultBody::store(const boost::shared_ptr<GeomAPI_Shape>& theShape)
boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
if (aData) {
TDF_Label& aShapeLab = aData->shapeLab();
- // remove the previous history
- clean();
- aShapeLab.ForgetAttribute(TNaming_NamedShape::GetID());
- for(TDF_ChildIterator anIter(aShapeLab); anIter.More(); anIter.Next()) {
- anIter.Value().ForgetAllAttributes();
- }
+ // clean builders
+ clean();
// store the new shape as primitive
TNaming_Builder aBuilder(aShapeLab);
if (!theShape)
}
}
+void Model_ResultBody::storeGenerated(const boost::shared_ptr<GeomAPI_Shape>& theFromShape,
+ const boost::shared_ptr<GeomAPI_Shape>& theToShape)
+{
+ boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
+ if (aData) {
+ TDF_Label& aShapeLab = aData->shapeLab();
+ // clean builders
+ clean();
+ // store the new shape as primitive
+ TNaming_Builder aBuilder(aShapeLab);
+ if (!theFromShape || !theToShape)
+ return; // bad shape
+ TopoDS_Shape aShapeBasis = theFromShape->impl<TopoDS_Shape>();
+ if (aShapeBasis.IsNull())
+ return; // null shape inside
+ TopoDS_Shape aShapeNew = theToShape->impl<TopoDS_Shape>();
+ if (aShapeNew.IsNull())
+ return; // null shape inside
+ aBuilder.Generated(aShapeBasis, aShapeNew);
+ }
+}
+
+void Model_ResultBody::storeModified(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+ const boost::shared_ptr<GeomAPI_Shape>& theNewShape)
+{
+ boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
+ if (aData) {
+ TDF_Label& aShapeLab = aData->shapeLab();
+ // clean builders
+ clean();
+ // store the new shape as primitive
+ TNaming_Builder aBuilder(aShapeLab);
+ if (!theOldShape || !theNewShape)
+ return; // bad shape
+ TopoDS_Shape aShapeOld = theOldShape->impl<TopoDS_Shape>();
+ if (aShapeOld.IsNull())
+ return; // null shape inside
+ TopoDS_Shape aShapeNew = theNewShape->impl<TopoDS_Shape>();
+ if (aShapeNew.IsNull())
+ return; // null shape inside
+ aBuilder.Generated(aShapeOld, aShapeNew);
+ }
+}
+
boost::shared_ptr<GeomAPI_Shape> Model_ResultBody::shape()
{
boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
public:
/// Stores the shape (called by the execution method).
MODEL_EXPORT virtual void store(const boost::shared_ptr<GeomAPI_Shape>& theShape);
+
+ /// Stores the generated shape (called by the execution method).
+ MODEL_EXPORT virtual void storeGenerated(const boost::shared_ptr<GeomAPI_Shape>& theFromShape,
+ const boost::shared_ptr<GeomAPI_Shape>& theToShape);
+
+ /// Stores the modified shape (called by the execution method).
+ MODEL_EXPORT virtual void storeModified(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+ const boost::shared_ptr<GeomAPI_Shape>& theNewShape);
+
/// Returns the shape-result produced by this feature
MODEL_EXPORT virtual boost::shared_ptr<GeomAPI_Shape> shape();
/// Returns the source feature of this result
Model_ResultConstruction::Model_ResultConstruction()
{
myIsInHistory = true;
+ setIsConcealed(false);
}
void Model_ResultConstruction::setIsInHistory(const bool isInHistory)
Model_ResultPart::Model_ResultPart()
{
+ setIsConcealed(false);
}
void Model_ResultPart::setData(boost::shared_ptr<ModelAPI_Data> theData)
aRT->SetRelocation(aSourceRoot, aTargetRoot);
TDF_CopyTool::Copy(aDS, aRT);
- aNew->synchronizeFeatures();
+ aNew->synchronizeFeatures(false, true);
return aNew;
}
#include <Model_Update.h>
#include <Model_Document.h>
+#include <Model_Data.h>
#include <ModelAPI_Feature.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Document.h>
aMustbeUpdated = true;
}
}
-
- // references
- list<boost::shared_ptr<ModelAPI_Attribute> > aRefs = theFeature->data()->attributes(
- ModelAPI_AttributeReference::type());
- list<boost::shared_ptr<ModelAPI_Attribute> >::iterator aRefsIter = aRefs.begin();
- for (; aRefsIter != aRefs.end(); aRefsIter++) {
- boost::shared_ptr<ModelAPI_Object> aSub = boost::dynamic_pointer_cast<
- ModelAPI_AttributeReference>(*aRefsIter)->value();
- if (updateObject(aSub)) {
- aMustbeUpdated = true;
- }
- }
- // reference to attribute or object
- list<boost::shared_ptr<ModelAPI_Attribute> > aRefAttrs = theFeature->data()->attributes(
- ModelAPI_AttributeRefAttr::type());
- for (aRefsIter = aRefAttrs.begin(); aRefsIter != aRefAttrs.end(); aRefsIter++) {
- boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*aRefsIter);
- if (!aRef) continue;
- if (aRef->isObject()) {
- boost::shared_ptr<ModelAPI_Object> aSub = aRef->object();
- if (updateObject(aSub)) {
- aMustbeUpdated = true;
- }
- } else if (aRef->attr()) { // reference to the attribute
- boost::shared_ptr<ModelAPI_Object> aSub = aRef->attr()->owner();
- if (updateObject(aSub)) {
- aMustbeUpdated = true;
- }
- }
- }
- // lists of references
- aRefs = theFeature->data()->attributes(ModelAPI_AttributeRefList::type());
- for (aRefsIter = aRefs.begin(); aRefsIter != aRefs.end(); aRefsIter++) {
- list<ObjectPtr> aListRef = boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(*aRefsIter)
- ->list();
- list<ObjectPtr>::iterator aListIter = aListRef.begin();
- for (; aListIter != aListRef.end(); aListIter++) {
- boost::shared_ptr<ModelAPI_Object> aSub = *aListIter;
- if (updateObject(aSub)) {
- aMustbeUpdated = true;
- }
- }
- }
- // selection attributes: must be called "update" methods if needed
- aRefs = theFeature->data()->attributes(ModelAPI_AttributeSelection::type());
- for (aRefsIter = aRefs.begin(); aRefsIter != aRefs.end(); aRefsIter++) {
- boost::shared_ptr<ModelAPI_AttributeSelection> aSel =
- boost::dynamic_pointer_cast<ModelAPI_AttributeSelection>(*aRefsIter);
- if (updateObject(aSel->context())) {
- aMustbeUpdated = true;
- // aSel->update(); // this must be done on execution since it may be long operation
- }
- }
- // lists of selection attributes: must be called "update" methods if needed
- aRefs = theFeature->data()->attributes(ModelAPI_AttributeSelectionList::type());
- for (aRefsIter = aRefs.begin(); aRefsIter != aRefs.end(); aRefsIter++) {
- boost::shared_ptr<ModelAPI_AttributeSelectionList> aSel =
- boost::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(*aRefsIter);
- for(int a = aSel->size() - 1; a >= 0; a--) {
- if (updateObject(aSel->value(a)->context())) {
+ // check all references: if referenced objects are updated, this object also must be updated
+ std::list<std::pair<std::string, std::list<ObjectPtr> > > aRefs;
+ boost::shared_ptr<Model_Data> aData =
+ boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
+ aData->referencesToObjects(aRefs);
+ std::list<std::pair<std::string, std::list<ObjectPtr> > >::iterator aRef = aRefs.begin();
+ for(; aRef != aRefs.end(); aRef++) {
+ std::list<ObjectPtr>::iterator aRefObj = aRef->second.begin();
+ for(; aRefObj != aRef->second.end(); aRefObj++) {
+ if (updateObject(*aRefObj)) {
aMustbeUpdated = true;
}
}
!theFeature->isPersistentResult() /* execute quick, not persistent results */)
{
// before execution update the selection attributes if any
- aRefs = theFeature->data()->attributes(ModelAPI_AttributeSelection::type());
- for (aRefsIter = aRefs.begin(); aRefsIter != aRefs.end(); aRefsIter++) {
+ list<AttributePtr> aRefs =
+ theFeature->data()->attributes(ModelAPI_AttributeSelection::type());
+ list<AttributePtr>::iterator aRefsIter = aRefs.begin();
+ for (; aRefsIter != aRefs.end(); aRefsIter++) {
boost::shared_ptr<ModelAPI_AttributeSelection> aSel =
boost::dynamic_pointer_cast<ModelAPI_AttributeSelection>(*aRefsIter);
aSel->update(); // this must be done on execution since it may be long operation
return true;
}
-void Model_ValidatorsFactory::registerNotObligatory(
- std::string theFeature, std::string theAttribute)
+void Model_ValidatorsFactory::registerNotObligatory(std::string theFeature, std::string theAttribute)
{
std::map<std::string, ModelAPI_Validator*>::const_iterator it = myIDs.find(kDefaultId);
if (it != myIDs.end()) {
}
}
}
+
+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,
/// so, it is not needed for the standard validation mechanism
virtual void registerNotObligatory(std::string theFeature, std::string theAttribute);
+ /// register that this attribute conceals in the object browser
+ /// 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
/// Returns true if feature must be updated (re-executed) on rebuild
virtual bool mustBeUpdated() = 0;
- /// Returns true if this data attributes are referenced to the given feature or its results
- virtual bool referencesTo(const boost::shared_ptr<ModelAPI_Feature>& theFeature) = 0;
-
/// Returns the identifier of feature-owner, unique in this document
virtual int featureId() const = 0;
virtual boost::shared_ptr<ModelAPI_Feature> feature(
const boost::shared_ptr<ModelAPI_Result>& theResult) = 0;
- ///! Reutrns true is result was conecaled because of usage it by other object
- virtual bool isConcealed(const boost::shared_ptr<ModelAPI_Object>& theResult) = 0;
-
protected:
/// Only for SWIG wrapping it is here
MODELAPI_EXPORT ModelAPI_Document()
/// To use virtuality for destructors
virtual ~ModelAPI_Object() {}
+
protected:
/// Sets the data manager of an object (document does)
virtual void setData(boost::shared_ptr<ModelAPI_Data> theData)
*/
class ModelAPI_Result : public ModelAPI_Object
{
+ bool myIsConcealed; ///< the result is concealed from the data tree (referenced by other objects)
public:
- /// Returns the source feature of this result
- //virtual boost::shared_ptr<ModelAPI_Feature> owner() = 0;
+ /// Returns true if the result is concealed from the data tree (referenced by other objects)
+ inline bool isConcealed() {return myIsConcealed;}
+
+ /// Returns true if the result is concealed from the data tree (referenced by other objects)
+ inline void setIsConcealed(const bool theValue) {myIsConcealed = theValue;}
+
+ /// To virtually destroy the fields of successors
+ virtual ~ModelAPI_Result()
+ {
+ }
- /// Returns the group identifier of this result
- //virtual std::string groupName() = 0;
};
//! Pointer on feature object
/// Stores the shape (called by the execution method).
virtual void store(const boost::shared_ptr<GeomAPI_Shape>& theShape) = 0;
+
+ /// Stores the generated shape (called by the execution method).
+ virtual void storeGenerated(const boost::shared_ptr<GeomAPI_Shape>& theFromShape,
+ const boost::shared_ptr<GeomAPI_Shape>& theToShape) = 0;
+
+ /// Stores the modified shape (called by the execution method).
+ virtual void storeModified(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+ const boost::shared_ptr<GeomAPI_Shape>& theNewShape) = 0;
+
/// Returns the shape-result produced by this feature
virtual boost::shared_ptr<GeomAPI_Shape> shape() = 0;
- /// To virtually destroy the fields of successors
- virtual ~ModelAPI_ResultBody()
- {
- }
-
/// Records the subshape newShape which was generated during a topological construction.
/// As an example, consider the case of a face generated in construction of a box.
virtual void generated(
const boost::shared_ptr<GeomAPI_Shape>& theOldShape, const int theTag = 1) = 0;
protected:
- /// Use plugin manager for features creation: this method is
- /// defined here only for SWIG-wrapping
- ModelAPI_ResultBody()
- {
- }
};
//! Pointer on feature object
/// so, it is not needed for the standard validation mechanism
virtual void registerNotObligatory(std::string theFeature, std::string theAttribute) = 0;
+ /// register that this attribute conceals in the object browser
+ /// 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()
myParentId(theParentId)
{
myIsComputedDefault = false;
- myIsObligatory = theData ? theData->getBooleanAttribute(FEATURE_OBLIGATORY, true) : true;
myAttributeID = theData ? theData->widgetId() : "";
}
{
QList<QWidget*> aMyControls = getControls();
foreach(QWidget* eachControl, aMyControls) {
- if(!myFocusInWidgets.contains(eachControl)) {
- enableFocusProcessing(eachControl);
- }
+ eachControl->setFocusPolicy(Qt::StrongFocus);
+ eachControl->installEventFilter(this);
}
}
ModelAPI_EventCreator::get()->sendUpdated(theObj, anEvent);
}
-void ModuleBase_ModelWidget::enableFocusProcessing(QWidget* theWidget)
-{
- theWidget->setFocusPolicy(Qt::StrongFocus);
- theWidget->installEventFilter(this);
- myFocusInWidgets.append(theWidget);
-}
-
bool ModuleBase_ModelWidget::eventFilter(QObject* theObject, QEvent *theEvent)
{
QWidget* aWidget = qobject_cast<QWidget*>(theObject);
- if (theEvent->type() == QEvent::MouseButtonRelease &&
- myFocusInWidgets.contains(aWidget)) {
- emit focusInWidget(this);
+ if (theEvent->type() == QEvent::FocusIn) {
+ if (getControls().contains(aWidget)) {
+ emit focusInWidget(this);
+ }
}
// pass the event on to the parent class
+
return QObject::eventFilter(theObject, theEvent);
}
/// on operation's execute, like radius for circle's constraint (can not be zero)
bool isComputedDefault() { return myIsComputedDefault; }
- /// Returns false for non-obligatory widgets which are
- /// valid even if they are not initialized
- bool isObligatory() { return myIsObligatory; }
-
/// Defines if it is supposed that the widget should interact with the viewer.
virtual bool isViewerSelector() { return false; }
void updateObject(ObjectPtr theObj) const;
- private:
- /// Let the widget process FocusIn events
- void enableFocusProcessing(QWidget* theWidget);
-
protected:
std::string myAttributeID; /// the attribute name of the model feature
std::string myParentId; /// name of parent
FeaturePtr myFeature;
bool myIsComputedDefault; /// Value should be computed on execute,
- /// like radius for circle's constraint (can not be zero)
- bool myIsObligatory; /// Non-obligatory widget is valid even if it is not initialized
-
- private:
- /// Contains a list of widgets that may accept focus
- QList<QWidget*> myFocusInWidgets;
+ /// like radius for circle's constraint (can not be zero)
};
#endif
void ModuleBase_Operation::resume()
{
if (myPropertyPanel)
- connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), this,
- SLOT(onWidgetActivated(ModuleBase_ModelWidget*)));
+ connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)),
+ this, SLOT(onWidgetActivated(ModuleBase_ModelWidget*)));
emit resumed();
}
#include "ModuleBase_ResultPrs.h"
#include <ModelAPI_Tools.h>
-#include <GeomAPI_Wire.h>
+#include <GeomAPI_PlanarEdges.h>
#include <GeomAlgoAPI_SketchBuilder.h>
#include <BRep_Builder.hxx>
: AIS_Shape(TopoDS_Shape()), myResult(theResult), myIsSketchMode(false)
{
boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(theResult);
- boost::shared_ptr<GeomAPI_Wire> aWirePtr =
- boost::dynamic_pointer_cast<GeomAPI_Wire>(aShapePtr);
+ boost::shared_ptr<GeomAPI_PlanarEdges> aWirePtr =
+ boost::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aShapePtr);
if (aWirePtr) {
if (aWirePtr->hasPlane() ) {
// If this is a wire with plane defined thin it is a sketch-like object
//Create a widget (doublevalue, groupbox, toolbox, etc.
QWidget* aWidget = createWidgetByType(aWdgType, theParent);
if (aWidget) {
- if (!myWidgetApi->getBooleanAttribute(FEATURE_INTERNAL, false)) {
+ if (!myWidgetApi->getBooleanAttribute(ATTRIBUTE_INTERNAL, false)) {
aWidgetLay->addWidget(aWidget);
} else {
aWidget->setVisible(false);
return result;
}
+void ModuleBase_WidgetFactory::processAttributes()
+{
+ // register that this attribute in feature is not obligatory for the feature execution
+ // so, it is not needed for the standard validation mechanism
+ bool isObligatory = true;
+ bool isConcealment = false;
+ if( myWidgetApi ){
+ isObligatory = myWidgetApi->getBooleanAttribute(ATTRIBUTE_OBLIGATORY, true);
+ isConcealment = myWidgetApi->getBooleanAttribute(ATTRIBUTE_CONCEALMENT, false);
+ }
+ boost::shared_ptr<ModelAPI_Session> aSession = ModelAPI_Session::get();
+ if (!isObligatory) {
+ aSession->validators()->registerNotObligatory(myParentId, myWidgetApi->widgetId());
+ }
+ if(isConcealment) {
+ aSession->validators()->registerConcealment(myParentId, myWidgetApi->widgetId());
+ }
+}
+
QWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType,
QWidget* theParent)
{
#endif
}
if (result) {
- // register that this attribute in feature is not obligatory for the feature execution
- // so, it is not needed for the standard validation mechanism
- bool isObligatory =
- myWidgetApi ? myWidgetApi->getBooleanAttribute(FEATURE_OBLIGATORY, true) : true;
- if (!isObligatory) {
- ModelAPI_Session::get()->validators()->registerNotObligatory(
- myParentId, myWidgetApi->widgetId());
- }
+ processAttributes();
}
return result;
QString qs(const std::string& theStdString) const;
+ void processAttributes();
private:
Config_WidgetAPI* myWidgetApi;
#include <boost/smart_ptr/shared_ptr.hpp>
#include <list>
-#include <stdexcept>
-#include <xstring>
+#include <string>
typedef QMap<QString, TopAbs_ShapeEnum> ShapeTypes;
static ShapeTypes MyShapeTypes;
if (!myUseSubShapes) {
static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TOHIDE);
ModelAPI_EventCreator::get()->sendUpdated(mySelectedObject, anEvent);
- Events_Loop::loop()->flush(anEvent);
}
}
updateSelectionName();
#include <XGUI_ContextMenuMgr.h>
#include <XGUI_Preferences.h>
#include <XGUI_ObjectsBrowser.h>
+#include <XGUI_OperationMgr.h>
+
+#include <ModuleBase_Operation.h>
#include <LightApp_Application.h>
#include <LightApp_SelectionMgr.h>
mySelector = createSelector(OCCViewManagers.first());
}
}
- myWorkshop->propertyPanel()->hide();
QtxPopupMgr* aMgr = popupMgr(); // Create popup manager
action(myEraseAll)->setEnabled(false);
QTimer::singleShot(1000, myWorkshop, SLOT(displayAllResults()));
}
}
+ SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
+ myIsStorePositions = aResMgr->booleanValue("Study", "store_positions", true);
+
+ // this following row is caused by #187 bug.
+ // SALOME saves the dock widget positions before deactivateModule() and
+ // load it after the module activation. So, if the panel is visible before
+ // deactivate, it becomes visible after activate.
+ // In order to avoid the visible property panel, the widget position save is
+ // switch off in this module
+ aResMgr->setValue("Study", "store_positions", false);
+
return isDone;
}
setMenuShown(false);
setToolShown(false);
- myWorkshop->propertyPanel()->setVisible(false);
- desktop()->removeDockWidget(myWorkshop->propertyPanel());
-
QObject* aObj = myWorkshop->objectBrowser()->parent();
QDockWidget* aObjDoc = dynamic_cast<QDockWidget*>(aObj);
if (aObjDoc) {
aViewAct->setEnabled(false);
}
+ // the active operation should be stopped for the next activation.
+ // There should not be active operation and visualized preview.
+ // Abort operation should be performed before the selection's remove
+ // because the displayed objects should be removed from the viewer, but
+ // the AIS context is obtained from the selector.
+ ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
+ if (anOperation)
+ anOperation->abort();
+
// Delete selector because it has to be redefined on next activation
if (mySelector) {
myProxyViewer->setSelector(0);
}
//myWorkshop->contextMenuMgr()->disconnectViewer();
+
+ SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
+ aResMgr->setValue("Study", "store_positions", myIsStorePositions);
+
return LightApp_Module::deactivateModule(theStudy);
}
return QStringList();
}
+//******************************************************
+void NewGeom_Module::setDocumentKind(const QString& theId, const QString& theKind)
+{
+ myDocumentType[theId] = theKind;
+}
+
+//******************************************************
+QString NewGeom_Module::documentKind(const QString& theId) const
+{
+ if (myDocumentType.contains(theId))
+ return myDocumentType[theId];
+ return QString();
+
+}
+
//******************************************************
void NewGeom_Module::selectionChanged()
{
//! Returns list of nested actions according to the given command ID
virtual QStringList nestedActions(const QString& theId) const;
+ //! Set the document kind of the action by the given command Id
+ //! \param theId - the command ID
+ //! \param theKind - the document kind
+ virtual void setDocumentKind(const QString& theId, const QString& theKind);
+
+ //! Returns the document kind of the action by the given command ID
+ virtual QString documentKind(const QString& theId) const;
+
//! Returns interface to Salome viewer
virtual ModuleBase_IViewer* viewer() const
{
NewGeom_SalomeViewer* myProxyViewer;
QMap<QString, QStringList> myNestedActions;
+ QMap<QString, QString> myDocumentType;
bool myIsOpened;
+ bool myIsStorePositions;
+
};
#endif
#include <V3d_View.hxx>
+#include <QMouseEvent>
#ifdef _DEBUG
#include <QDebug>
#endif
-#include <QMouseEvent>
-
-using namespace std;
+//using namespace std;
PartSet_OperationFeatureEditMulti::PartSet_OperationFeatureEditMulti(const QString& theId,
QObject* theParent,
myFeatures.append(aPrs);
}
// Remove current feature if it is in the list (it will be moved as main feature)
- FeaturePtr aFea = feature();
foreach (ModuleBase_ViewerPrs aPrs, myFeatures) {
FeaturePtr aF = ModelAPI_Feature::feature(aPrs.object());
if (ModelAPI_Feature::feature(aPrs.object()) == feature()) {
#include <QObject>
#include <QList>
+#include <list>
+
class QMouseEvent;
/*!
#include <GeomAPI_AISObject.h>
#include <GeomAPI_Dir.h>
-#include <GeomAPI_Wire.h>
+#include <GeomAPI_PlanarEdges.h>
#include <GeomAPI_XYZ.h>
#include <GeomDataAPI_Dir.h>
return;
// Collect all edges as one big wire
- boost::shared_ptr<GeomAPI_Wire> aBigWire(new GeomAPI_Wire);
+ boost::shared_ptr<GeomAPI_PlanarEdges> aBigWire(new GeomAPI_PlanarEdges);
std::list<boost::shared_ptr<GeomAPI_Shape> >::const_iterator aShapeIt = aFeaturesPreview.begin();
for (; aShapeIt != aFeaturesPreview.end(); ++aShapeIt) {
aBigWire->addEdge(*aShapeIt);
{
std::string aStdDocKind = ModelAPI_Session::get()->activeDocument()->kind();
QString aDocKind = QString::fromStdString(aStdDocKind);
+ XGUI_Workshop* aWorkshop = static_cast<XGUI_Workshop*>(parent());
foreach(QAction* eachAction, myActions.values()) {
XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(eachAction);
+ QString aCmdDocKind;
if(aCmd) {
- QString aCmdDocKind = aCmd->documentKind();
- if(!aCmdDocKind.isEmpty() && aCmdDocKind != aDocKind) {
- eachAction->setEnabled(false);
+ aCmdDocKind = aCmd->documentKind();
+ }
+ else {
+ QString aId = eachAction->data().toString();
+ if (!aId.isEmpty()) {
+ aCmdDocKind = aWorkshop->salomeConnector()->documentKind(aId);
}
}
+ if(!aCmdDocKind.isEmpty() && aCmdDocKind != aDocKind) {
+ eachAction->setEnabled(false);
+ }
}
}
void XGUI_PreferencesDlg::onDefault()
{
// reset main resources
- QtxResourceMgr::WorkingMode aPrev = myPreferences->resourceMgr()->setWorkingMode
- (QtxResourceMgr::IgnoreUserValues);
+#ifdef WIN32
+ QtxResourceMgr::WorkingMode aPrev =
+ myPreferences->resourceMgr()->setWorkingMode(QtxResourceMgr::IgnoreUserValues);
myPreferences->retrieve();
myPreferences->resourceMgr()->setWorkingMode(aPrev);
-
+#endif
// reset plugin's resources
XGUI_Preferences::resetConfig();
XGUI_Preferences::updateResourcesByConfig();
#endif
XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent)
- : ModuleBase_IPropertyPanel(theParent), myActiveWidget(0)
+ : ModuleBase_IPropertyPanel(theParent),
+ myActiveWidget(NULL)
{
this->setWindowTitle(tr("Property Panel"));
QAction* aViewAct = this->toggleViewAction();
{
myWidgets.clear();
qDeleteAll(myCustomWidget->children());
+ myActiveWidget = NULL;
}
void XGUI_PropertyPanel::setModelWidgets(const QList<ModuleBase_ModelWidget*>& theWidgets)
connect(*anIt, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)), this,
SLOT(activateNextWidget(ModuleBase_ModelWidget*)));
connect(*anIt, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)),
- this, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)));
+ this, SLOT(activateWidget(ModuleBase_ModelWidget*)));
ModuleBase_WidgetPoint2D* aPointWidget = dynamic_cast<ModuleBase_WidgetPoint2D*>(*anIt);
if (aPointWidget)
void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature)
{
- int aS = myWidgets.size();
foreach(ModuleBase_ModelWidget* eachWidget, myWidgets)
{
eachWidget->setFeature(theFeature);
eachWidget->restoreValue();
}
- // the repaint is used here to immediatelly react in GUI to the values change.
+ // the repaint is used here to immediately react in GUI to the values change.
repaint();
}
-
void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget)
{
- QObject* aSender = sender();
ModuleBase_ModelWidget* aNextWidget = 0;
QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end();
bool isFoundWidget = false;
}
isFoundWidget = (*anIt) == theWidget;
}
- myActiveWidget = aNextWidget;
- emit widgetActivated(myActiveWidget);
+ // Normaly focusTo is enough to activate widget
+ // here is a special case on mouse click in the viewer
+ if(aNextWidget == NULL) {
+ activateWidget(NULL);
+ }
}
void XGUI_PropertyPanel::activateNextWidget()
QPushButton* anOkBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
anOkBtn->setEnabled(isEnabled);
}
+
+void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget)
+{
+ if(myActiveWidget) {
+ myActiveWidget->setHighlighted(false);
+ }
+ if(theWidget) {
+ theWidget->setHighlighted(true);
+ }
+ myActiveWidget = theWidget;
+ emit widgetActivated(theWidget);
+}
// Enables / disables "ok" ("accept") button
void setAcceptEnabled(bool);
-signals:
+ protected slots:
+ // Makes the given widget active, highlights it and removes
+ // highlighting from the previous active widget
+ // emits widgetActivated(theWidget) signal
+ void activateWidget(ModuleBase_ModelWidget* theWidget);
+
+ signals:
/// Signal about the point 2d set to the feature
/// \param the feature
/// \param the attribute of the feature
void storedPoint2D(ObjectPtr theFeature, const std::string& theAttribute);
+
private:
QWidget* myCustomWidget;
QList<ModuleBase_ModelWidget*> myWidgets;
//! Returns list of nested actions according to the given command ID
virtual QStringList nestedActions(const QString& theId) const = 0;
+ //! Set the document kind of the action by the given command Id
+ //! \param theId - the command ID
+ //! \param theKind - the document kind
+ virtual void setDocumentKind(const QString& theId, const QString& theKind) = 0;
+
+ //! Returns the document kind of the action by the given command ID
+ virtual QString documentKind(const QString& theId) const = 0;
+
//! Returns interface to Salome viewer
virtual ModuleBase_IViewer* viewer() const = 0;
QIntList aModes;
for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
ObjectPtr aObj = (*aIt);
- if (!aObj->data() || !aObj->data()->isValid() || aObj->document()->isConcealed(aObj))
+ bool aHide = !aObj->data() || !aObj->data()->isValid();
+ if (!aHide) { // check that this is not hidden result
+ ResultPtr aRes = boost::dynamic_pointer_cast<ModelAPI_Result>(aObj);
+ aHide = aRes && aRes->isConcealed();
+ }
+ if (aHide)
myDisplayer->erase(aObj, false);
else {
if (myDisplayer->isVisible(aObj)) {
// it doesn't stored in the operation mgr and doesn't displayed
} else if (myOperationMgr->hasOperation()) {
ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
- if (!(*aIt)->document()->isConcealed(*aIt) &&
- aOperation->hasObject(*aIt)) { // Display only current operation results
+ if (aOperation->hasObject(*aIt)) { // Display only current operation results
myDisplayer->display(*aIt, false);
isDisplayed = true;
}
QKeySequence(),
isUsePropPanel);
salomeConnector()->setNestedActions(aFeatureId, aNestedFeatures.split(" ", QString::SkipEmptyParts));
+ salomeConnector()->setDocumentKind(aFeatureId, QString::fromStdString(theMessage->documentKind()));
+
myActionsMgr->addCommand(aAction);
myModule->featureCreated(aAction);
} else {
connect(aCancelBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onAbortOperation()));
connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)), myOperationMgr,
SLOT(onKeyReleased(QKeyEvent*)));
- //connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), myOperationMgr,
- // SLOT(onWidgetActivated(ModuleBase_ModelWidget*)));
- //connect(myOperationMgr, SIGNAL(activateNextWidget(ModuleBase_ModelWidget*)), myPropertyPanel,
- // SLOT(onActivateNextWidget(ModuleBase_ModelWidget*)));
connect(myOperationMgr, SIGNAL(operationValidated(bool)), myPropertyPanel,
SLOT(setAcceptEnabled(bool)));