{
}
-bool GeomAPI_Shape::isNull()
+bool GeomAPI_Shape::isNull() const
{
return MY_SHAPE->IsNull() == Standard_True;
}
+bool GeomAPI_Shape::isEqual(const boost::shared_ptr<GeomAPI_Shape> theShape) const
+{
+ if (isNull())
+ return theShape->isNull();
+ if (theShape->isNull())
+ return false;
+
+ return MY_SHAPE->IsEqual(theShape->impl<TopoDS_Shape>()) == Standard_True;
+}
+
bool GeomAPI_Shape::isVertex() const
{
const TopoDS_Shape& aShape = const_cast<GeomAPI_Shape*>(this)->impl<TopoDS_Shape>();
#define GeomAPI_Shape_H_
#include <GeomAPI_Interface.h>
+#include <boost/shared_ptr.hpp>
/**\class GeomAPI_Shape
* \ingroup DataModel
/// Creation of empty (null) shape
GeomAPI_Shape();
- bool isNull();
+ bool isNull() const;
+
+ /// Returns whether the shapes are equal
+ virtual bool isEqual(const boost::shared_ptr<GeomAPI_Shape> theShape) const;
/// Returns whether the shape is a vertex
virtual bool isVertex() const;
};
#endif
-
Model_AttributeBoolean.h
Model_AttributeString.h
Model_AttributeInteger.h
+ Model_AttributeSelection.h
Model_Events.h
Model_Update.h
Model_Validator.h
Model_AttributeBoolean.cpp
Model_AttributeString.cpp
Model_AttributeInteger.cpp
+ Model_AttributeSelection.cpp
Model_Events.cpp
Model_Update.cpp
Model_Validator.cpp
ADD_DEFINITIONS(-DMODEL_EXPORTS ${CAS_DEFINITIONS} ${BOOST_DEFINITIONS})
-ADD_LIBRARY(Model MODULE ${PROJECT_SOURCES} ${PROJECT_HEADERS})
+ADD_LIBRARY(Model SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS})
TARGET_LINK_LIBRARIES(Model ${PROJECT_LIBRARIES})
INCLUDE_DIRECTORIES(
MODEL_EXPORT Model_AttributeReference(TDF_Label& theLabel);
friend class Model_Data;
+ friend class Model_AttributeSelection;
};
#endif
--- /dev/null
+// File: Model_AttributeSelection.h
+// Created: 2 Oct 2014
+// Author: Mikhail PONIKAROV
+
+#include "Model_AttributeSelection.h"
+#include "Model_Application.h"
+#include "Model_Events.h"
+#include "Model_Data.h"
+#include <ModelAPI_Feature.h>
+
+#include <TNaming_Selector.hxx>
+#include <TNaming_NamedShape.hxx>
+#include <TopoDS_Shape.hxx>
+
+using namespace std;
+
+void Model_AttributeSelection::setValue(const ResultBodyPtr& theContext,
+ const boost::shared_ptr<GeomAPI_Shape>& theSubShape)
+{
+ const boost::shared_ptr<GeomAPI_Shape>& anOldShape = value();
+ bool isOldShape =
+ (theSubShape == anOldShape || (theSubShape && anOldShape && theSubShape->isEqual(anOldShape)));
+ if (isOldShape) return; // shape is the same, so context is also unchanged
+ // update the referenced object if needed
+ bool isOldContext = theContext == myRef.value();
+ if (!isOldContext)
+ myRef.setValue(theContext);
+
+ // perform the selection
+ TNaming_Selector aSel(myRef.myRef->Label());
+ TopoDS_Shape aNewShape = theSubShape ? theSubShape->impl<TopoDS_Shape>() : TopoDS_Shape();
+ TopoDS_Shape aContext = theContext->shape()->impl<TopoDS_Shape>();
+ aSel.Select(aNewShape, aContext);
+ myIsInitialized = true;
+
+ owner()->data()->sendAttributeUpdated(this);
+}
+
+boost::shared_ptr<GeomAPI_Shape> Model_AttributeSelection::value()
+{
+ boost::shared_ptr<GeomAPI_Shape> aResult;
+ if (myIsInitialized) {
+ Handle(TNaming_NamedShape) aSelection;
+ if (myRef.myRef->Label().FindAttribute(TNaming_NamedShape::GetID(), aSelection)) {
+ TopoDS_Shape aSelShape = aSelection->Get();
+ aResult->setImpl(&aSelShape);
+ }
+ }
+ return aResult;
+}
+
+Model_AttributeSelection::Model_AttributeSelection(TDF_Label& theLabel)
+ : myRef(theLabel)
+{
+ myIsInitialized = myRef.isInitialized();
+}
+
+ResultBodyPtr Model_AttributeSelection::context() {
+ return boost::dynamic_pointer_cast<ModelAPI_ResultBody>(myRef.value());
+}
--- /dev/null
+// File: Model_AttributeSelection.h
+// Created: 8 May 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef Model_AttributeSelection_H_
+#define Model_AttributeSelection_H_
+
+#include "Model.h"
+#include "Model_AttributeReference.h"
+#include <ModelAPI_AttributeSelection.h>
+
+/**\class Model_AttributeSelection
+ * \ingroup DataModel
+ * \brief Attribute that contains reference to the sub-shape of some result, the selected shape.
+ */
+
+class Model_AttributeSelection : public ModelAPI_AttributeSelection
+{
+ Model_AttributeReference myRef; ///< The reference functionality reusage
+public:
+ /// Defines the result and its selected sub-shape
+ MODEL_EXPORT virtual void setValue(
+ const ResultBodyPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape);
+
+ /// Returns the selected subshape
+ MODEL_EXPORT virtual boost::shared_ptr<GeomAPI_Shape> value();
+
+ /// Returns the context of the selection (the whole shape owner)
+ MODEL_EXPORT virtual ResultBodyPtr context();
+
+protected:
+ /// Objects are created for features automatically
+ MODEL_EXPORT Model_AttributeSelection(TDF_Label& theLabel);
+
+ friend class Model_Data;
+};
+
+#endif
#include <TDataStd_Integer.hxx>
#include <TDataStd_Comment.hxx>
-#include <TDataStd_UAttribute.hxx>
#include <TDF_ChildIDIterator.hxx>
#include <TDataStd_ReferenceArray.hxx>
#include <TDataStd_HLabelArray1.hxx>
: myID(theID), myKind(theKind),
myDoc(new TDocStd_Document("BinOcaf")) // binary OCAF format
{
- myDoc->SetUndoLimit(UNDO_LIMIT);
+ myDoc->SetUndoLimit(UNDO_LIMIT);
myTransactionsAfterSave = 0;
myNestedNum = -1;
myExecuteFeatures = true;
- //myDoc->SetNestedTransactionMode();
// to have something in the document and avoid empty doc open/save problem
// in transaction for nesting correct working
myDoc->NewCommand();
}
}
-static const Standard_GUID ID_CONSTRUCTION("b59fa408-8ab1-42b8-980c-af5adeebe7e4");
-static const Standard_GUID ID_BODY("c1148e9a-9b17-4e9c-9160-18e918fd0013");
-static const Standard_GUID ID_PART("1b3319b9-3e0a-4298-a1dc-3fb5aaf9be59");
-
boost::shared_ptr<ModelAPI_ResultConstruction> Model_Document::createConstruction(
const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
{
TDF_Label aLab = resultLabel(theFeatureData, theIndex);
- TDataStd_UAttribute::Set(aLab, ID_CONSTRUCTION);
+ TDataStd_Comment::Set(aLab, ModelAPI_ResultConstruction::group().c_str());
ObjectPtr anOldObject = object(aLab);
boost::shared_ptr<ModelAPI_ResultConstruction> aResult;
if (anOldObject) {
const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
{
TDF_Label aLab = resultLabel(theFeatureData, theIndex);
- TDataStd_UAttribute::Set(aLab, ID_BODY);
+ TDataStd_Comment::Set(aLab, ModelAPI_ResultBody::group().c_str());
ObjectPtr anOldObject = object(aLab);
boost::shared_ptr<ModelAPI_ResultBody> aResult;
if (anOldObject) {
const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
{
TDF_Label aLab = resultLabel(theFeatureData, theIndex);
- TDataStd_UAttribute::Set(aLab, ID_PART);
+ TDataStd_Comment::Set(aLab, ModelAPI_ResultPart::group().c_str());
ObjectPtr anOldObject = object(aLab);
boost::shared_ptr<ModelAPI_ResultPart> aResult;
if (anOldObject) {
ResultPtr aNewBody;
if (aResSize <= aResIndex) {
TDF_Label anArgLab = aLabIter.Value();
- if (anArgLab.IsAttribute(ID_BODY)) {
- aNewBody = createBody(theFeature->data(), aResIndex);
- } else if (anArgLab.IsAttribute(ID_PART)) {
- aNewBody = createPart(theFeature->data(), aResIndex);
- } else if (!anArgLab.IsAttribute(ID_CONSTRUCTION) && anArgLab.FindChild(1).HasAttribute()) {
- Events_Error::send("Unknown type of result is found in the document");
+ Handle(TDataStd_Comment) aGroup;
+ if (anArgLab.FindAttribute(TDataStd_Comment::GetID(), aGroup)) {
+ if (aGroup->Get() == ModelAPI_ResultBody::group().c_str()) {
+ aNewBody = createBody(theFeature->data(), aResIndex);
+ } else if (aGroup->Get() == ModelAPI_ResultPart::group().c_str()) {
+ aNewBody = createPart(theFeature->data(), aResIndex);
+ } else if (aGroup->Get() != ModelAPI_ResultConstruction::group().c_str()) {
+ Events_Error::send(std::string("Unknown type of result is found in the document:") +
+ TCollection_AsciiString(aGroup->Get()).ToCString());
+ }
}
if (aNewBody) {
theFeature->setResult(aNewBody, aResIndex);
boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
if (aData) {
TDF_Label& aShapeLab = aData->shapeLab();
- // TODO: to add the naming mechanism for shape storage in the next iteration
+ // remove the previous history
+ clean();
+ aShapeLab.ForgetAllAttributes();
+ // store the new shape as primitive
TNaming_Builder aBuilder(aShapeLab);
if (!theShape)
return; // bad shape
{
return myOwner;
}
+
+void Model_ResultBody::clean()
+{
+ std::vector<TNaming_Builder*>::iterator aBuilder = myBuilders.begin();
+ for(; aBuilder != myBuilders.end(); aBuilder++)
+ delete *aBuilder;
+}
+
+Model_ResultBody::~Model_ResultBody()
+{
+ clean();
+}
+
+TNaming_Builder* Model_ResultBody::builder(const int theTag)
+{
+ if (myBuilders.size() < (unsigned int)theTag) {
+ myBuilders.insert(myBuilders.end(), theTag - myBuilders.size() + 1, NULL);
+ }
+ if (!myBuilders[theTag]) {
+ boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
+ myBuilders[theTag] = new TNaming_Builder(aData->shapeLab().FindChild(theTag));
+ }
+ return myBuilders[theTag];
+}
+
+void Model_ResultBody::generated(
+ const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag)
+{
+ TopoDS_Shape aShape = theNewShape->impl<TopoDS_Shape>();
+ builder(theTag)->Generated(aShape);
+}
+
+void Model_ResultBody::generated(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+ const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag)
+{
+ TopoDS_Shape anOldShape = theOldShape->impl<TopoDS_Shape>();
+ TopoDS_Shape aNewShape = theNewShape->impl<TopoDS_Shape>();
+ builder(theTag)->Generated(anOldShape, aNewShape);
+}
+
+
+void Model_ResultBody::modified(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+ const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag)
+{
+ TopoDS_Shape anOldShape = theOldShape->impl<TopoDS_Shape>();
+ TopoDS_Shape aNewShape = theNewShape->impl<TopoDS_Shape>();
+ builder(theTag)->Modify(anOldShape, aNewShape);
+}
+
+void Model_ResultBody::deleted(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+ const int theTag)
+{
+ TopoDS_Shape aShape = theOldShape->impl<TopoDS_Shape>();
+ builder(theTag)->Delete(aShape);
+}
#include "Model.h"
#include <ModelAPI_ResultBody.h>
+#include <vector>
+
+class TNaming_Builder;
/**\class ModelAPI_ResultBody
* \ingroup DataModel
class Model_ResultBody : public ModelAPI_ResultBody
{
boost::shared_ptr<ModelAPI_Feature> myOwner; ///< owner of this result
- public:
+ /// builders that tores the naming history: one per label to allow store several shapes to one
+ /// label; index in vector corresponds to the label tag
+ std::vector<TNaming_Builder*> myBuilders;
+public:
/// Stores the shape (called by the execution method).
MODEL_EXPORT virtual void store(const boost::shared_ptr<GeomAPI_Shape>& theShape);
/// Returns the shape-result produced by this feature
/// Returns the source feature of this result
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> owner();
- protected:
+ /// 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.
+ MODEL_EXPORT virtual void generated(const boost::shared_ptr<GeomAPI_Shape>& theNewShape,
+ const int theTag = 1);
+
+ /// Records the shape newShape which was generated from the shape oldShape during a topological
+ /// construction. As an example, consider the case of a face generated from an edge in
+ /// construction of a prism.
+ MODEL_EXPORT virtual void generated(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+ const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag = 1);
+
+
+ /// Records the shape newShape which is a modification of the shape oldShape.
+ /// As an example, consider the case of a face split or merged in a Boolean operation.
+ MODEL_EXPORT virtual void modified(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+ const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag = 1);
+
+ /// Records the shape oldShape which was deleted from the current label.
+ /// As an example, consider the case of a face removed by a Boolean operation.
+ MODEL_EXPORT virtual void deleted(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+ const int theTag = 1);
+
+ /// Removes the stored builders
+ MODEL_EXPORT virtual ~Model_ResultBody();
+
+protected:
/// Makes a body on the given feature
Model_ResultBody();
+ /// Removes the stored builders
+ void clean();
+
+ /// Returns (creates if necessary) the builder created on the needed tag of sub-label
+ TNaming_Builder* builder(const int theTag);
+
friend class Model_Document;
};
ModelAPI_AttributeRefList.h
ModelAPI_AttributeBoolean.h
ModelAPI_AttributeString.h
+ ModelAPI_AttributeSelection.h
ModelAPI_Events.h
ModelAPI_Validator.h
ModelAPI_FeatureValidator.h
#include "ModelAPI_AttributeString.h"
#include "ModelAPI_AttributeReference.h"
#include "ModelAPI_AttributeRefAttr.h"
+ #include "ModelAPI_AttributeSelection.h"
#include "ModelAPI_Validator.h"
#include "ModelAPI_AttributeRefList.h"
#include "ModelAPI_AttributeBoolean.h"
%shared_ptr(ModelAPI_AttributeRefAttr)
%shared_ptr(ModelAPI_AttributeRefList)
%shared_ptr(ModelAPI_AttributeBoolean)
+%shared_ptr(ModelAPI_AttributeSelection)
%shared_ptr(ModelAPI_Result)
%shared_ptr(ModelAPI_ResultConstruction)
%shared_ptr(ModelAPI_ResultBody)
%include "ModelAPI_AttributeString.h"
%include "ModelAPI_AttributeReference.h"
%include "ModelAPI_AttributeRefAttr.h"
-%include "ModelAPI_Validator.h"
+%include "ModelAPI_AttributeBoolean.h"
+%include "ModelAPI_AttributeSelection.h"
%include "ModelAPI_AttributeRefList.h"
+%include "ModelAPI_Validator.h"
%include "ModelAPI_Result.h"
%include "ModelAPI_ResultConstruction.h"
%include "ModelAPI_ResultBody.h"
%include "ModelAPI_ResultPart.h"
-%include "ModelAPI_AttributeBoolean.h"
%template(ObjectList) std::list<boost::shared_ptr<ModelAPI_Object> >;
%template(ResultList) std::list<boost::shared_ptr<ModelAPI_Result> >;
--- /dev/null
+// File: ModelAPI_AttributeSelection.h
+// Created: 2 Oct 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef ModelAPI_AttributeSelection_H_
+#define ModelAPI_AttributeSelection_H_
+
+#include "ModelAPI_Attribute.h"
+#include <ModelAPI_ResultBody.h>
+
+/**\class ModelAPI_AttributeSelection
+ * \ingroup DataModel
+ * \brief Attribute that contains reference to the sub-shape of some result, the selected shape.
+ */
+
+class ModelAPI_AttributeSelection : public ModelAPI_Attribute
+{
+ public:
+ /// Defines the result and its selected sub-shape
+ virtual void setValue(
+ const ResultBodyPtr& theContext, const boost::shared_ptr<GeomAPI_Shape>& theSubShape) = 0;
+
+ /// Returns the selected subshape
+ virtual boost::shared_ptr<GeomAPI_Shape> value() = 0;
+
+ /// Returns the context of the selection (the whole shape owner)
+ virtual ResultBodyPtr context() = 0;
+
+ /// Returns the type of this class of attributes
+ static std::string type()
+ {
+ return "Selection";
+ }
+
+ /// Returns the type of this class of attributes, not static method
+ virtual std::string attributeType()
+ {
+ return type();
+ }
+
+ /// To virtually destroy the fields of successors
+ virtual ~ModelAPI_AttributeSelection()
+ {
+ }
+
+ protected:
+ /// Objects are created for features automatically
+ MODELAPI_EXPORT ModelAPI_AttributeSelection()
+ {
+ }
+};
+
+#endif
/// Returns the group identifier of this object
virtual std::string groupName() = 0;
+ /// 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)
#include <string>
/**\class ModelAPI_ResultBody
- * \ingroup DataModel
- * \brief The body (shape) result of a feature.
- *
- * Provides a shape that may be displayed in the viewer.
- * May provide really huge results, so, working with this kind
- * of result must be optimized.
- */
+* \ingroup DataModel
+* \brief The body (shape) result of a feature.
+*
+* Provides a shape that may be displayed in the viewer.
+* May provide really huge results, so, working with this kind
+* of result must be optimized.
+*/
class ModelAPI_ResultBody : public ModelAPI_Result
{
- public:
+public:
/// Returns the group identifier of this result
virtual std::string groupName()
{
{
}
- protected:
+ /// 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>& theNewShape, const int theTag = 1) = 0;
+
+ /// Records the shape newShape which was generated from the shape oldShape during a topological
+ /// construction. As an example, consider the case of a face generated from an edge in
+ /// construction of a prism.
+ virtual void generated(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+ const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag = 1) = 0;
+
+ /// Records the shape newShape which is a modification of the shape oldShape.
+ /// As an example, consider the case of a face split or merged in a Boolean operation.
+ virtual void modified(const boost::shared_ptr<GeomAPI_Shape>& theOldShape,
+ const boost::shared_ptr<GeomAPI_Shape>& theNewShape, const int theTag = 1) = 0;
+
+ /// Records the shape oldShape which was deleted from the current label.
+ /// As an example, consider the case of a face removed by a Boolean operation.
+ virtual void deleted(
+ 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()
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_AttributeRefList.h>
#include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_AttributeSelection.h>
#include <ModelAPI_Events.h>
#include <ModelAPI_Validator.h>