#include "ModelAPI_Document.h"
#include "ModelAPI_Data.h"
#include "ModelAPI_AttributeDouble.h"
+#include <ModelAPI_ResultConstruction.h>
#include <GeomAlgoAPI_PointBuilder.h>
#include <GeomAPI_Pnt.h>
boost::shared_ptr<GeomAPI_Pnt> aPnt(new GeomAPI_Pnt(
data()->real(POINT_ATTR_X)->value(), data()->real(POINT_ATTR_Y)->value(), data()->real(POINT_ATTR_Z)->value()));
- data()->store(GeomAlgoAPI_PointBuilder::point(aPnt));
+ boost::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction();
+ aConstr->setShape(GeomAlgoAPI_PointBuilder::point(aPnt));
+ results().push_back(aConstr);
}
#include <ModelAPI_PluginManager.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_Data.h>
+#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_ResultBody.h>
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeReference.h>
#include <ModelAPI_AttributeBoolean.h>
FeaturePtr aFaceFeature = aFaceRef->value();
if (!aFaceFeature)
return;
- boost::shared_ptr<GeomAPI_Shape> aFace = aFaceFeature->data()->shape();
+ boost::shared_ptr<ModelAPI_ResultConstruction> aConstr =
+ boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aFaceFeature->firstResult());
+ if (!aConstr)
+ return;
+ boost::shared_ptr<GeomAPI_Shape> aFace = aConstr->shape();
if (!aFace)
return;
double aSize = data()->real(EXTRUSION_SIZE)->value();
if (data()->boolean(EXTRUSION_REVERSE)->value())
aSize = -aSize;
- data()->store(GeomAlgoAPI_Extrusion::makeExtrusion(aFace, aSize));
+ boost::shared_ptr<ModelAPI_ResultBody> aResult = document()->createBody();
+ aResult->store(GeomAlgoAPI_Extrusion::makeExtrusion(aFace, aSize));
+ document()->storeResult(data(), aResult);
+ setResult(aResult);
}
FEATURESPLUGIN_EXPORT virtual const std::string& getKind()
{ static std::string MY_KIND = FEATURES_EXTRUSION_KIND; return MY_KIND; }
- /// Returns to which group in the document must be added feature
- FEATURESPLUGIN_EXPORT virtual const std::string& getGroup()
- { static std::string MY_GROUP = "Construction"; return MY_GROUP; }
-
/// Creates a new part document if needed
FEATURESPLUGIN_EXPORT virtual void execute();
return aFeature;
}
-void Model_Document::storeResult(boost::shared_ptr<ModelAPI_Feature> theFeature,
+void Model_Document::storeResult(boost::shared_ptr<ModelAPI_Data> theFeatureData,
boost::shared_ptr<ModelAPI_Result> theResult, const int theResultIndex)
{
- initData(theResult, boost::dynamic_pointer_cast<Model_Data>(theFeature->data())->
+ initData(theResult, boost::dynamic_pointer_cast<Model_Data>(theFeatureData)->
label().Father().FindChild(TAG_FEATURE_RESULTS), theResultIndex);
}
boost::shared_ptr<ModelAPI_Document> aThis =
Model_Application::getApplication()->getDocument(myID);
boost::shared_ptr<Model_Data> aData(new Model_Data);
- aData->setLabel(theLab.FindChild(theTag));
+ aData->setLabel(theLab.FindChild(theTag + 1));
aData->setObject(theObj);
theObj->setDoc(aThis);
theObj->setData(aData);
boost::shared_ptr<ModelAPI_ResultConstruction> aResult(new Model_ResultConstruction());
return aResult;
}
+
+boost::shared_ptr<ModelAPI_ResultBody> Model_Document::createBody()
+{
+ boost::shared_ptr<ModelAPI_ResultBody> aResult(new Model_ResultBody());
+ return aResult;
+}
+
+boost::shared_ptr<ModelAPI_ResultPart> Model_Document::createPart()
+{
+ boost::shared_ptr<ModelAPI_ResultPart> aResult(new Model_ResultPart());
+ return aResult;
+}
MODEL_EXPORT virtual int size(const std::string& theGroupID);
//! Allows to store the result in the data tree of the document (attaches 'data' of result to tree)
- MODEL_EXPORT virtual void storeResult(boost::shared_ptr<ModelAPI_Feature> theFeature,
- boost::shared_ptr<ModelAPI_Result> theResult, const int theResultIndex);
+ MODEL_EXPORT virtual void storeResult(boost::shared_ptr<ModelAPI_Data> theFeatureData,
+ boost::shared_ptr<ModelAPI_Result> theResult, const int theResultIndex = 0);
/// Creates a construction cresults
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_ResultConstruction> createConstruction();
+ /// Creates a body results
+ MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_ResultBody> createBody();
+ /// Creates a part results
+ MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_ResultPart> createPart();
protected:
#include <TopoDS_Shape.hxx>
#include <GeomAPI_Shape.h>
-Model_ResultBody::Model_ResultBody(const boost::shared_ptr<ModelAPI_Feature>& theFeature)
- : myOwner(theFeature)
+Model_ResultBody::Model_ResultBody()
{
}
protected:
/// Makes a body on the given feature
- Model_ResultBody(const boost::shared_ptr<ModelAPI_Feature>& theFeature);
+ Model_ResultBody();
friend class Model_Document;
};
boost::shared_ptr<ModelAPI_Feature> myOwner; ///< owner of this result
boost::shared_ptr<GeomAPI_Shape> myShape; ///< shape of this result created "on the fly"
public:
- /// Returns the group identifier of this result
- virtual std::string group()
- {static std::string MY_GROUP = "Construction"; return MY_GROUP;}
/// Sets the result
MODEL_EXPORT virtual void setShape(boost::shared_ptr<GeomAPI_Shape> theShape);
/// Returns the shape-result produced by this feature
return boost::shared_ptr<ModelAPI_Feature>(); // return empty pointer
}
-Model_ResultPart::Model_ResultPart(
-const boost::shared_ptr<ModelAPI_Feature>& theFeature)
+Model_ResultPart::Model_ResultPart()
{
}
class Model_ResultPart : public ModelAPI_ResultPart
{
public:
- /// Returns the group identifier of this result
- virtual std::string group()
- {static std::string MY_GROUP = "Parts"; return MY_GROUP;}
/// Returns the part-document of this result
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Document> partDoc();
/// Part has no stored feature: this method returns NULL
protected:
/// makes a result on a temporary feature (an action)
- Model_ResultPart(const boost::shared_ptr<ModelAPI_Feature>& theFeature);
+ Model_ResultPart();
friend class Model_Document;
};
#include "ModelAPI.h"
#include "ModelAPI_Document.h"
#include "ModelAPI_PluginManager.h"
+ #include "ModelAPI_Object.h"
#include "ModelAPI_Feature.h"
#include "ModelAPI_Data.h"
- #include "ModelAPI_Object.h"
#include "ModelAPI_Attribute.h"
#include "ModelAPI_AttributeDocRef.h"
#include "ModelAPI_AttributeDouble.h"
%include <boost_shared_ptr.i>
%shared_ptr(ModelAPI_Document)
%shared_ptr(ModelAPI_PluginManager)
+%shared_ptr(ModelAPI_Object)
%shared_ptr(ModelAPI_Feature)
%shared_ptr(ModelAPI_Data)
-%shared_ptr(ModelAPI_Object)
%shared_ptr(ModelAPI_Attribute)
%shared_ptr(ModelAPI_AttributeDocRef)
%shared_ptr(ModelAPI_AttributeDouble)
// all supported interfaces
%include "ModelAPI_Document.h"
%include "ModelAPI_PluginManager.h"
+%include "ModelAPI_Object.h"
%include "ModelAPI_Feature.h"
%include "ModelAPI_Data.h"
-%include "ModelAPI_Object.h"
%include "ModelAPI_Attribute.h"
%include "ModelAPI_AttributeDocRef.h"
%include "ModelAPI_AttributeDouble.h"
class ModelAPI_Object;
class ModelAPI_Result;
class ModelAPI_ResultConstruction;
+class ModelAPI_ResultBody;
+class ModelAPI_ResultPart;
+class ModelAPI_Data;
/**\class Model_Document
* \ingroup DataModel
/// Creates a construction cresults
virtual boost::shared_ptr<ModelAPI_ResultConstruction> createConstruction() = 0;
+ /// Creates a body results
+ virtual boost::shared_ptr<ModelAPI_ResultBody> createBody() = 0;
+ /// Creates a part results
+ virtual boost::shared_ptr<ModelAPI_ResultPart> createPart() = 0;
+
+ //! Allows to store the result in the data tree of the document (attaches 'data' of result to tree)
+ virtual void storeResult(boost::shared_ptr<ModelAPI_Data> theFeatureData,
+ boost::shared_ptr<ModelAPI_Result> theResult, const int theResultIndex = 0) = 0;
+
protected:
/// Only for SWIG wrapping it is here
/// Computes or recomputes the results
virtual void execute() = 0;
- // returns the current results of the feature
+ /// returns the current results of the feature
std::list<boost::shared_ptr<ModelAPI_Result> >& results() {return myResults;}
- // returns the first result in the list or NULL reference
+ /// returns the first result in the list or NULL reference
boost::shared_ptr<ModelAPI_Result> firstResult()
{return myResults.size() ? *(myResults.begin()) : boost::shared_ptr<ModelAPI_Result>();}
+ /// sets the alone result
+ void setResult(const boost::shared_ptr<ModelAPI_Result>& theResult)
+ {myResults.clear(); myResults.push_back(theResult);}
/// Returns true if this feature must not be created: this is just an action
/// that is not stored in the features history and data model (like "delete part").
class ModelAPI_ResultConstruction : public ModelAPI_Result
{
public:
+ /// Returns the group identifier of this result
+ virtual std::string group()
+ {static std::string MY_GROUP = "Construction"; return MY_GROUP;}
+
/// Returns the shape-result produced by this feature
virtual boost::shared_ptr<GeomAPI_Shape>& shape() = 0;
class ModelAPI_ResultPart : public ModelAPI_Result
{
public:
+ /// Returns the group identifier of this result
+ virtual std::string group()
+ {static std::string MY_GROUP = "Parts"; return MY_GROUP;}
+
/// Returns the part-document of this result
virtual boost::shared_ptr<ModelAPI_Document> partDoc() = 0;
};
boost::shared_ptr<PartSetPlugin_Part> aSource; // searching for source document attribute
for(int a = aRoot->size(getGroup()) - 1; a >= 0; a--) {
aSource = boost::dynamic_pointer_cast<PartSetPlugin_Part>(
- aRoot->feature(getGroup(), a, true));
+ aRoot->object(ModelAPI_Feature::group(), a));
if (aSource->data()->docRef(PART_ATTR_DOC_REF)->value() == aPManager->currentDocument())
break;
aSource.reset();
}
if (aSource) {
boost::shared_ptr<ModelAPI_Document> aCopy =
- aPManager->copy(aSource->data()->docRef(PART_ATTR_DOC_REF)->value(), data()->getName());
+ aPManager->copy(aSource->data()->docRef(PART_ATTR_DOC_REF)->value(), data()->name());
aRef->setFeature(aSource);
}
}
#include "ModelAPI_Document.h"
#include "ModelAPI_Data.h"
#include "ModelAPI_AttributeDocRef.h"
+#include <ModelAPI_ResultPart.h>
using namespace std;
if (!aDocRef->value()) { // create a document if not yet created
boost::shared_ptr<ModelAPI_Document> aPartSetDoc =
ModelAPI_PluginManager::get()->rootDocument();
- aDocRef->setValue(aPartSetDoc->subDocument(data()->getName()));
+ aDocRef->setValue(aPartSetDoc->subDocument(data()->name()));
+ }
+ // create a result only once
+ if (results().empty()) {
+ boost::shared_ptr<ModelAPI_ResultPart> aResult = document()->createPart();
+ document()->storeResult(data(), aResult);
+ if (aResult->data()->name().empty())
+ aResult->data()->setName(data()->name());
}
}
boost::shared_ptr<ModelAPI_Document> aCurrent;
boost::shared_ptr<PartSetPlugin_Part> a;
for(int a = aRoot->size(getGroup()) - 1; a >= 0; a--) {
- FeaturePtr aFeature = aRoot->feature(getGroup(), a, true);
+ FeaturePtr aFeature =
+ boost::dynamic_pointer_cast<ModelAPI_Feature>(aRoot->object(ModelAPI_Feature::group(), a));
if (aFeature->getKind() == PARTSET_PART_KIND) {
boost::shared_ptr<PartSetPlugin_Part> aPart =
boost::static_pointer_cast<PartSetPlugin_Part>(aFeature);
// store the result
boost::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction();
aConstr->setShape(aCompound);
- results().push_back(aConstr);
+ setResult(aConstr);
}
}
// store the result
boost::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction();
aConstr->setShape(anEdge);
- results().push_back(aConstr);
+ setResult(aConstr);
}
}
}
boost::shared_ptr<GeomAPI_Shape> aPointShape = GeomAlgoAPI_PointBuilder::point(aPoint3D);
boost::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction();
aConstr->setShape(aPointShape);
- results().push_back(aConstr);
+ setResult(aConstr);
}
}
boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aFaces);
boost::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction();
aConstr->setShape(aCompound);
- results().push_back(aConstr);
+ setResult(aConstr);
return;
}
if (!data()->isValid())
boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aLoops);
boost::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction();
aConstr->setShape(aCompound);
- results().push_back(aConstr);
+ setResult(aConstr);
}
boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_Sketch::getAISObject(
{
const ModelAPI_ObjectUpdatedMessage* anUpdateMsg =
dynamic_cast<const ModelAPI_ObjectUpdatedMessage*>(theMessage);
- std::set< FeaturePtr > aFeatures = anUpdateMsg->features();
+ std::set< ObjectPtr > aFeatures = anUpdateMsg->features();
bool isModifiedEvt =
theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_MOVED);
if (!isModifiedEvt)
{
- std::set< FeaturePtr >::iterator aFeatIter;
+ std::set< ObjectPtr >::iterator aFeatIter;
for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++)
{
+ FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(*aFeatIter);
// Only sketches and constraints can be added by Create event
- const std::string& aFeatureKind = (*aFeatIter)->getKind();
+ const std::string& aFeatureKind = aFeature->getKind();
if (aFeatureKind.compare(SKETCH_KIND) == 0)
{
boost::shared_ptr<SketchPlugin_Feature> aSketch =
- boost::dynamic_pointer_cast<SketchPlugin_Feature>(*aFeatIter);
+ boost::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
if (aSketch)
changeWorkplane(aSketch);
continue;
}
boost::shared_ptr<SketchPlugin_Constraint> aConstraint =
- boost::dynamic_pointer_cast<SketchPlugin_Constraint>(*aFeatIter);
+ boost::dynamic_pointer_cast<SketchPlugin_Constraint>(aFeature);
if (aConstraint)
changeConstraint(aConstraint);
else
{
// Sketch plugin features can be only updated
boost::shared_ptr<SketchPlugin_Feature> aFeature =
- boost::dynamic_pointer_cast<SketchPlugin_Feature>(*aFeatIter);
+ boost::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
if (aFeature)
updateEntity(aFeature);
}
}
else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED))
{
- const ModelAPI_FeatureDeletedMessage* aDeleteMsg =
- dynamic_cast<const ModelAPI_FeatureDeletedMessage*>(theMessage);
+ const ModelAPI_ObjectDeletedMessage* aDeleteMsg =
+ dynamic_cast<const ModelAPI_ObjectDeletedMessage*>(theMessage);
const std::set<std::string>& aFeatureGroups = aDeleteMsg->groups();
// Find SKETCH_KIND in groups. The constraint groups should be updated when an object removed from Sketch