#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(data());
+ aConstr->setShape(GeomAlgoAPI_PointBuilder::point(aPnt));
+ setResult(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>
boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(data()->attribute(FeaturesPlugin_Extrusion::FACE_ID()));
if (!aFaceRef)
return;
- FeaturePtr aFaceFeature = aFaceRef->value();
- if (!aFaceFeature)
+ boost::shared_ptr<ModelAPI_ResultConstruction> aConstr =
+ boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aFaceRef->value());
+ if (!aConstr)
return;
- boost::shared_ptr<GeomAPI_Shape> aFace = aFaceFeature->data()->shape();
+ boost::shared_ptr<GeomAPI_Shape> aFace = aConstr->shape();
if (!aFace)
return;
double aSize = data()->real(FeaturesPlugin_Extrusion::SIZE_ID())->value();
if (data()->boolean(FeaturesPlugin_Extrusion::REVERSE_ID())->value())
aSize = -aSize;
- data()->store(GeomAlgoAPI_Extrusion::makeExtrusion(aFace, aSize));
+ boost::shared_ptr<ModelAPI_ResultBody> aResult = document()->createBody(data());
+ aResult->store(GeomAlgoAPI_Extrusion::makeExtrusion(aFace, aSize));
+ setResult(aResult);
}
FEATURESPLUGIN_EXPORT virtual const std::string& getKind()
{ static std::string MY_KIND = FeaturesPlugin_Extrusion::ID(); 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();
Model_Document.h
Model_PluginManager.h
Model_Data.h
- Model_Object.h
Model_AttributeDouble.h
Model_AttributeDocRef.h
Model_AttributeReference.h
Model_Events.h
Model_Update.h
Model_Validator.h
+ Model_ResultBody.h
+ Model_ResultConstruction.h
+ Model_ResultPart.h
)
SET(PROJECT_SOURCES
Model_Document.cpp
Model_PluginManager.cpp
Model_Data.cpp
- Model_Object.cpp
Model_AttributeDouble.cpp
Model_AttributeDocRef.cpp
Model_AttributeReference.cpp
Model_Events.cpp
Model_Update.cpp
Model_Validator.cpp
+ Model_ResultBody.cpp
+ Model_ResultConstruction.cpp
+ Model_ResultPart.cpp
)
SET(PROJECT_LIBRARIES
using namespace std;
-bool Model_AttributeRefAttr::isFeature()
+bool Model_AttributeRefAttr::isObject()
{
return myID->Get().Length() == 0;
}
boost::shared_ptr<Model_Data> aData =
boost::dynamic_pointer_cast<Model_Data>(theAttr->owner()->data());
string anID = aData->id(theAttr);
- if (myIsInitialized && feature() == theAttr->owner() && myID->Get().IsEqual(anID.c_str()))
+ if (myIsInitialized && object() == theAttr->owner() && myID->Get().IsEqual(anID.c_str()))
return; // nothing is changed
myRef->Set(aData->label());
boost::shared_ptr<ModelAPI_Attribute> Model_AttributeRefAttr::attr()
{
- FeaturePtr aFeature = feature();
- if (aFeature) {
+ ObjectPtr anObj = object();
+ if (anObj) {
boost::shared_ptr<Model_Data> aData =
- boost::dynamic_pointer_cast<Model_Data>(aFeature->data());
+ boost::dynamic_pointer_cast<Model_Data>(anObj->data());
return aData->attribute(TCollection_AsciiString(myID->Get()).ToCString());
}
// not initialized
return boost::shared_ptr<ModelAPI_Attribute>();
}
-void Model_AttributeRefAttr::setFeature(FeaturePtr theFeature)
+void Model_AttributeRefAttr::setObject(ObjectPtr theObject)
{
- if (!myIsInitialized || myID->Get().Length() != 0 || feature() != theFeature) {
+ if (!myIsInitialized || myID->Get().Length() != 0 || object() != theObject) {
boost::shared_ptr<Model_Data> aData =
- boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
+ boost::dynamic_pointer_cast<Model_Data>(theObject->data());
myRef->Set(aData->label());
myID->Set(""); // feature is identified by the empty ID
owner()->data()->sendAttributeUpdated(this);
}
}
-FeaturePtr Model_AttributeRefAttr::feature()
+ObjectPtr Model_AttributeRefAttr::object()
{
if (myRef->Get() != myRef->Label()) { // initialized
boost::shared_ptr<Model_Document> aDoc =
boost::dynamic_pointer_cast<Model_Document>(owner()->document());
if (aDoc) {
TDF_Label aRefLab = myRef->Get();
- TDF_Label aFeatureLab = aRefLab.Father();
- return aDoc->feature(aRefLab);
+ TDF_Label anObjLab = aRefLab.Father();
+ return aDoc->object(aRefLab);
}
}
// not initialized
- return FeaturePtr();
+ return ObjectPtr();
}
Model_AttributeRefAttr::Model_AttributeRefAttr(TDF_Label& theLabel)
///< ID of the referenced attirbute (empty if this is a reference to a feature)
Handle_TDataStd_Comment myID;
public:
- /// Returns true if this attribute references to a feature (not to the attribute)
- MODEL_EXPORT virtual bool isFeature();
+ /// Returns true if this attribute references to a object (not to the attribute)
+ MODEL_EXPORT virtual bool isObject();
/// Defines the reference to the attribute
MODEL_EXPORT virtual void setAttr(boost::shared_ptr<ModelAPI_Attribute> theAttr);
/// Returns attribute referenced from this attribute
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Attribute> attr();
- /// Defines the reference to the feature
- MODEL_EXPORT virtual void setFeature(FeaturePtr theFeature);
+ /// Defines the reference to the object
+ MODEL_EXPORT virtual void setObject(ObjectPtr theFeature);
- /// Returns feature referenced from this attribute
- MODEL_EXPORT virtual FeaturePtr feature();
+ /// Returns object referenced from this attribute
+ MODEL_EXPORT virtual ObjectPtr object();
protected:
/// Objects are created for features automatically
using namespace std;
-void Model_AttributeRefList::append(FeaturePtr theFeature)
+void Model_AttributeRefList::append(ObjectPtr theObject)
{
boost::shared_ptr<Model_Data> aData =
- boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
+ boost::dynamic_pointer_cast<Model_Data>(theObject->data());
myRef->Append(aData->label());
owner()->data()->sendAttributeUpdated(this);
}
-void Model_AttributeRefList::remove(FeaturePtr theFeature)
+void Model_AttributeRefList::remove(ObjectPtr theObject)
{
boost::shared_ptr<Model_Data> aData =
- boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
+ boost::dynamic_pointer_cast<Model_Data>(theObject->data());
myRef->Remove(aData->label());
owner()->data()->sendAttributeUpdated(this);
return myRef->Extent();
}
-list<FeaturePtr> Model_AttributeRefList::list()
+list<ObjectPtr> Model_AttributeRefList::list()
{
- std::list< FeaturePtr > aResult;
+ std::list< ObjectPtr > aResult;
boost::shared_ptr<Model_Document> aDoc =
boost::dynamic_pointer_cast<Model_Document>(owner()->document());
if (aDoc) {
const TDF_LabelList& aList = myRef->List();
for(TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next()) {
- aResult.push_back(aDoc->feature(aLIter.Value()));
+ aResult.push_back(aDoc->object(aLIter.Value()));
}
}
return aResult;
Handle_TDataStd_ReferenceList myRef; ///< references to the features labels
public:
/// Appends the feature to the end of a list
- MODEL_EXPORT virtual void append(FeaturePtr theFeature);
+ MODEL_EXPORT virtual void append(ObjectPtr theObject);
/// Erases the first meet of the feature in the list
- MODEL_EXPORT virtual void remove(FeaturePtr theFeature);
+ MODEL_EXPORT virtual void remove(ObjectPtr theObject);
/// Returns number of features in the list
MODEL_EXPORT virtual int size();
/// Returns the list of features
- MODEL_EXPORT virtual std::list<FeaturePtr > list();
+ MODEL_EXPORT virtual std::list<ObjectPtr > list();
protected:
/// Objects are created for features automatically
using namespace std;
-void Model_AttributeReference::setValue(FeaturePtr theFeature)
+void Model_AttributeReference::setValue(ObjectPtr theObject)
{
- if (!myIsInitialized || value() != theFeature) {
+ if (!myIsInitialized || value() != theObject) {
boost::shared_ptr<Model_Data> aData =
- boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
+ boost::dynamic_pointer_cast<Model_Data>(theObject->data());
if (myRef.IsNull()) {
boost::shared_ptr<Model_Data> aMyData =
boost::dynamic_pointer_cast<Model_Data>(owner()->data());
}
}
-FeaturePtr Model_AttributeReference::value()
+ObjectPtr Model_AttributeReference::value()
{
if (!myRef.IsNull()) {
boost::shared_ptr<Model_Document> aDoc =
boost::dynamic_pointer_cast<Model_Document>(owner()->document());
if (aDoc) {
TDF_Label aRefLab = myRef->Get();
- return aDoc->feature(aRefLab);
+ return aDoc->object(aRefLab);
}
}
// not initialized
{
Handle_TDF_Reference myRef; ///< references to the feature label
public:
- /// Defines the feature referenced from this attribute
- MODEL_EXPORT virtual void setValue(FeaturePtr theFeature);
+ /// Defines the object referenced from this attribute
+ MODEL_EXPORT virtual void setValue(ObjectPtr theObject);
- /// Returns feature referenced from this attribute
- MODEL_EXPORT virtual FeaturePtr value();
+ /// Returns object referenced from this attribute
+ MODEL_EXPORT virtual ObjectPtr value();
protected:
/// Objects are created for features automatically
#include <TDataStd_Name.hxx>
#include "Model_Events.h"
#include <Events_Loop.h>
+#include <Events_Error.h>
using namespace std;
myLab = theLab;
}
-string Model_Data::getName()
+string Model_Data::name()
{
Handle(TDataStd_Name) aName;
if (myLab.FindAttribute(TDataStd_Name::GetID(), aName))
aName->Set(theName.c_str());
}
if (isModified) {
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
- ModelAPI_EventCreator::get()->sendUpdated(myFeature, anEvent, false);
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
+ ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent, false);
}
}
if (anAttr) {
myAttrs[theID] = boost::shared_ptr<ModelAPI_Attribute>(anAttr);
- anAttr->setFeature(myFeature);
+ anAttr->setObject(myObject);
+ }
+ else {
+ Events_Error::send("Can not create unknown type of attribute " + theAttrType);
}
- else
- ; // TODO: generate error on unknown attribute request and/or add mechanism for customization
}
boost::shared_ptr<ModelAPI_AttributeDocRef> Model_Data::docRef(const string theID)
void Model_Data::sendAttributeUpdated(ModelAPI_Attribute* theAttr)
{
theAttr->setInitialized();
- static const Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
- ModelAPI_EventCreator::get()->sendUpdated(myFeature, anEvent);
-}
-
-#include <TNaming_Builder.hxx>
-#include <TNaming_NamedShape.hxx>
-#include <TopoDS_Shape.hxx>
-#include <GeomAPI_Shape.h>
-
-void Model_Data::store(const boost::shared_ptr<GeomAPI_Shape>& theShape)
-{
- // the simplest way is to keep this attribute here, on Data
- // TODO: add naming structure in separated document for shape storage
- TNaming_Builder aBuilder(myLab);
- if (!theShape) return; // bad shape
- TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
- if (aShape.IsNull()) return; // null shape inside
-
- aBuilder.Generated(aShape);
-}
-
-boost::shared_ptr<GeomAPI_Shape> Model_Data::shape()
-{
- Handle(TNaming_NamedShape) aName;
- if (myLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
- TopoDS_Shape aShape = aName->Get();
- if (!aShape.IsNull()) {
- boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
- aRes->setImpl(new TopoDS_Shape(aShape));
- return aRes;
- }
- }
- return boost::shared_ptr<GeomAPI_Shape>();
+ static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
+ ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent);
}
/// All attributes of the object identified by the attribute ID
std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> > myAttrs;
- /// needed here to emit signal that feature changed on change of the attribute
- FeaturePtr myFeature;
+ /// needed here to emit signal that object changed on change of the attribute
+ ObjectPtr myObject;
Model_Data();
public:
/// Returns the name of the feature visible by the user in the object browser
- MODEL_EXPORT virtual std::string getName();
+ MODEL_EXPORT virtual std::string name();
/// Defines the name of the feature visible by the user in the object browser
MODEL_EXPORT virtual void setName(std::string theName);
/// Returns the attribute that references to another document
/// Returns true if it is correctly connected t othe data model
MODEL_EXPORT virtual bool isValid();
- /// 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
- MODEL_EXPORT virtual boost::shared_ptr<GeomAPI_Shape> shape();
+ /// Returns the label where the shape must be stored (used in ResultBody)
+ TDF_Label& shapeLab() {return myLab;}
/// Initializes object by the attributes: must be called just after the object is created
/// for each attribute of the object
/// Puts feature to the document data sub-structure
MODEL_EXPORT void setLabel(TDF_Label& theLab);
- /// Sets the feature of this data
- MODEL_EXPORT virtual void setFeature(FeaturePtr theFeature)
- {myFeature = theFeature;}
+ /// Sets the object of this data
+ MODEL_EXPORT virtual void setObject(ObjectPtr theObject)
+ {myObject = theObject;}
};
#endif
// Author: Mikhail PONIKAROV
#include <Model_Document.h>
-#include <ModelAPI_Feature.h>
#include <Model_Data.h>
-#include <Model_Object.h>
#include <Model_Application.h>
#include <Model_PluginManager.h>
#include <Model_Events.h>
+#include <Model_ResultPart.h>
+#include <Model_ResultConstruction.h>
+#include <Model_ResultBody.h>
#include <Events_Loop.h>
#include <Events_Error.h>
#include <TDataStd_ReferenceArray.hxx>
#include <TDataStd_HLabelArray1.hxx>
#include <TDataStd_Name.hxx>
+#include <TDF_Reference.hxx>
#include <climits>
#ifndef WIN32
static const int UNDO_LIMIT = 10; // number of possible undo operations
static const int TAG_GENERAL = 1; // general properties tag
-static const int TAG_OBJECTS = 2; // tag of the objects sub-tree (features)
+static const int TAG_OBJECTS = 2; // tag of the objects sub-tree (features, results)
static const int TAG_HISTORY = 3; // tag of the history sub-tree (python dump)
-using namespace std;
+// feature sub-labels
+static const int TAG_FEATURE_ARGUMENTS = 1; ///< where the arguments are located
+static const int TAG_FEATURE_RESULTS = 2; ///< where the results are located
/// Returns the file name of this document by the nameof directory and identifuer of a document
-static TCollection_ExtendedString DocFileName(const char* theFileName, const string& theID)
+static TCollection_ExtendedString DocFileName(const char* theFileName, const std::string& theID)
{
TCollection_ExtendedString aPath ((const Standard_CString)theFileName);
aPath += _separator_;
catch (Standard_Failure)
{
Handle(Standard_Failure) aFail = Standard_Failure::Caught();
- Events_Error::send(string("Exception in opening of document: ") + aFail->GetMessageString());
+ Events_Error::send(std::string("Exception in opening of document: ") + aFail->GetMessageString());
return false;
}
bool isError = aStatus != PCDM_RS_OK;
switch (aStatus)
{
case PCDM_RS_UnknownDocument:
- Events_Error::send(string("Can not open document: PCDM_RS_UnknownDocument")); break;
+ Events_Error::send(std::string("Can not open document: PCDM_RS_UnknownDocument")); break;
case PCDM_RS_AlreadyRetrieved:
- Events_Error::send(string("Can not open document: PCDM_RS_AlreadyRetrieved")); break;
+ Events_Error::send(std::string("Can not open document: PCDM_RS_AlreadyRetrieved")); break;
case PCDM_RS_AlreadyRetrievedAndModified:
- Events_Error::send(string("Can not open document: PCDM_RS_AlreadyRetrievedAndModified")); break;
+ Events_Error::send(
+ std::string("Can not open document: PCDM_RS_AlreadyRetrievedAndModified"));
+ break;
case PCDM_RS_NoDriver:
- Events_Error::send(string("Can not open document: PCDM_RS_NoDriver")); break;
+ Events_Error::send(std::string("Can not open document: PCDM_RS_NoDriver")); break;
case PCDM_RS_UnknownFileDriver:
- Events_Error::send(string("Can not open document: PCDM_RS_UnknownFileDriver")); break;
+ Events_Error::send(std::string("Can not open document: PCDM_RS_UnknownFileDriver")); break;
case PCDM_RS_OpenError:
- Events_Error::send(string("Can not open document: PCDM_RS_OpenError")); break;
+ Events_Error::send(std::string("Can not open document: PCDM_RS_OpenError")); break;
case PCDM_RS_NoVersion:
- Events_Error::send(string("Can not open document: PCDM_RS_NoVersion")); break;
+ Events_Error::send(std::string("Can not open document: PCDM_RS_NoVersion")); break;
case PCDM_RS_NoModel:
- Events_Error::send(string("Can not open document: PCDM_RS_NoModel")); break;
+ Events_Error::send(std::string("Can not open document: PCDM_RS_NoModel")); break;
case PCDM_RS_NoDocument:
- Events_Error::send(string("Can not open document: PCDM_RS_NoDocument")); break;
+ Events_Error::send(std::string("Can not open document: PCDM_RS_NoDocument")); break;
case PCDM_RS_FormatFailure:
- Events_Error::send(string("Can not open document: PCDM_RS_FormatFailure")); break;
+ Events_Error::send(std::string("Can not open document: PCDM_RS_FormatFailure")); break;
case PCDM_RS_TypeNotFoundInSchema:
- Events_Error::send(string("Can not open document: PCDM_RS_TypeNotFoundInSchema")); break;
+ Events_Error::send(std::string("Can not open document: PCDM_RS_TypeNotFoundInSchema"));
+ break;
case PCDM_RS_UnrecognizedFileFormat:
- Events_Error::send(string("Can not open document: PCDM_RS_UnrecognizedFileFormat")); break;
+ Events_Error::send(std::string("Can not open document: PCDM_RS_UnrecognizedFileFormat"));
+ break;
case PCDM_RS_MakeFailure:
- Events_Error::send(string("Can not open document: PCDM_RS_MakeFailure")); break;
+ Events_Error::send(std::string("Can not open document: PCDM_RS_MakeFailure")); break;
case PCDM_RS_PermissionDenied:
- Events_Error::send(string("Can not open document: PCDM_RS_PermissionDenied")); break;
+ Events_Error::send(std::string("Can not open document: PCDM_RS_PermissionDenied")); break;
case PCDM_RS_DriverFailure:
- Events_Error::send(string("Can not open document: PCDM_RS_DriverFailure")); break;
+ Events_Error::send(std::string("Can not open document: PCDM_RS_DriverFailure")); break;
default:
- Events_Error::send(string("Can not open document: unknown error")); break;
+ Events_Error::send(std::string("Can not open document: unknown error")); break;
}
}
if (!isError) {
}
catch (Standard_Failure) {
Handle(Standard_Failure) aFail = Standard_Failure::Caught();
- Events_Error::send(string("Exception in saving of document: ") + aFail->GetMessageString());
+ Events_Error::send(std::string("Exception in saving of document: ") + aFail->GetMessageString());
return false;
}
bool isDone = aStatus == PCDM_SS_OK || aStatus == PCDM_SS_No_Obj;
switch (aStatus)
{
case PCDM_SS_DriverFailure:
- Events_Error::send(string("Can not save document: PCDM_SS_DriverFailure"));
+ Events_Error::send(std::string("Can not save document: PCDM_SS_DriverFailure"));
break;
case PCDM_SS_WriteFailure:
- Events_Error::send(string("Can not save document: PCDM_SS_WriteFailure"));
+ Events_Error::send(std::string("Can not save document: PCDM_SS_WriteFailure"));
break;
case PCDM_SS_Failure:
default:
- Events_Error::send(string("Can not save document: PCDM_SS_Failure"));
+ Events_Error::send(std::string("Can not save document: PCDM_SS_Failure"));
break;
}
}
myTransactionsAfterSave = 0;
if (isDone) { // save also sub-documents if any
- set<string>::iterator aSubIter = mySubs.begin();
+ std::set<std::string>::iterator aSubIter = mySubs.begin();
for(; aSubIter != mySubs.end() && isDone; aSubIter++)
isDone = subDocument(*aSubIter)->save(theFileName);
}
aPM->setCurrentDocument(aPM->rootDocument());
}
// close all subs
- set<string>::iterator aSubIter = mySubs.begin();
+ std::set<std::string>::iterator aSubIter = mySubs.begin();
for(; aSubIter != mySubs.end(); aSubIter++)
subDocument(*aSubIter)->close();
mySubs.clear();
myDoc->NewCommand();
}
// new command for all subs
- set<string>::iterator aSubIter = mySubs.begin();
+ std::set<std::string>::iterator aSubIter = mySubs.begin();
for(; aSubIter != mySubs.end(); aSubIter++)
subDocument(*aSubIter)->startOperation();
}
void Model_Document::finishOperation()
{
// just to be sure that everybody knows that changes were performed
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_CREATED));
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_DELETED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
if (myNestedNum != -1) // this nested transaction is owervritten
myNestedNum++;
}
// finish for all subs
- set<string>::iterator aSubIter = mySubs.begin();
+ std::set<std::string>::iterator aSubIter = mySubs.begin();
for(; aSubIter != mySubs.end(); aSubIter++)
subDocument(*aSubIter)->finishOperation();
}
}
synchronizeFeatures(true);
// abort for all subs
- set<string>::iterator aSubIter = mySubs.begin();
+ std::set<std::string>::iterator aSubIter = mySubs.begin();
for(; aSubIter != mySubs.end(); aSubIter++)
subDocument(*aSubIter)->abortOperation();
}
if (myDoc->GetAvailableUndos() > 0 && myNestedNum != 0 && myTransactionsAfterSave != 0 /* for omitting the first useless transaction */)
return true;
// check other subs contains operation that can be undoed
- set<string>::iterator aSubIter = mySubs.begin();
+ std::set<std::string>::iterator aSubIter = mySubs.begin();
for(; aSubIter != mySubs.end(); aSubIter++)
if (subDocument(*aSubIter)->canUndo())
return true;
myDoc->Undo();
synchronizeFeatures(true);
// undo for all subs
- set<string>::iterator aSubIter = mySubs.begin();
+ std::set<std::string>::iterator aSubIter = mySubs.begin();
for(; aSubIter != mySubs.end(); aSubIter++)
subDocument(*aSubIter)->undo();
}
if (myDoc->GetAvailableRedos() > 0)
return true;
// check other subs contains operation that can be redoed
- set<string>::iterator aSubIter = mySubs.begin();
+ std::set<std::string>::iterator aSubIter = mySubs.begin();
for(; aSubIter != mySubs.end(); aSubIter++)
if (subDocument(*aSubIter)->canRedo())
return true;
myTransactionsAfterSave++;
synchronizeFeatures(true);
// redo for all subs
- set<string>::iterator aSubIter = mySubs.begin();
+ std::set<std::string>::iterator aSubIter = mySubs.begin();
for(; aSubIter != mySubs.end(); aSubIter++)
subDocument(*aSubIter)->redo();
}
-FeaturePtr Model_Document::addFeature(string theID)
-{
- FeaturePtr aFeature =
- ModelAPI_PluginManager::get()->createFeature(theID);
- if (aFeature) {
- boost::dynamic_pointer_cast<Model_Document>(aFeature->documentToAdd())->addFeature(aFeature);
- } else {
- // TODO: generate error that feature is not created
- }
- return aFeature;
-}
-
/// Appenad to the array of references a new referenced label
static void AddToRefArray(TDF_Label& theArrayLab, TDF_Label& theReferenced) {
Handle(TDataStd_ReferenceArray) aRefs;
}
}
-void Model_Document::addFeature(const FeaturePtr theFeature)
+FeaturePtr Model_Document::addFeature(std::string theID)
{
- if (theFeature->isAction()) return; // do not add action to the data model
-
- boost::shared_ptr<ModelAPI_Document> aThis =
- Model_Application::getApplication()->getDocument(myID);
- TDF_Label aFeaturesLab = groupLabel(ModelAPI_Document::FEATURES_GROUP());
- TDF_Label aFeatureLab = aFeaturesLab.NewChild();
-
- // organize feature and data objects
- boost::shared_ptr<Model_Data> aData(new Model_Data);
- aData->setFeature(theFeature);
- aData->setLabel(aFeatureLab);
- theFeature->setDoc(aThis);
- theFeature->setData(aData);
- setUniqueName(theFeature);
- theFeature->initAttributes();
-
- // keep the feature ID to restore document later correctly
- TDataStd_Comment::Set(aFeatureLab, theFeature->getKind().c_str());
- myFeatures.push_back(theFeature);
- // store feature in the history of features array
- if (theFeature->isInHistory()) {
- AddToRefArray(aFeaturesLab, aFeatureLab);
+ TDF_Label anEmptyLab;
+ FeaturePtr anEmptyFeature;
+ FeaturePtr aFeature = ModelAPI_PluginManager::get()->createFeature(theID);
+ if (aFeature) {
+ TDF_Label aFeatureLab;
+ if (!aFeature->isAction()) {// do not add action to the data model
+ TDF_Label aFeaturesLab = groupLabel(ModelAPI_Feature::group());
+ aFeatureLab = aFeaturesLab.NewChild();
+ initData(aFeature, aFeatureLab, TAG_FEATURE_ARGUMENTS);
+ // keep the feature ID to restore document later correctly
+ TDataStd_Comment::Set(aFeatureLab, aFeature->getKind().c_str());
+ setUniqueName(aFeature);
+ myObjs[ModelAPI_Feature::group()].push_back(aFeature);
+ // store feature in the history of features array
+ if (aFeature->isInHistory()) {
+ AddToRefArray(aFeaturesLab, aFeatureLab);
+ }
+ }
+ if (!aFeature->isAction()) {// do not add action to the data model
+ // event: feature is added
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
+ ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
+ }
}
- // add featue to the group
- const std::string& aGroup = theFeature->getGroup();
- TDF_Label aGroupLab = groupLabel(aGroup);
- AddToRefArray(aGroupLab, aFeatureLab);
- // new name of this feature object by default equal to name of feature
- TDF_Label anObjLab = aGroupLab.NewChild();
- TCollection_ExtendedString aName(theFeature->data()->getName().c_str());
- TDataStd_Name::Set(anObjLab, aName);
- TDF_Label aGrLabChild = aGroupLab.FindChild(1);
- AddToRefArray(aGrLabChild, anObjLab); // reference to names is on the first sub
-
- // event: feature is added
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_CREATED);
- ModelAPI_EventCreator::get()->sendUpdated(theFeature, anEvent);
+ return aFeature;
}
/// Appenad to the array of references a new referenced label.
void Model_Document::removeFeature(FeaturePtr theFeature)
{
boost::shared_ptr<Model_Data> aData = boost::static_pointer_cast<Model_Data>(theFeature->data());
- TDF_Label aFeatureLabel = aData->label();
- // remove the object
- TDF_Label aGroupLabel = groupLabel(theFeature->getGroup());
- int aRemovedIndex = RemoveFromRefArray(aGroupLabel, aFeatureLabel);
- RemoveFromRefArray(aGroupLabel.FindChild(1), TDF_Label(), aRemovedIndex);
- // remove feature from the myFeatures list
- std::vector<FeaturePtr >::iterator aFIter = myFeatures.begin();
- while(aFIter != myFeatures.end()) {
- if (*aFIter == theFeature) {
- aFIter = myFeatures.erase(aFIter);
+ TDF_Label aFeatureLabel = aData->label().Father();
+ // remove feature from the myObjects list
+ std::vector<ObjectPtr>& aVec = myObjs[ModelAPI_Feature::group()];
+ std::vector<ObjectPtr>::iterator anIter = aVec.begin();
+ while(anIter != aVec.end()) {
+ if (*anIter == theFeature) {
+ anIter = aVec.erase(anIter);
} else {
- aFIter++;
+ anIter++;
}
}
// erase all attributes under the label of feature
aFeatureLabel.ForgetAllAttributes();
// remove it from the references array
- RemoveFromRefArray(groupLabel(ModelAPI_Document::FEATURES_GROUP()), aData->label());
+ RemoveFromRefArray(groupLabel(ModelAPI_Feature::group()), aData->label());
+
+ // event: feature is deleted
+ ModelAPI_EventCreator::get()->sendDeleted(theFeature->document(), ModelAPI_Feature::group());
+}
- // event: feature is added
- ModelAPI_EventCreator::get()->sendDeleted(theFeature->document(), theFeature->getGroup());
+/// returns the object group name by the object label
+static std::string groupName(TDF_Label theObjectLabel) {
+ TDF_Label aGroupLab = theObjectLabel.Father();
+ Handle(TDataStd_Comment) aComment;
+ if (aGroupLab.FindAttribute(TDataStd_Comment::GetID(), aComment))
+ return std::string(TCollection_AsciiString(aComment->Get()).ToCString());
+ return ""; // not found
}
FeaturePtr Model_Document::feature(TDF_Label& theLabel)
{
// iterate all features, may be optimized later by keeping labels-map
- vector<FeaturePtr >::iterator aFIter = myFeatures.begin();
- for(; aFIter != myFeatures.end(); aFIter++) {
+ std::vector<ObjectPtr>& aVec = myObjs[ModelAPI_Feature::group()];
+ std::vector<ObjectPtr>::iterator aFIter = aVec.begin();
+ for(; aFIter != aVec.end(); aFIter++) {
+ boost::shared_ptr<Model_Data> aData =
+ boost::dynamic_pointer_cast<Model_Data>((*aFIter)->data());
+ if (aData->label().IsEqual(theLabel))
+ return boost::dynamic_pointer_cast<ModelAPI_Feature>(*aFIter);
+ }
+ return FeaturePtr(); // not found
+}
+
+ObjectPtr Model_Document::object(TDF_Label& theLabel)
+{
+ // iterate all features, may be optimized later by keeping labels-map
+ std::vector<ObjectPtr>& aVec = myObjs[ModelAPI_Feature::group()];
+ std::vector<ObjectPtr>::iterator aFIter = aVec.begin();
+ for(; aFIter != aVec.end(); aFIter++) {
boost::shared_ptr<Model_Data> aData =
boost::dynamic_pointer_cast<Model_Data>((*aFIter)->data());
if (aData->label().IsEqual(theLabel))
return *aFIter;
+ std::list<boost::shared_ptr<ModelAPI_Result> >& aResults =
+ boost::dynamic_pointer_cast<ModelAPI_Feature>(*aFIter)->results();
+ std::list<boost::shared_ptr<ModelAPI_Result> >::iterator aRIter = aResults.begin();
+ for(; aRIter != aResults.end(); aRIter++) {
+ boost::shared_ptr<Model_Data> aResData =
+ boost::dynamic_pointer_cast<Model_Data>((*aRIter)->data());
+ if (aResData->label().IsEqual(theLabel))
+ return *aRIter;
+ }
}
return FeaturePtr(); // not found
}
-boost::shared_ptr<ModelAPI_Document> Model_Document::subDocument(string theDocID)
+boost::shared_ptr<ModelAPI_Document> Model_Document::subDocument(std::string theDocID)
{
// just store sub-document identifier here to manage it later
if (mySubs.find(theDocID) == mySubs.end())
return Model_Application::getApplication()->getDocument(theDocID);
}
-FeaturePtr Model_Document::feature(
- const string& theGroupID, const int theIndex, const bool isOperation)
+ObjectPtr Model_Document::object(const std::string& theGroupID, const int theIndex)
{
- TDF_Label aGroupLab = groupLabel(theGroupID);
- Handle(TDataStd_ReferenceArray) aRefs;
- if (aGroupLab.FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) {
- if (aRefs->Lower() <= theIndex && aRefs->Upper() >= theIndex) {
- TDF_Label aFeatureLab = aRefs->Value(theIndex);
- FeaturePtr aFeature = feature(aFeatureLab);
-
- if (theGroupID == ModelAPI_Document::FEATURES_GROUP() || isOperation) { // just returns the feature from the history
- return aFeature;
- } else { // create a new object from the group to return it
- Handle(TDataStd_Name) aName; // name of the object
- if (aGroupLab.FindChild(1).FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs))
- aRefs->Value(theIndex).FindAttribute(TDataStd_Name::GetID(), aName);
- boost::shared_ptr<Model_Object> anObj(new Model_Object(aFeature, aName));
- return anObj;
+ if (theGroupID == ModelAPI_Feature::group()) {
+ std::map<std::string, std::vector<ObjectPtr> >::iterator aFind = myObjs.find(theGroupID);
+ if (aFind != myObjs.end()) {
+ int aSize = aFind->second.size();
+ if (theIndex >= 0 && theIndex < aSize)
+ return aFind->second[theIndex];
+ }
+ } else {
+ // iterate all features in order to find the needed result
+ std::map<std::string, std::vector<ObjectPtr> >::iterator aFind =
+ myObjs.find(ModelAPI_Feature::group());
+ if (aFind != myObjs.end()) {
+ std::vector<ObjectPtr>::iterator aFIter = aFind->second.begin();
+ for(int anIndex = 0; aFIter != aFind->second.end(); aFIter++) {
+ const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults =
+ boost::dynamic_pointer_cast<ModelAPI_Feature>(*aFIter)->results();
+ std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
+ for(; aRIter != aResults.cend(); aRIter++) {
+ if ((*aRIter)->isInHistory() && (*aRIter)->groupName() == theGroupID) {
+ if (anIndex == theIndex)
+ return *aRIter;
+ anIndex++;
+ }
+ }
}
}
}
-
// not found
- return FeaturePtr();
+ return ObjectPtr();
}
-int Model_Document::size(const string& theGroupID)
+int Model_Document::size(const std::string& theGroupID)
{
- Handle(TDataStd_ReferenceArray) aRefs;
- if (groupLabel(theGroupID).FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs))
- return aRefs->Length();
+ int aResult = 0;
+ if (theGroupID == ModelAPI_Feature::group()) {
+ std::map<std::string, std::vector<ObjectPtr> >::iterator aFind = myObjs.find(theGroupID);
+ if (aFind != myObjs.end()) {
+ aResult = aFind->second.size();
+ }
+ } else {
+ // iterate all features in order to find the needed result
+ std::map<std::string, std::vector<ObjectPtr> >::iterator aFind =
+ myObjs.find(ModelAPI_Feature::group());
+ if (aFind != myObjs.end()) {
+ std::vector<ObjectPtr>::iterator aFIter = aFind->second.begin();
+ for(; aFIter != aFind->second.end(); aFIter++) {
+ const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults =
+ boost::dynamic_pointer_cast<ModelAPI_Feature>(*aFIter)->results();
+ std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
+ for(; aRIter != aResults.cend(); aRIter++) {
+ if ((*aRIter)->isInHistory() && (*aRIter)->groupName() == theGroupID) {
+ aResult++;
+ }
+ }
+ }
+ }
+ }
// group is not found
- return 0;
+ return aResult;
}
Model_Document::Model_Document(const std::string theID)
myDoc->CommitCommand();
}
-TDF_Label Model_Document::groupLabel(const string theGroup)
+TDF_Label Model_Document::groupLabel(const std::string theGroup)
{
// searching for existing
TCollection_ExtendedString aGroup(theGroup.c_str());
void Model_Document::setUniqueName(FeaturePtr theFeature)
{
- string aName; // result
- // iterate all features but also iterate group of this feature if object is not in history
- list<string> aGroups;
- aGroups.push_back(ModelAPI_Document::FEATURES_GROUP());
- if (!theFeature->isInHistory()) {
- aGroups.push_back(theFeature->getGroup());
+ std::string aName; // result
+ // first count all objects of such kind to start with index = count + 1
+ int a, aNumObjects = 0;
+ int aSize = size(ModelAPI_Feature::group());
+ for(a = 0; a < aSize; a++) {
+ if (boost::dynamic_pointer_cast<ModelAPI_Feature>(object(ModelAPI_Feature::group(), a))->
+ getKind() == theFeature->getKind())
+ aNumObjects++;
}
- for(list<string>::iterator aGIter = aGroups.begin(); aGIter != aGroups.end(); aGIter++) {
- // first count all objects of such kind to start with index = count + 1
- int a, aNumObjects = 0;
- int aSize = size(*aGIter);
- for(a = 0; a < aSize; a++) {
- if (feature(*aGIter, a)->getKind() == theFeature->getKind())
- aNumObjects++;
- }
- // generate candidate name
- stringstream aNameStream;
- aNameStream<<theFeature->getKind()<<"_"<<aNumObjects + 1;
- aName = aNameStream.str();
- // check this is unique, if not, increase index by 1
- for(a = 0; a < aSize;) {
- if (feature(*aGIter, a, true)->data()->getName() == aName) {
- aNumObjects++;
- stringstream aNameStream;
- aNameStream<<theFeature->getKind()<<"_"<<aNumObjects + 1;
- aName = aNameStream.str();
- // reinitialize iterator to make sure a new name is unique
- a = 0;
- } else a++;
- }
+ // generate candidate name
+ std::stringstream aNameStream;
+ aNameStream<<theFeature->getKind()<<"_"<<aNumObjects + 1;
+ aName = aNameStream.str();
+ // check this is unique, if not, increase index by 1
+ for(a = 0; a < aSize;) {
+ if (boost::dynamic_pointer_cast<ModelAPI_Feature>(object(ModelAPI_Feature::group(), a))
+ ->data()->name() == aName) {
+ aNumObjects++;
+ std::stringstream aNameStream;
+ aNameStream<<theFeature->getKind()<<"_"<<aNumObjects + 1;
+ aName = aNameStream.str();
+ // reinitialize iterator to make sure a new name is unique
+ a = 0;
+ } else a++;
}
theFeature->data()->setName(aName);
}
-//! Returns the object by the feature
-FeaturePtr Model_Document::objectByFeature(
- const FeaturePtr theFeature)
-{
- for(int a = 0; a < size(theFeature->getGroup()); a++) {
- boost::shared_ptr<Model_Object> anObj =
- boost::dynamic_pointer_cast<Model_Object>(feature(theFeature->getGroup(), a));
- if (anObj && anObj->featureRef() == theFeature) {
- return anObj;
- }
- }
- return FeaturePtr(); // not found
+void Model_Document::initData(ObjectPtr theObj, TDF_Label& theLab, const int theTag) {
+ 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 + 1));
+ aData->setObject(theObj);
+ theObj->setDoc(aThis);
+ theObj->setData(aData);
+ FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
+ if (aFeature) aFeature->initAttributes();
}
void Model_Document::synchronizeFeatures(const bool theMarkUpdated)
{
- boost::shared_ptr<ModelAPI_Document> aThis = Model_Application::getApplication()->getDocument(myID);
- // update features
- vector<FeaturePtr >::iterator aFIter = myFeatures.begin();
- // and in parallel iterate labels of features
- TDF_ChildIDIterator aFLabIter(groupLabel(ModelAPI_Document::FEATURES_GROUP()), TDataStd_Comment::GetID());
- while(aFIter != myFeatures.end() || aFLabIter.More()) {
- static const int INFINITE_TAG = INT_MAX; // no label means that it exists somwhere in infinite
- int aFeatureTag = INFINITE_TAG;
- if (aFIter != myFeatures.end()) { // existing tag for feature
- boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>((*aFIter)->data());
- aFeatureTag = aData->label().Tag();
- }
- int aDSTag = INFINITE_TAG;
- if (aFLabIter.More()) { // next label in DS is existing
- aDSTag = aFLabIter.Value()->Label().Tag();
- }
- if (aDSTag > aFeatureTag) { // feature is removed
- FeaturePtr aFeature = *aFIter;
- aFIter = myFeatures.erase(aFIter);
- // event: model is updated
- if (aFeature->isInHistory()) {
- ModelAPI_EventCreator::get()->sendDeleted(aThis, ModelAPI_Document::FEATURES_GROUP());
- }
- ModelAPI_EventCreator::get()->sendDeleted(aThis, aFeature->getGroup());
- } else if (aDSTag < aFeatureTag) { // a new feature is inserted
- // create a feature
- FeaturePtr aFeature = ModelAPI_PluginManager::get()->createFeature(
- TCollection_AsciiString(Handle(TDataStd_Comment)::DownCast(
- aFLabIter.Value())->Get()).ToCString());
-
- if (aFIter == myFeatures.end()) { // must be before "setData" to redo the sketch line correctly
- myFeatures.push_back(aFeature);
- aFIter = myFeatures.end();
- } else {
- aFIter++;
- myFeatures.insert(aFIter, aFeature);
+ boost::shared_ptr<ModelAPI_Document> aThis =
+ Model_Application::getApplication()->getDocument(myID);
+ // update all objects: iterate from the end: as they appeared in the list
+ std::map<std::string, std::vector<ObjectPtr> >::reverse_iterator aGroupIter = myObjs.rbegin();
+ for(; aGroupIter != myObjs.rend(); aGroupIter++) {
+ std::vector<ObjectPtr>::iterator anObjIter = aGroupIter->second.begin();
+ // and in parallel iterate labels of features
+ const std::string& aGroupName = aGroupIter->first;
+ TDF_ChildIDIterator aLabIter(groupLabel(aGroupName), TDataStd_Comment::GetID());
+ while(anObjIter != aGroupIter->second.end() || aLabIter.More()) {
+ static const int INFINITE_TAG = INT_MAX; // no label means that it exists somwhere in infinite
+ int aFeatureTag = INFINITE_TAG;
+ if (anObjIter != aGroupIter->second.end()) { // existing tag for feature
+ boost::shared_ptr<Model_Data> aData =
+ boost::dynamic_pointer_cast<Model_Data>((*anObjIter)->data());
+ aFeatureTag = aData->label().Tag();
}
- boost::shared_ptr<Model_Data> aData(new Model_Data);
- TDF_Label aLab = aFLabIter.Value()->Label();
- aData->setLabel(aLab);
- aData->setFeature(aFeature);
- aFeature->setDoc(aThis);
- aFeature->setData(aData);
- aFeature->initAttributes();
-
- // event: model is updated
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_CREATED);
- ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
- FeaturePtr anObj = objectByFeature(aFeature);
- if (anObj) {
- ModelAPI_EventCreator::get()->sendUpdated(anObj, anEvent);
+ int aDSTag = INFINITE_TAG;
+ if (aLabIter.More()) { // next label in DS is existing
+ aDSTag = aLabIter.Value()->Label().Tag();
}
-
- // feature for this label is added, so go to the next label
- aFLabIter.Next();
- } else { // nothing is changed, both iterators are incremented
- if (theMarkUpdated) {
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
- ModelAPI_EventCreator::get()->sendUpdated(*aFIter, anEvent);
+ if (aDSTag > aFeatureTag) { // feature is removed
+ ObjectPtr anObj = *anObjIter;
+ anObjIter = aGroupIter->second.erase(anObjIter);
+ // event: model is updated
+ if (anObj->isInHistory()) {
+ ModelAPI_EventCreator::get()->sendDeleted(aThis, aGroupName);
+ }
+ ModelAPI_EventCreator::get()->sendDeleted(aThis, aGroupName);
+ } else if (aDSTag < aFeatureTag) { // a new feature is inserted
+ // create a feature
+ TDF_Label aLab = aLabIter.Value()->Label();
+ ObjectPtr aNewObj = ModelAPI_PluginManager::get()->createFeature(
+ TCollection_AsciiString(Handle(TDataStd_Comment)::DownCast(aLabIter.Value())->Get())
+ .ToCString());
+ // this must be before "setData" to redo the sketch line correctly
+ if (anObjIter == aGroupIter->second.end()) {
+ aGroupIter->second.push_back(aNewObj);
+ anObjIter = aGroupIter->second.end();
+ } else {
+ anObjIter++;
+ aGroupIter->second.insert(anObjIter, aNewObj);
+ }
+ initData(aNewObj, aLab, TAG_FEATURE_ARGUMENTS);
+
+ // event: model is updated
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
+ ModelAPI_EventCreator::get()->sendUpdated(aNewObj, anEvent);
+ // feature for this label is added, so go to the next label
+ aLabIter.Next();
+ } else { // nothing is changed, both iterators are incremented
+ if (theMarkUpdated) {
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
+ ModelAPI_EventCreator::get()->sendUpdated(*anObjIter, anEvent);
+ }
+ anObjIter++;
+ aLabIter.Next();
}
- aFIter++;
- aFLabIter.Next();
}
}
// after all updates, sends a message that groups of features were created or updated
boost::static_pointer_cast<Model_PluginManager>(Model_PluginManager::get())->
setCheckTransactions(false);
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_CREATED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
if (theMarkUpdated)
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_DELETED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
boost::static_pointer_cast<Model_PluginManager>(Model_PluginManager::get())->
setCheckTransactions(true);
}
+
+void Model_Document::storeResult(boost::shared_ptr<ModelAPI_Data> theFeatureData,
+ boost::shared_ptr<ModelAPI_Result> theResult, const int theResultIndex)
+{
+ boost::shared_ptr<ModelAPI_Document> aThis =
+ Model_Application::getApplication()->getDocument(myID);
+ theResult->setDoc(aThis);
+ initData(theResult, boost::dynamic_pointer_cast<Model_Data>(theFeatureData)->
+ label().Father().FindChild(TAG_FEATURE_RESULTS), theResultIndex);
+ if (theResult->data()->name().empty()) { // if was not initialized, generate event and set a name
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
+ ModelAPI_EventCreator::get()->sendUpdated(theResult, anEvent);
+ theResult->data()->setName(theFeatureData->name());
+ }
+}
+
+boost::shared_ptr<ModelAPI_ResultConstruction> Model_Document::createConstruction(
+ const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
+{
+ boost::shared_ptr<ModelAPI_ResultConstruction> aResult(new Model_ResultConstruction());
+ storeResult(theFeatureData, aResult);
+ return aResult;
+}
+
+boost::shared_ptr<ModelAPI_ResultBody> Model_Document::createBody(
+ const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
+{
+ boost::shared_ptr<ModelAPI_ResultBody> aResult(new Model_ResultBody());
+ storeResult(theFeatureData, aResult);
+ return aResult;
+}
+
+boost::shared_ptr<ModelAPI_ResultPart> Model_Document::createPart(
+ const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
+{
+ boost::shared_ptr<ModelAPI_ResultPart> aResult(new Model_ResultPart());
+ storeResult(theFeatureData, aResult);
+ return aResult;
+}
+
+boost::shared_ptr<ModelAPI_Feature> Model_Document::feature(
+ const boost::shared_ptr<ModelAPI_Result>& theResult)
+{
+ // iterate all features in order to find the needed result
+ std::map<std::string, std::vector<ObjectPtr> >::iterator aFind =
+ myObjs.find(ModelAPI_Feature::group());
+ if (aFind != myObjs.end()) {
+ std::vector<ObjectPtr>::iterator aFIter = aFind->second.begin();
+ for(; aFIter != aFind->second.end(); aFIter++) {
+ FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(*aFIter);
+ 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++) {
+ if (*aRIter == theResult) {
+ return aFeature;
+ }
+ }
+ }
+ }
+ return FeaturePtr();
+}
#include <Model.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_Feature.h>
+#include <ModelAPI_Result.h>
#include <TDocStd_Document.hxx>
#include <map>
//! \param creates feature and puts it in the document
MODEL_EXPORT virtual FeaturePtr addFeature(std::string theID);
- //! Removes the feature from the document
+ //! Removes the feature from the document (with result)
MODEL_EXPORT virtual void removeFeature(FeaturePtr theFeature);
//! Returns the existing feature by the label
//! \param theLabel base label of the feature
MODEL_EXPORT virtual FeaturePtr feature(TDF_Label& theLabel);
+ //! Returns the existing object: result or feature
+ //! \param theLabel base label of the object
+ MODEL_EXPORT virtual ObjectPtr object(TDF_Label& theLabel);
+
//! Adds a new sub-document by the identifier, or returns existing one if it is already exist
MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Document> subDocument(std::string theDocID);
//! \param theGroupID group that contains a feature
//! \param theIndex zero-based index of feature in the group
//! \param isOperation if it is true, returns feature (not Object)
- MODEL_EXPORT virtual FeaturePtr
- feature(const std::string& theGroupID, const int theIndex, const bool isOperation = false);
+ MODEL_EXPORT virtual ObjectPtr object(const std::string& theGroupID, const int theIndex);
//! Returns the number of features in the group
MODEL_EXPORT virtual int size(const std::string& theGroupID);
+ /// Creates a construction cresults
+ MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_ResultConstruction> createConstruction(
+ const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
+ /// Creates a body results
+ MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_ResultBody> createBody(
+ const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
+ /// Creates a part results
+ MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_ResultPart> createPart(
+ const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
+
+ //! Returns a feature by result (owner of result)
+ MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Feature>
+ feature(const boost::shared_ptr<ModelAPI_Result>& theResult);
+
+
protected:
//! Returns (creates if needed) the group label
//! feature type + "_" + index
void setUniqueName(FeaturePtr theFeature);
- //! Adds to the document the new feature
- void addFeature(const FeaturePtr theFeature);
-
- //! Returns the object by the feature
- FeaturePtr objectByFeature(
- const FeaturePtr theFeature);
-
//! Synchronizes myFeatures list with the updated document
void synchronizeFeatures(const bool theMarkUpdated = false);
//! performas compactification of all nested operations into one
void compactNested();
+ //! Initializes the data fields of the feature
+ void Model_Document::initData(ObjectPtr theObj, TDF_Label& theLab, const int theTag);
+
+ //! 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_Data> theFeatureData,
+ boost::shared_ptr<ModelAPI_Result> theResult, const int theResultIndex = 0);
+
+
friend class Model_Application;
friend class Model_PluginManager;
friend class DFBrowser;
int myTransactionsAfterSave;
/// number of nested transactions performed (or -1 if not nested)
int myNestedNum;
- /// All features managed by this document (not only in history of OB)
- std::vector<FeaturePtr > myFeatures;
+ /// All objects managed by this document (not only in history of OB)
+ std::map<std::string, std::vector<ObjectPtr> > myObjs;
///< set of identifiers of sub-documents of this document
std::set<std::string> mySubs;
/////////////////////// CREATOR /////////////////////////////
void Model_EventCreator::sendUpdated(
- const FeaturePtr& theFeature, const Events_ID& theEvent, const bool isGroupped) const
+ const ObjectPtr& theObject, const Events_ID& theEvent, const bool isGroupped) const
{
- Model_FeatureUpdatedMessage aMsg(theFeature, theEvent);
+ Model_ObjectUpdatedMessage aMsg(theObject, theEvent);
Events_Loop::loop()->send(aMsg, isGroupped);
}
void Model_EventCreator::sendDeleted(
const boost::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theGroup) const
{
- Model_FeatureDeletedMessage aMsg(theDoc, theGroup);
+ Model_ObjectDeletedMessage aMsg(theDoc, theGroup);
Events_Loop::loop()->send(aMsg, true);
}
}
/////////////////////// UPDATED MESSAGE /////////////////////////////
-Model_FeatureUpdatedMessage::Model_FeatureUpdatedMessage(
- const FeaturePtr& theFeature,
- const Events_ID& theEvent) : ModelAPI_FeatureUpdatedMessage(theEvent, 0)
+Model_ObjectUpdatedMessage::Model_ObjectUpdatedMessage(
+ const ObjectPtr& theObject,
+ const Events_ID& theEvent) : ModelAPI_ObjectUpdatedMessage(theEvent, 0)
{
- if (theFeature) myFeatures.insert(theFeature);
+ if (theObject) myObjects.insert(theObject);
}
-std::set<FeaturePtr> Model_FeatureUpdatedMessage::features() const
+std::set<ObjectPtr> Model_ObjectUpdatedMessage::features() const
{
- return myFeatures;
+ return myObjects;
}
-Events_MessageGroup* Model_FeatureUpdatedMessage::newEmpty()
+Events_MessageGroup* Model_ObjectUpdatedMessage::newEmpty()
{
- FeaturePtr anEmptyFeature;
- return new Model_FeatureUpdatedMessage(anEmptyFeature, eventID());
+ ObjectPtr anEmptyObject;
+ return new Model_ObjectUpdatedMessage(anEmptyObject, eventID());
}
-void Model_FeatureUpdatedMessage::Join(Events_MessageGroup& theJoined)
+void Model_ObjectUpdatedMessage::Join(Events_MessageGroup& theJoined)
{
- Model_FeatureUpdatedMessage* aJoined = dynamic_cast<Model_FeatureUpdatedMessage*>(&theJoined);
- std::set<FeaturePtr >::iterator aFIter = aJoined->myFeatures.begin();
- for(; aFIter != aJoined->myFeatures.end(); aFIter++) {
- myFeatures.insert(*aFIter);
+ Model_ObjectUpdatedMessage* aJoined = dynamic_cast<Model_ObjectUpdatedMessage*>(&theJoined);
+ std::set<ObjectPtr >::iterator aFIter = aJoined->myObjects.begin();
+ for(; aFIter != aJoined->myObjects.end(); aFIter++) {
+ myObjects.insert(*aFIter);
}
}
/////////////////////// DELETED MESSAGE /////////////////////////////
-Model_FeatureDeletedMessage::Model_FeatureDeletedMessage(
+Model_ObjectDeletedMessage::Model_ObjectDeletedMessage(
const boost::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theGroup)
- : ModelAPI_FeatureDeletedMessage(messageId(), 0), myDoc(theDoc)
+ : ModelAPI_ObjectDeletedMessage(messageId(), 0), myDoc(theDoc)
{
if (!theGroup.empty())
myGroups.insert(theGroup);
}
-Events_MessageGroup* Model_FeatureDeletedMessage::newEmpty()
+Events_MessageGroup* Model_ObjectDeletedMessage::newEmpty()
{
- return new Model_FeatureDeletedMessage(myDoc, "");
+ return new Model_ObjectDeletedMessage(myDoc, "");
}
-const Events_ID Model_FeatureDeletedMessage::messageId()
+const Events_ID Model_ObjectDeletedMessage::messageId()
{
- static Events_ID MY_ID = Events_Loop::eventByName(EVENT_FEATURE_DELETED);
+ static Events_ID MY_ID = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
return MY_ID;
}
-void Model_FeatureDeletedMessage::Join(Events_MessageGroup& theJoined)
+void Model_ObjectDeletedMessage::Join(Events_MessageGroup& theJoined)
{
- Model_FeatureDeletedMessage* aJoined = dynamic_cast<Model_FeatureDeletedMessage*>(&theJoined);
+ Model_ObjectDeletedMessage* aJoined = dynamic_cast<Model_ObjectDeletedMessage*>(&theJoined);
std::set<std::string>::iterator aGIter = aJoined->myGroups.begin();
for(; aGIter != aJoined->myGroups.end(); aGIter++) {
myGroups.insert(*aGIter);
public:
/// creates created, updated or moved messages and sends to the loop
virtual void sendUpdated(
- const FeaturePtr& theFeature, const Events_ID& theEvent, const bool isGroupped = true) const;
+ const ObjectPtr& theObject, const Events_ID& theEvent, const bool isGroupped = true) const;
/// creates deleted message and sends to the loop
virtual void sendDeleted(
const boost::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theGroup) const;
};
/// Message that feature was changed (used for Object Browser update): moved, updated and deleted
-class Model_FeatureUpdatedMessage : public ModelAPI_FeatureUpdatedMessage {
- std::set<FeaturePtr> myFeatures; ///< which feature is changed
+class Model_ObjectUpdatedMessage : public ModelAPI_ObjectUpdatedMessage {
+ std::set<ObjectPtr> myObjects; ///< which feature is changed
/// Sender is not important, all information is located in the feature.
/// Use ModelAPI for creation of this event. Used for creation, movement and edition events.
- Model_FeatureUpdatedMessage(
- const FeaturePtr& theFeature,
+ Model_ObjectUpdatedMessage(
+ const ObjectPtr& theObject,
const Events_ID& theEvent);
friend class Model_EventCreator;
public:
/// Returns the feature that has been updated
- virtual std::set<FeaturePtr> features() const;
+ virtual std::set<ObjectPtr> features() const;
//! Creates a new empty group (to store it in the loop before flush)
virtual Events_MessageGroup* newEmpty();
};
/// Message that feature was deleted (used for Object Browser update)
-class Model_FeatureDeletedMessage : public ModelAPI_FeatureDeletedMessage {
+class Model_ObjectDeletedMessage : public ModelAPI_ObjectDeletedMessage {
boost::shared_ptr<ModelAPI_Document> myDoc; ///< document owner of the feature
std::set<std::string> myGroups; ///< group identifiers that contained the deleted feature
/// Use ModelAPI for creation of this event.
- Model_FeatureDeletedMessage(
+ Model_ObjectDeletedMessage(
const boost::shared_ptr<ModelAPI_Document>& theDoc, const std::string& theGroup);
friend class Model_EventCreator;
+++ /dev/null
-// File: Model_Object.cpp
-// Created: 19 May 2014
-// Author: Mikhail PONIKAROV
-
-#include "Model_Object.h"
-#include <TCollection_AsciiString.hxx>
-#include "Model_Events.h"
-#include <Events_Loop.h>
-
-FeaturePtr Model_Object::featureRef()
-{
- return myRef;
-}
-
-std::string Model_Object::getName()
-{
- return TCollection_AsciiString(myName->Get()).ToCString();
-}
-
-void Model_Object::setName(std::string theName)
-{
- if (myName->Get() != theName.c_str()) {
- myName->Set(theName.c_str());
- /*
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
- Model_FeatureUpdatedMessage aMsg(boost::shared_ptr<ModelAPI_Object>(this), anEvent);
- Events_Loop::loop()->send(aMsg, false);
- */
- }
-}
-
-Model_Object::Model_Object(FeaturePtr theRef,
- Handle_TDataStd_Name theName)
- : myRef(theRef), myName(theName)
-{
-}
+++ /dev/null
-// File: Model_Object.hxx
-// Created: 19 May 2014
-// Author: Mikhail PONIKAROV
-
-#ifndef Model_Object_HeaderFile
-#define Model_Object_HeaderFile
-
-#include <Model.h>
-#include <ModelAPI_Object.h>
-#include <ModelAPI_Document.h>
-
-#include <TDataStd_Name.hxx>
-
-/**\class ModelAPI_Object
- * \ingroup DataModel
- * \brief Represents the result of some feature in the object browser
- * under the specific folder. Just a reference to specific feature-operation
- * with possibility to rename it.
- */
-class Model_Object : public ModelAPI_Object
-{
- FeaturePtr myRef; ///< the referenced feature
- Handle_TDataStd_Name myName; ///< the name of this object that may be changed
-public:
- /// Reference to the feature-operation that produces this object
- MODEL_EXPORT virtual FeaturePtr featureRef();
-
- /// Returns the name of this object (by default equal to the name of feature)
- MODEL_EXPORT virtual std::string getName();
-
- /// Defines the name of the object
- MODEL_EXPORT virtual void setName(std::string theName);
-
- /// Returns the kind of a feature (like "Point")
- MODEL_EXPORT virtual const std::string& getKind() {return myRef->getKind();}
-
- /// Returns to which group in the document must be added feature
- MODEL_EXPORT virtual const std::string& getGroup() {return ModelAPI_Document::FEATURES_GROUP();}
-
- /// Returns document this feature belongs to
- MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Document> document()
- {return myRef->document();}
-
- /// Returns true if feature refers to the same model data instance
- MODEL_EXPORT virtual bool isSame(const FeaturePtr& theFeature)
- {
- boost::shared_ptr<Model_Object> anObj = boost::dynamic_pointer_cast<Model_Object>(theFeature);
- return anObj && myRef == anObj->myRef;
- }
-
- /// It is just a reference: don't init attributes
- MODEL_EXPORT virtual void initAttributes() {}
-
- /// It is just a reference: don't execute
- MODEL_EXPORT virtual void execute() {}
-
-private:
-
- /// Constructor fully defines this object
- Model_Object(FeaturePtr theRef, Handle_TDataStd_Name theName);
-
- friend class Model_Document;
-};
-
-#endif
} else {
Events_Error::send(string("Can not load plugin '") + myCurrentPluginName + "'");
}
+ } else {
+ Events_Error::send(string("Feature '") + theFeatureID + "' not found in any plugin");
}
return FeaturePtr(); // return nothing
Events_Loop* aLoop = Events_Loop::loop();
static Events_ID FeatureEvent = Events_Loop::eventByName("FeatureRegisterEvent");
aLoop->registerListener(this, FeatureEvent);
- aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_CREATED));
- aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
- aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_DELETED));
+ aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+ aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+ aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
}
void Model_PluginManager::processEvent(const Events_Message* theMessage)
--- /dev/null
+// File: Model_ResultBody.cpp
+// Created: 08 Jul 2014
+// Author: Mikhail PONIKAROV
+
+#include <Model_ResultBody.h>
+#include <Model_Data.h>
+#include <TNaming_Builder.hxx>
+#include <TNaming_NamedShape.hxx>
+#include <TopoDS_Shape.hxx>
+#include <GeomAPI_Shape.h>
+
+Model_ResultBody::Model_ResultBody()
+{
+}
+
+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();
+ // TODO: to add the naming mechanism for shape storage in the next iteration
+ TNaming_Builder aBuilder(aShapeLab);
+ if (!theShape) return; // bad shape
+ TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
+ if (aShape.IsNull()) return; // null shape inside
+
+ aBuilder.Generated(aShape);
+ }
+}
+
+boost::shared_ptr<GeomAPI_Shape> Model_ResultBody::shape()
+{
+ boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(data());
+ if (aData) {
+ TDF_Label& aShapeLab = aData->shapeLab();
+ Handle(TNaming_NamedShape) aName;
+ if (aShapeLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
+ TopoDS_Shape aShape = aName->Get();
+ if (!aShape.IsNull()) {
+ boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
+ aRes->setImpl(new TopoDS_Shape(aShape));
+ return aRes;
+ }
+ }
+ }
+ return boost::shared_ptr<GeomAPI_Shape>();
+}
+
+boost::shared_ptr<ModelAPI_Feature> Model_ResultBody::owner()
+{
+ return myOwner;
+}
--- /dev/null
+// File: Model_ResultBody.h
+// Created: 08 Jul 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef Model_ResultBody_HeaderFile
+#define Model_ResultBody_HeaderFile
+
+#include "Model.h"
+#include <ModelAPI_ResultBody.h>
+
+/**\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.
+ */
+class Model_ResultBody : public ModelAPI_ResultBody
+{
+ boost::shared_ptr<ModelAPI_Feature> myOwner; ///< owner of this result
+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
+ MODEL_EXPORT virtual boost::shared_ptr<GeomAPI_Shape> shape();
+ /// Returns the source feature of this result
+ MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> owner();
+
+protected:
+ /// Makes a body on the given feature
+ Model_ResultBody();
+
+ friend class Model_Document;
+};
+
+#endif
--- /dev/null
+// File: ModelAPI_ResultConstruction.cpp
+// Created: 07 Jul 2014
+// Author: Mikhail PONIKAROV
+
+#include <Model_ResultConstruction.h>
+
+void Model_ResultConstruction::setShape(boost::shared_ptr<GeomAPI_Shape> theShape)
+{
+ myShape = theShape;
+}
+
+boost::shared_ptr<GeomAPI_Shape>& Model_ResultConstruction::shape()
+{
+ return myShape;
+}
+
+/*
+boost::shared_ptr<ModelAPI_Feature> Model_ResultConstruction::owner()
+{
+ return myOwner;
+}*/
+
+Model_ResultConstruction::Model_ResultConstruction()
+{
+}
--- /dev/null
+// File: ModelAPI_ResultConstruction.hxx
+// Created: 07 Jul 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef Model_ResultConstruction_HeaderFile
+#define Model_ResultConstruction_HeaderFile
+
+#include "Model.h"
+#include <ModelAPI_ResultConstruction.h>
+
+/**\class ModelAPI_ResultConstruction
+ * \ingroup DataModel
+ * \brief The construction element result of a feature.
+ *
+ * Provides a shape that may be displayed in the viewer.
+ * Intermediate, light result that in many cases produces a result on the fly.
+ */
+class Model_ResultConstruction : public ModelAPI_ResultConstruction
+{
+ 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:
+ /// Sets the result
+ MODEL_EXPORT virtual void setShape(boost::shared_ptr<GeomAPI_Shape> theShape);
+ /// 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_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> owner();
+
+protected:
+ /// Makes a body on the given feature
+ Model_ResultConstruction();
+
+ friend class Model_Document;
+};
+
+#endif
--- /dev/null
+// File: ModelAPI_ResultPart.cpp
+// Created: 07 Jul 2014
+// Author: Mikhail PONIKAROV
+
+#include <Model_ResultPart.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_AttributeDocRef.h>
+
+boost::shared_ptr<ModelAPI_Document> Model_ResultPart::partDoc()
+{
+ return data()->docRef("PartDocument")->value();
+}
+
+boost::shared_ptr<ModelAPI_Feature> Model_ResultPart::owner()
+{
+ return boost::shared_ptr<ModelAPI_Feature>(); // return empty pointer
+}
+
+Model_ResultPart::Model_ResultPart()
+{
+}
--- /dev/null
+// File: ModelAPI_ResultPart.hxx
+// Created: 07 Jul 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef Model_ResultPart_HeaderFile
+#define Model_ResultPart_HeaderFile
+
+#include "Model.h"
+#include <ModelAPI_ResultPart.h>
+
+/**\class ModelAPI_ResultPart
+ * \ingroup DataModel
+ * \brief The Part document, result of a creation of new part feature.
+ *
+ * This result leaves without feature: no parametricity for this element,
+ * only add/remove, undo/redo.
+ */
+class Model_ResultPart : public ModelAPI_ResultPart
+{
+public:
+ /// 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
+ MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> owner();
+
+protected:
+ /// makes a result on a temporary feature (an action)
+ Model_ResultPart();
+
+ friend class Model_Document;
+};
+
+#endif
Model_Update::Model_Update()
{
- Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+ Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
}
void Model_Update::processEvent(const Events_Message* theMessage)
{
- const ModelAPI_FeatureUpdatedMessage* aMsg =
- dynamic_cast<const ModelAPI_FeatureUpdatedMessage*>(theMessage);
+ const ModelAPI_ObjectUpdatedMessage* aMsg =
+ dynamic_cast<const ModelAPI_ObjectUpdatedMessage*>(theMessage);
myInitial = aMsg->features();
// collect all documents involved into the update
set<boost::shared_ptr<ModelAPI_Document> > aDocs;
- set<boost::shared_ptr<ModelAPI_Feature> >::iterator aFIter = myInitial.begin();
+ set<boost::shared_ptr<ModelAPI_Object> >::iterator aFIter = myInitial.begin();
for(; aFIter != myInitial.end(); aFIter++) {
aDocs.insert((*aFIter)->document());
}
// iterate all features of features-documents to update them
set<boost::shared_ptr<ModelAPI_Document> >::iterator aDIter = aDocs.begin();
for(; aDIter != aDocs.end(); aDIter++) {
- int aNbFeatures = (*aDIter)->size(ModelAPI_Document::FEATURES_GROUP());
+ int aNbFeatures = (*aDIter)->size(ModelAPI_Feature::group());
for(int aFIndex = 0; aFIndex < aNbFeatures; aFIndex++) {
- boost::shared_ptr<ModelAPI_Feature> aFeature = (*aDIter)->feature(ModelAPI_Document::FEATURES_GROUP(), aFIndex);
+ boost::shared_ptr<ModelAPI_Object> aFeature = boost::dynamic_pointer_cast<ModelAPI_Object>
+ ((*aDIter)->object(ModelAPI_Feature::group(), aFIndex));
if (aFeature)
- updateFeature(aFeature);
+ updateObject(aFeature);
}
}
myUpdated.clear();
// flush
- static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_FEATURE_TO_REDISPLAY);
+ static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
Events_Loop::loop()->flush(EVENT_DISP);
}
-bool Model_Update::updateFeature(boost::shared_ptr<ModelAPI_Feature> theFeature)
+bool Model_Update::updateObject(boost::shared_ptr<ModelAPI_Object> theObject)
{
// check it is already processed
- if (myUpdated.find(theFeature) != myUpdated.end())
- return myUpdated[theFeature];
+ if (myUpdated.find(theObject) != myUpdated.end())
+ return myUpdated[theObject];
// check all features this feature depended on (recursive call of updateFeature)
- bool aMustbeUpdated = myInitial.find(theFeature) != myInitial.end();
- // 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_Feature> aSub =
- boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(*aRefsIter)->value();
- if (aSub && aSub != theFeature && updateFeature(aSub))
- aMustbeUpdated = true;
- }
- // lists of references
- aRefs = theFeature->data()->attributes(ModelAPI_AttributeRefList::type());
- for(aRefsIter = aRefs.begin(); aRefsIter != aRefs.end(); aRefsIter++) {
- list<FeaturePtr> aListRef =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(*aRefsIter)->list();
- list<FeaturePtr>::iterator aListIter = aListRef.begin();
- for(; aListIter != aListRef.end(); aListIter++) {
- boost::shared_ptr<ModelAPI_Feature> aSub = *aListIter;
- if (aSub && updateFeature(aSub))
+ bool anExecute = myInitial.find(theObject) != myInitial.end();
+ bool aMustbeUpdated = myInitial.find(theObject) != myInitial.end();
+ FeaturePtr aRealFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
+ if (aRealFeature) { // only real feature contains references to other objects
+ // references
+ list<boost::shared_ptr<ModelAPI_Attribute> > aRefs =
+ theObject->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 (aSub && aSub != theObject && updateObject(aSub))
aMustbeUpdated = true;
}
+ // lists of references
+ aRefs = theObject->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 (aSub && updateObject(aSub))
+ aMustbeUpdated = true;
+ }
+ }
+ // execute feature if it must be updated
+ anExecute = aMustbeUpdated || anExecute;
+ if (anExecute) {
+ aRealFeature->execute();
+ static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+ ModelAPI_EventCreator::get()->sendUpdated(theObject, EVENT_DISP);
+ }
}
- // execute feature if it must be updated
- bool anExecute = aMustbeUpdated || myInitial.find(theFeature) != myInitial.end();
- if (anExecute) {
- theFeature->execute();
- static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_FEATURE_TO_REDISPLAY);
- ModelAPI_EventCreator::get()->sendUpdated(theFeature, EVENT_DISP);
- }
- myUpdated[theFeature] = anExecute;
+ myUpdated[theObject] = anExecute;
return anExecute;
}
#include <set>
#include <map>
+class ModelAPI_Object;
class ModelAPI_Feature;
/**\class Model_Update
class Model_Update : public Events_Listener
{
///< initial set of updated features that must be processed
- std::set<boost::shared_ptr<ModelAPI_Feature> > myInitial;
+ std::set<boost::shared_ptr<ModelAPI_Object> > myInitial;
///< already updated and processed features and modificated feature flag
- std::map<boost::shared_ptr<ModelAPI_Feature>, bool> myUpdated;
+ std::map<boost::shared_ptr<ModelAPI_Object>, bool> myUpdated;
public:
/// Is called only once, on startup of the application
Model_Update();
MODEL_EXPORT virtual void processEvent(const Events_Message* theMessage);
protected:
- /// Recoursively checks and updates the feature if needed
- /// Returns true if feature was updated.
- bool updateFeature(boost::shared_ptr<ModelAPI_Feature> theFeature);
+ /// Recoursively checks and updates the object if needed
+ /// Returns true if object was updated.
+ bool updateObject(boost::shared_ptr<ModelAPI_Object> theObject);
};
#endif
ModelAPI_Events.h
ModelAPI_Validator.h
ModelAPI_FeatureValidator.h
+ ModelAPI_Result.h
+ ModelAPI_ResultBody.h
+ ModelAPI_ResultConstruction.h
+ ModelAPI_ResultPart.h
+ ModelAPI_ResultParameters.h
)
SET(PROJECT_SOURCES
#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"
#include <string>
#include <boost/shared_ptr.hpp>
-class ModelAPI_Feature;
+class ModelAPI_Object;
/**\class ModelAPI_Attribute
* \ingroup DataModel
class ModelAPI_Attribute
{
///< needed here to emit signal that feature changed on change of the attribute
- boost::shared_ptr<ModelAPI_Feature> myFeature;
+ boost::shared_ptr<ModelAPI_Object> myObject;
protected: // accessible from the attributes
bool myIsInitialized;
public:
MODELAPI_EXPORT virtual ~ModelAPI_Attribute() {}
/// Sets the owner of this attribute
- MODELAPI_EXPORT void setFeature(const boost::shared_ptr<ModelAPI_Feature>& theFeature)
- {myFeature = theFeature;}
+ MODELAPI_EXPORT void setObject(const boost::shared_ptr<ModelAPI_Object>& theObject)
+ {myObject = theObject;}
/// Returns the owner of this attribute
- MODELAPI_EXPORT const boost::shared_ptr<ModelAPI_Feature>& owner()
- {return myFeature;}
+ MODELAPI_EXPORT const boost::shared_ptr<ModelAPI_Object>& owner()
+ {return myObject;}
/// Returns true if attribute was initialized by some value
MODELAPI_EXPORT bool isInitialized() {return myIsInitialized;}
class ModelAPI_AttributeRefAttr : public ModelAPI_Attribute
{
public:
- /// Returns true if this attribute references to a feature (not to the attribute)
- MODELAPI_EXPORT virtual bool isFeature() = 0;
+ /// Returns true if this attribute references to a object (not to the attribute)
+ MODELAPI_EXPORT virtual bool isObject() = 0;
/// Defines the reference to the attribute
MODELAPI_EXPORT virtual void setAttr(boost::shared_ptr<ModelAPI_Attribute> theAttr) = 0;
/// Returns attribute referenced from this attribute
MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Attribute> attr() = 0;
- /// Defines the reference to the feature
- MODELAPI_EXPORT virtual void setFeature(FeaturePtr theFeature) = 0;
+ /// Defines the reference to the object
+ MODELAPI_EXPORT virtual void setObject(ObjectPtr theFeature) = 0;
- /// Returns feature referenced from this attribute
- MODELAPI_EXPORT virtual FeaturePtr feature() = 0;
+ /// Returns object referenced from this attribute
+ MODELAPI_EXPORT virtual ObjectPtr object() = 0;
/// Returns the type of this class of attributes
MODELAPI_EXPORT static std::string type() {return "RefAttr";}
MODELAPI_EXPORT virtual std::string attributeType() {return type();}
/// Appends the feature to the end of a list
- MODELAPI_EXPORT virtual void append(FeaturePtr theFeature) = 0;
+ MODELAPI_EXPORT virtual void append(ObjectPtr theObject) = 0;
/// Erases the first meet of the feature in the list
- MODELAPI_EXPORT virtual void remove(FeaturePtr theFeature) = 0;
+ MODELAPI_EXPORT virtual void remove(ObjectPtr theObject) = 0;
/// Returns number of features in the list
MODELAPI_EXPORT virtual int size() = 0;
/// Returns the list of features
- MODELAPI_EXPORT virtual std::list<FeaturePtr > list() = 0;
+ MODELAPI_EXPORT virtual std::list<ObjectPtr > list() = 0;
protected:
/// Objects are created for features automatically
class ModelAPI_AttributeReference : public ModelAPI_Attribute
{
public:
- /// Defines the feature referenced from this attribute
- MODELAPI_EXPORT virtual void setValue(FeaturePtr theFeature) = 0;
+ /// Defines the object referenced from this attribute
+ MODELAPI_EXPORT virtual void setValue(ObjectPtr theObject) = 0;
- /// Returns feature referenced from this attribute
- MODELAPI_EXPORT virtual FeaturePtr value() = 0;
+ /// Returns object referenced from this attribute
+ MODELAPI_EXPORT virtual ObjectPtr value() = 0;
/// Returns the type of this class of attributes
MODELAPI_EXPORT static std::string type() {return "Reference";}
public:
/// Returns the name of the feature visible by the user in the object browser
- virtual std::string getName() = 0;
+ virtual std::string name() = 0;
/// Defines the name of the feature visible by the user in the object browser
virtual void setName(std::string theName) = 0;
/// Returns true if it is correctly connected t othe data model
virtual bool isValid() = 0;
- /// Stores the shape (called by the execution method).
- virtual void store(const boost::shared_ptr<GeomAPI_Shape>& theShape) = 0;
- /// Returns the shape-result produced by this feature
- virtual boost::shared_ptr<GeomAPI_Shape> shape() = 0;
-
/// Initializes object by the attributes: must be called just after the object is created
/// for each attribute of the object
/// \param theID identifier of the attribute that can be referenced by this ID later
#include <vector>
class ModelAPI_Feature;
+class ModelAPI_Object;
+class ModelAPI_Result;
+class ModelAPI_ResultConstruction;
+class ModelAPI_ResultBody;
+class ModelAPI_ResultPart;
+class ModelAPI_Data;
/**\class Model_Document
* \ingroup DataModel
class ModelAPI_Document
{
public:
- //! Common groups identifiers
- //! Group of parameters
- inline static const std::string& PARAMETERS_GROUP()
- {
- static const std::string MY_PARAMETERS_GROUP = "Parameters";
- return MY_PARAMETERS_GROUP;
- }
- //! Group of constructions
- inline static const std::string& CONSTRUCTIONS_GROUP()
- {
- static const std::string MY_CONSTRUCTIONS_GROUP = "Construction";
- return MY_CONSTRUCTIONS_GROUP;
- }
- //! Group of parts
- inline static const std::string& PARTS_GROUP()
- {
- static const std::string MY_PARTS_GROUP = "Parts";
- return MY_PARTS_GROUP;
- }
- //! All created fetaures of the document (a history)
- inline static const std::string& FEATURES_GROUP()
- {
- static const std::string MY_FEATURES_GROUP = "Features";
- return MY_FEATURES_GROUP;
- }
-
//! Loads the OCAF document from the file.
//! \param theFileName full name of the file to load
//! \param theStudyID identifier of the SALOME study to associate with loaded file
//! \returns true if file was loaded successfully
- MODELAPI_EXPORT virtual bool load(const char* theFileName) = 0;
+ virtual bool load(const char* theFileName) = 0;
//! Saves the OCAF document to the file.
//! \param theFileName full name of the file to store
//! \returns true if file was stored successfully
- MODELAPI_EXPORT virtual bool save(const char* theFileName) = 0;
+ virtual bool save(const char* theFileName) = 0;
//! Removes document data
- MODELAPI_EXPORT virtual void close() = 0;
+ virtual void close() = 0;
//! Starts a new operation (opens a tansaction)
- MODELAPI_EXPORT virtual void startOperation() = 0;
+ virtual void startOperation() = 0;
//! Finishes the previously started operation (closes the transaction)
- MODELAPI_EXPORT virtual void finishOperation() = 0;
+ virtual void finishOperation() = 0;
//! Aborts the operation
- MODELAPI_EXPORT virtual void abortOperation() = 0;
+ virtual void abortOperation() = 0;
//! Returns true if operation has been started, but not yet finished or aborted
- MODELAPI_EXPORT virtual bool isOperation() = 0;
+ virtual bool isOperation() = 0;
//! Returns true if document was modified (since creation/opening)
- MODELAPI_EXPORT virtual bool isModified() = 0;
+ virtual bool isModified() = 0;
//! Returns True if there are available Undos
- MODELAPI_EXPORT virtual bool canUndo() = 0;
+ virtual bool canUndo() = 0;
//! Undoes last operation
- MODELAPI_EXPORT virtual void undo() = 0;
+ virtual void undo() = 0;
//! Returns True if there are available Redos
- MODELAPI_EXPORT virtual bool canRedo() = 0;
+ virtual bool canRedo() = 0;
//! Redoes last operation
- MODELAPI_EXPORT virtual void redo() = 0;
+ virtual void redo() = 0;
//! Adds to the document the new feature of the given feature id
- //! \param creates feature and puts it in the document
- MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Feature> addFeature(std::string theID) = 0;
+ //! \param creates feature and puts it in the document (if it is not action)
+ virtual boost::shared_ptr<ModelAPI_Feature> addFeature(std::string theID) = 0;
//! Removes the feature from the document
- MODELAPI_EXPORT virtual void removeFeature(boost::shared_ptr<ModelAPI_Feature> theFeature) = 0;
+ virtual void removeFeature(boost::shared_ptr<ModelAPI_Feature> theFeature) = 0;
///! Adds a new sub-document by the identifier, or returns existing one if it is already exist
- MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Document>
+ virtual boost::shared_ptr<ModelAPI_Document>
subDocument(std::string theDocID) = 0;
- ///! Returns the id of hte document
- MODELAPI_EXPORT virtual const std::string& id() const = 0;
+ ///! Returns the id of the document
+ virtual const std::string& id() const = 0;
- //! Returns the feature in the group by the index (started from zero)
- //! \param theGroupID group that contains a feature
+ //! Returns the object in the group by the index (started from zero)
+ //! \param theGroupID group that contains an object
//! \param theIndex zero-based index of feature in the group
- //! \param isOperation if it is true, returns feature (not Object)
- MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Feature>
- feature(const std::string& theGroupID, const int theIndex, const bool isOperation = false) = 0;
+ virtual boost::shared_ptr<ModelAPI_Object>
+ object(const std::string& theGroupID, const int theIndex) = 0;
- //! Returns the number of features in the group
- MODELAPI_EXPORT virtual int size(const std::string& theGroupID) = 0;
+ //! Returns the number of objects in the group of objects
+ virtual int size(const std::string& theGroupID) = 0;
/// To virtually destroy the fields of successors
virtual ~ModelAPI_Document() {}
+ /// Creates a construction cresults
+ virtual boost::shared_ptr<ModelAPI_ResultConstruction> createConstruction(
+ const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
+ /// Creates a body results
+ virtual boost::shared_ptr<ModelAPI_ResultBody> createBody(
+ const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
+ /// Creates a part results
+ virtual boost::shared_ptr<ModelAPI_ResultPart> createPart(
+ const boost::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
+
+ //! Returns a feature by result (owner of result)
+ virtual boost::shared_ptr<ModelAPI_Feature> feature(
+ const boost::shared_ptr<ModelAPI_Result>& theResult) = 0;
+
protected:
/// Only for SWIG wrapping it is here
MODELAPI_EXPORT ModelAPI_Document()
#include <string>
#include <set>
-#include "ModelAPI_Feature.h"
+#include "ModelAPI_Object.h"
class ModelAPI_Document;
-/// Event ID that feature is created (comes with ModelAPI_FeatureUpdatedMessage)
-static const char * EVENT_FEATURE_CREATED = "FeatureCreated";
-/// Event ID that data of feature is updated (comes with Model_FeatureUpdatedMessage)
-static const char * EVENT_FEATURE_UPDATED = "FeatureUpdated";
-/// Event ID that data of feature is deleted (comes with Model_FeatureDeletedMessage)
-static const char * EVENT_FEATURE_DELETED = "FeatureDeleted";
-/// Event ID that data of feature is updated (comes with ModelAPI_FeatureUpdatedMessage)
-static const char * EVENT_FEATURE_MOVED = "FeaturesMoved";
-/// Event ID that visualization must be redisplayed (comes with ModelAPI_FeatureUpdatedMessage)
-static const char * EVENT_FEATURE_TO_REDISPLAY = "FeaturesToRedisplay";
-/// Event ID that visualization must be redisplayed (comes with ModelAPI_FeatureUpdatedMessage)
+/// Event ID that feature is created (comes with ModelAPI_ObjectUpdatedMessage)
+static const char * EVENT_OBJECT_CREATED = "ObjectCreated";
+/// Event ID that data of feature is updated (comes with Model_ObjectUpdatedMessage)
+static const char * EVENT_OBJECT_UPDATED = "ObjectUpdated";
+/// Event ID that data of feature is deleted (comes with Model_ObjectDeletedMessage)
+static const char * EVENT_OBJECT_DELETED = "ObjectDeleted";
+/// Event ID that data of feature is updated (comes with ModelAPI_ObjectUpdatedMessage)
+static const char * EVENT_OBJECT_MOVED = "ObjectsMoved";
+/// Event ID that visualization must be redisplayed (comes with ModelAPI_ObjectUpdatedMessage)
+static const char * EVENT_OBJECT_TO_REDISPLAY = "ObjectsToRedisplay";
+/// Event ID that visualization must be redisplayed (comes with ModelAPI_ObjectUpdatedMessage)
static const char * EVENT_OPERATION_LAUNCHED = "OperationLaunched";
/// Message that feature was changed (used for Object Browser update): moved, updated and deleted
-class ModelAPI_FeatureUpdatedMessage : public Events_MessageGroup {
+class ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup {
protected:
- ModelAPI_FeatureUpdatedMessage(const Events_ID theID, const void* theSender = 0)
+ ModelAPI_ObjectUpdatedMessage(const Events_ID theID, const void* theSender = 0)
: Events_MessageGroup(theID, theSender) {}
public:
/// Returns the feature that has been updated
- virtual std::set<FeaturePtr> features() const = 0;
+ virtual std::set<ObjectPtr> features() const = 0;
//! Creates a new empty group (to store it in the loop before flush)
virtual Events_MessageGroup* newEmpty() = 0;
};
/// Message that feature was deleted (used for Object Browser update)
-class ModelAPI_FeatureDeletedMessage : public Events_MessageGroup {
+class ModelAPI_ObjectDeletedMessage : public Events_MessageGroup {
protected:
- ModelAPI_FeatureDeletedMessage(const Events_ID theID, const void* theSender = 0)
+ ModelAPI_ObjectDeletedMessage(const Events_ID theID, const void* theSender = 0)
: Events_MessageGroup(theID, theSender) {}
public:
class MODELAPI_EXPORT ModelAPI_EventCreator {
public:
/// creates created, updated or moved messages and sends to the loop
- virtual void sendUpdated(const FeaturePtr& theFeature, const Events_ID& theEvent,
+ virtual void sendUpdated(const ObjectPtr& theObject, const Events_ID& theEvent,
const bool isGroupped = true) const = 0;
/// creates deleted message and sends to the loop
virtual void sendDeleted(
#ifndef ModelAPI_Feature_HeaderFile
#define ModelAPI_Feature_HeaderFile
-#include "ModelAPI.h"
+#include "ModelAPI_Object.h"
#include "ModelAPI_PluginManager.h"
#include <string>
+#include <list>
#include <boost/shared_ptr.hpp>
class ModelAPI_Data;
class ModelAPI_Document;
+class ModelAPI_Result;
/**\class ModelAPI_Feature
* \ingroup DataModel
- * \brief Functionality of the model object: to update result,
- * to initialize attributes, etc.
+ * \brief Feature function that represents the particular functionality
+ * of this operation. Produces results by the arguments.
*/
-class ModelAPI_Feature
+class ModelAPI_Feature : public ModelAPI_Object
{
- boost::shared_ptr<ModelAPI_Data> myData; ///< manager of the data model of a feature
- boost::shared_ptr<ModelAPI_Document> myDoc; ///< document this feature belongs to
-
+ ///< list of current results of this feature
+ std::list<boost::shared_ptr<ModelAPI_Result> > myResults;
public:
- /// Returns the kind of a feature (like "Point")
- MODELAPI_EXPORT virtual const std::string& getKind() = 0;
+ /// Returns the unique kind of a feature (like "Point")
+ virtual const std::string& getKind() = 0;
+
+ /// Returns the group identifier of all features
+ static std::string group()
+ {static std::string MY_GROUP = "Features"; return MY_GROUP;}
- /// Returns to which group in the document must be added feature
- MODELAPI_EXPORT virtual const std::string& getGroup() = 0;
+ /// Returns the group identifier of this result
+ virtual std::string groupName() { return group(); }
/// Request for initialization of data model of the feature: adding all attributes
- MODELAPI_EXPORT virtual void initAttributes() = 0;
+ virtual void initAttributes() = 0;
- /// Computes or recomputes the result
- MODELAPI_EXPORT virtual void execute() = 0;
+ /// Computes or recomputes the results
+ virtual void execute() = 0;
- /// Returns true if this feature must be displayed in the history (top level of Part tree)
- MODELAPI_EXPORT virtual bool isInHistory() {return true;}
+ /// 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
+ 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 (like delete part).
- MODELAPI_EXPORT virtual bool isAction() {return false;}
-
- /// Returns the data manager of this feature
- MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Data> data() {return myData;}
+ /// that is not stored in the features history and data model (like "delete part").
+ virtual bool isAction() {return false;}
/// Must return document where the new feature must be added to
/// By default it is current document
- MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Document> documentToAdd()
+ virtual boost::shared_ptr<ModelAPI_Document> documentToAdd()
{return ModelAPI_PluginManager::get()->currentDocument();}
- /// Returns document this feature belongs to
- MODELAPI_EXPORT virtual boost::shared_ptr<ModelAPI_Document> document()
- {return myDoc;}
-
- /// Returns true if feature refers to the same model data instance
- MODELAPI_EXPORT virtual bool isSame(const boost::shared_ptr<ModelAPI_Feature>& theFeature)
- {return theFeature.get() == this;}
-
/// To virtually destroy the fields of successors
virtual ~ModelAPI_Feature() {}
-
-protected:
- /// Use plugin manager for features creation: this method is
- /// defined here only for SWIG-wrapping
- ModelAPI_Feature()
- {}
-
- /// Sets the data manager of an object (document does)
- MODELAPI_EXPORT virtual void setData(boost::shared_ptr<ModelAPI_Data> theData)
- {myData = theData;}
- /// Sets the data manager of an object (document does)
- MODELAPI_EXPORT void setDoc(boost::shared_ptr<ModelAPI_Document> theDoc) {myDoc = theDoc;}
-
- friend class Model_Document;
};
//! Pointer on feature object
typedef boost::shared_ptr<ModelAPI_Feature> FeaturePtr;
-
#endif
#ifndef ModelAPI_Object_HeaderFile
#define ModelAPI_Object_HeaderFile
-#include "ModelAPI_Feature.h"
+#include "ModelAPI.h"
#include <boost/shared_ptr.hpp>
+class ModelAPI_Data;
+class ModelAPI_Document;
+
/**\class ModelAPI_Object
* \ingroup DataModel
- * \brief Represents the result of some feature in the object browser
- * under the specific folder. Just a reference to specific feature-operation
- * with possibility to rename it.
+ * \brief Represents any object in the data model and in the object browser.
+ *
+ * It may be feature or result of the feature. User just may set name for it
+ * or change this name later. Generic class for Feature, Body, Parameter and other
+ * objects related to the features and their results. Contains attributes of this
+ * object in the "Data".
*/
-class ModelAPI_Object : public ModelAPI_Feature
+class ModelAPI_Object
{
+ boost::shared_ptr<ModelAPI_Data> myData; ///< manager of the data model of a feature
+ boost::shared_ptr<ModelAPI_Document> myDoc; ///< document this feature belongs to
public:
+ /// By default object is displayed in the object browser.
+ virtual bool isInHistory() {return true;}
- /// It is never located in history
- MODELAPI_EXPORT virtual bool isInHistory() {return false;}
+ /// Returns the data manager of this object: attributes
+ virtual boost::shared_ptr<ModelAPI_Data> data() {return myData;}
- /// Reference to the feature-operation that produces this object
- MODELAPI_EXPORT virtual FeaturePtr featureRef() = 0;
+ /// Returns true if feature refers to the same data model instance
+ virtual bool isSame(const boost::shared_ptr<ModelAPI_Object>& theObject)
+ {return theObject.get() == this;}
- /// Returns the name of this object (by default equal to the name of feature)
- MODELAPI_EXPORT virtual std::string getName() = 0;
+ /// Returns document this feature belongs to
+ virtual boost::shared_ptr<ModelAPI_Document> document()
+ {return myDoc;}
- /// Defines the name of the object
- MODELAPI_EXPORT virtual void setName(std::string theName) = 0;
-};
+ /// Returns the group identifier of this object
+ virtual std::string groupName() = 0;
+
+protected:
+ /// Sets the data manager of an object (document does)
+ virtual void setData(boost::shared_ptr<ModelAPI_Data> theData)
+ {myData = theData;}
+ /// Sets the data manager of an object (document does)
+ virtual void setDoc(boost::shared_ptr<ModelAPI_Document> theDoc) {myDoc = theDoc;}
+
+ friend class Model_Document;
+};
typedef boost::shared_ptr<ModelAPI_Object> ObjectPtr;
--- /dev/null
+// File: ModelAPI_Result.hxx
+// Created: 07 Jul 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef ModelAPI_Result_HeaderFile
+#define ModelAPI_Result_HeaderFile
+
+#include "ModelAPI_Object.h"
+
+class ModelAPI_Feature;
+
+/**\class ModelAPI_Result
+ * \ingroup DataModel
+ * \brief The result of a feature.
+ *
+ * A generic class that .
+ */
+class ModelAPI_Result : public ModelAPI_Object
+{
+public:
+ /// Returns the source feature of this result
+ //virtual boost::shared_ptr<ModelAPI_Feature> owner() = 0;
+
+ /// Returns the group identifier of this result
+ //virtual std::string groupName() = 0;
+};
+
+//! Pointer on feature object
+typedef boost::shared_ptr<ModelAPI_Result> ResultPtr;
+
+#endif
--- /dev/null
+// File: ModelAPI_ResultBody.hxx
+// Created: 07 Jul 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef ModelAPI_ResultBody_HeaderFile
+#define ModelAPI_ResultBody_HeaderFile
+
+#include "ModelAPI_Result.h"
+#include <GeomAPI_Shape.h>
+
+/**\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.
+ */
+class ModelAPI_ResultBody : public ModelAPI_Result
+{
+public:
+ /// Returns the group identifier of this result
+ virtual std::string groupName()
+ { return group(); }
+
+ /// Returns the group identifier of this result
+ static std::string group()
+ {static std::string MY_GROUP = "Bodies"; return MY_GROUP;}
+
+ /// Stores the shape (called by the execution method).
+ virtual void store(const boost::shared_ptr<GeomAPI_Shape>& theShape) = 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() {}
+
+protected:
+ /// Use plugin manager for features creation: this method is
+ /// defined here only for SWIG-wrapping
+ ModelAPI_ResultBody()
+ {}
+};
+
+//! Pointer on feature object
+typedef boost::shared_ptr<ModelAPI_ResultBody> ResultBodyPtr;
+
+#endif
--- /dev/null
+// File: ModelAPI_ResultConstruction.h
+// Created: 07 Jul 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef ModelAPI_ResultConstruction_HeaderFile
+#define ModelAPI_ResultConstruction_HeaderFile
+
+#include "ModelAPI_Result.h"
+#include <GeomAPI_Shape.h>
+
+/**\class ModelAPI_ResultConstruction
+ * \ingroup DataModel
+ * \brief The construction element result of a feature.
+ *
+ * Provides a shape that may be displayed in the viewer.
+ * Intermediate, light result that in many cases produces a result on the fly.
+ */
+class ModelAPI_ResultConstruction : public ModelAPI_Result
+{
+public:
+ /// Returns the group identifier of this result
+ virtual std::string groupName()
+ { return group(); }
+
+ /// Returns the group identifier of this result
+ static 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;
+
+ /// Sets the result
+ virtual void setShape(boost::shared_ptr<GeomAPI_Shape> theShape) = 0;
+};
+
+//! Pointer on feature object
+typedef boost::shared_ptr<ModelAPI_ResultConstruction> ResultConstructionPtr;
+
+#endif
--- /dev/null
+// File: ModelAPI_ResultParameters.h
+// Created: 07 Jul 2014
+// Author: Vitaly SMETANNIKOV
+
+#ifndef ModelAPI_ResultParameters_HeaderFile
+#define ModelAPI_ResultParameters_HeaderFile
+
+#include "ModelAPI_Result.h"
+
+/**\class ModelAPI_ResultParameters
+ * \ingroup DataModel
+ * \brief The construction element result of a feature.
+ *
+ * Provides a shape that may be displayed in the viewer.
+ * Intermediate, light result that in many cases produces a result on the fly.
+ */
+class ModelAPI_ResultParameters : public ModelAPI_Result
+{
+public:
+ /// Returns the group identifier of this result
+ virtual std::string groupName()
+ { return group(); }
+
+ /// Returns the group identifier of this result
+ static std::string group()
+ {static std::string MY_GROUP = "Parameters"; return MY_GROUP;}
+};
+
+//! Pointer on feature object
+typedef boost::shared_ptr<ModelAPI_ResultParameters> ResultParametersPtr;
+
+#endif
--- /dev/null
+// File: ModelAPI_ResultPart.h
+// Created: 07 Jul 2014
+// Author: Mikhail PONIKAROV
+
+#ifndef ModelAPI_ResultPart_HeaderFile
+#define ModelAPI_ResultPart_HeaderFile
+
+#include "ModelAPI_Result.h"
+
+/**\class ModelAPI_ResultPart
+ * \ingroup DataModel
+ * \brief The Part document, result of a creation of new part feature.
+ *
+ * This result leaves without feature: no parametricity for this element,
+ * only add/remove, undo/redo.
+ */
+class ModelAPI_ResultPart : public ModelAPI_Result
+{
+public:
+ /// Returns the group identifier of this result
+ virtual std::string groupName()
+ { return group(); }
+
+ /// Returns the group identifier of this result
+ static 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;
+};
+
+//! Pointer on feature object
+typedef boost::shared_ptr<ModelAPI_ResultPart> ResultPartPtr;
+
+#endif
ModuleBase_SelectionValidator.h
ModuleBase_ISelection.h
ModuleBase_ViewerPrs.h
+ ModuleBase_Tools.h
)
SET(PROJECT_SOURCES
ModuleBase_WidgetPoint2dDistance.cpp
ModuleBase_WidgetValue.cpp
ModuleBase_WidgetValueFeature.cpp
+ ModuleBase_Tools.cpp
)
SET(PROJECT_LIBRARIES
#include <QList>
#include <ModelAPI_Feature.h>
+#include <ModelAPI_Result.h>
typedef QList<int> QIntList; //!< list of int values
typedef QList<short> QShortList; //!< list of short int values
typedef QList<double> QDoubleList; //!< list of double values
typedef QList<FeaturePtr> QFeatureList; //!< List of features
+typedef QList<ResultPtr> QResultList; //!< List of results
#endif
\ No newline at end of file
/**
* Returns list of features currently selected in 3d viewer
*/
- virtual QFeatureList selectedFeatures() const = 0;
+ virtual QList<ObjectPtr> selectedObjects() const = 0;
+
+ /**
+ * Returns list of currently selected results
+ */
+ virtual QResultList selectedResults() const = 0;
//! Returns list of currently selected QModelIndexes
virtual QModelIndexList selectedIndexes() const = 0;
#include "ModuleBase.h"
-#include <ModelAPI_Feature.h>
+#include <ModelAPI_Object.h>
#include <AIS_InteractiveContext.hxx>
virtual Handle(AIS_InteractiveContext) AISContext() const = 0;
//! Returns list of currently selected data objects
- virtual QList<FeaturePtr> selectedFeatures() const = 0;
+ virtual QList<ObjectPtr> selectedObjects() const = 0;
//! Returns instance of loaded module
virtual ModuleBase_IModule* module() const = 0;
myAttributeID = theData ? theData->widgetId() : "";
}
-bool ModuleBase_ModelWidget::isInitialized(FeaturePtr theFeature) const
+bool ModuleBase_ModelWidget::isInitialized(ObjectPtr theObject) const
{
- return theFeature->data()->attribute(attributeID())->isInitialized();
+ return theObject->data()->attribute(attributeID())->isInitialized();
}
bool ModuleBase_ModelWidget::focusTo()
virtual bool setValue(ModuleBase_WidgetValue* theValue) { return false; };
/// Returns the state whether the attribute of the feature is initialized
- /// \param theFeature a model feature to be checked
+ /// \param theObject a model feature to be checked
/// \return the boolean result
- bool isInitialized(FeaturePtr theFeature) const;
+ bool isInitialized(ObjectPtr theObject) const;
/// Saves the internal parameters to the given feature
- /// \param theFeature a model feature to be changed
- virtual bool storeValue(FeaturePtr theFeature) const = 0;
+ /// \param theObject a model feature to be changed
+ virtual bool storeValue(ObjectPtr theObject) const = 0;
- virtual bool restoreValue(FeaturePtr theFeature) = 0;
+ virtual bool restoreValue(ObjectPtr theObject) = 0;
/// Set focus to the first control of the current widget. The focus policy of the control is checked.
/// If the widget has the NonFocus focus policy, it is skipped.
void ModuleBase_Operation::flushUpdated()
{
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
}
void ModuleBase_Operation::flushCreated()
{
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_CREATED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
}
FeaturePtr ModuleBase_Operation::createFeature(const bool theFlushMessage)
--- /dev/null
+// File: ModuleBase_Tools.cpp
+// Created: 11 July 2014
+// Author: Vitaly Smetannikov
+
+#include "ModuleBase_Tools.h"
+#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_ResultConstruction.h>
+
+namespace ModuleBase_Tools
+{
+
+//******************************************************************
+boost::shared_ptr<GeomAPI_Shape> shape(ResultPtr theResult)
+{
+ ResultBodyPtr aBody = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
+ if (aBody)
+ return aBody->shape();
+
+ ResultConstructionPtr aConstruct = boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theResult);
+ if (aConstruct)
+ return aConstruct->shape();
+
+ return boost::shared_ptr<GeomAPI_Shape>();
+}
+
+}
\ No newline at end of file
--- /dev/null
+// File: ModuleBase_Tools.h
+// Created: 11 July 2014
+// Author: Vitaly Smetannikov
+
+
+#ifndef ModuleBase_Tools_H
+#define ModuleBase_Tools_H
+
+#include "ModuleBase.h"
+
+#include <ModelAPI_Result.h>
+
+class GeomAPI_Shape;
+
+namespace ModuleBase_Tools
+{
+
+ /**
+ * Returns returns a shape if the result has a shape method. Otherwise returns NULL pointer
+ */
+ MODULEBASE_EXPORT boost::shared_ptr<GeomAPI_Shape> shape(ResultPtr theResult);
+
+};
+
+#endif
\ No newline at end of file
#include <TopoDS_Shape.hxx>
#include <SelectMgr_EntityOwner.hxx>
-#include <ModelAPI_Feature.h>
+#include <ModelAPI_Result.h>
/**\class ModuleBase_ViewerPrs
* \ingroup Module base
/// \param theFeature a model feature
/// \param theShape a viewer shape
/// \param theOwner a selection owner
- ModuleBase_ViewerPrs(FeaturePtr theFeature,
+ ModuleBase_ViewerPrs(ResultPtr theResult,
const TopoDS_Shape& theShape,
Handle_SelectMgr_EntityOwner theOwner)
- : myFeature(theFeature), myShape(theShape), myOwner(theOwner) {}
+ : myResult(theResult), myShape(theShape), myOwner(theOwner) {}
/// Destructor
virtual ~ModuleBase_ViewerPrs() {}
/// Sets the feature.
/// \param theFeature a feature instance
- void setFeature(FeaturePtr theFeature) { myFeature = theFeature; }
+ void setFeature(ResultPtr theResult) { myResult = theResult; }
/// Returns the feature.
/// \return a feature instance
- FeaturePtr feature() const { return myFeature; }
+ ResultPtr result() const { return myResult; }
/// Returns the presentation owner
/// \param the owner
bool operator==(const ModuleBase_ViewerPrs& thePrs)
{
- bool aFeature = (myFeature.get() == thePrs.feature().get());
+ bool aResult = (myResult.get() == thePrs.result().get());
bool aOwner = (myOwner.Access() == thePrs.owner().Access());
bool aShape = myShape.IsEqual(thePrs.shape());
- return aFeature && aOwner && aShape;
+ return aResult && aOwner && aShape;
}
private:
- FeaturePtr myFeature; /// the feature
+ ResultPtr myResult; /// the feature
Handle(SelectMgr_EntityOwner) myOwner; /// the selection owner
TopoDS_Shape myShape; /// the shape
};
return myCheckBox;
}
-bool ModuleBase_WidgetBoolValue::storeValue(FeaturePtr theFeature) const
+bool ModuleBase_WidgetBoolValue::storeValue(ObjectPtr theObject) const
{
- DataPtr aData = theFeature->data();
+ DataPtr aData = theObject->data();
boost::shared_ptr<ModelAPI_AttributeBoolean> aBool = aData->boolean(attributeID());
if (aBool->value() != myCheckBox->isChecked()) {
aBool->setValue(myCheckBox->isChecked());
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
}
return true;
}
-bool ModuleBase_WidgetBoolValue::restoreValue(FeaturePtr theFeature)
+bool ModuleBase_WidgetBoolValue::restoreValue(ObjectPtr theObject)
{
- DataPtr aData = theFeature->data();
+ DataPtr aData = theObject->data();
boost::shared_ptr<ModelAPI_AttributeBoolean> aRef = aData->boolean(attributeID());
bool isBlocked = myCheckBox->blockSignals(true);
virtual ~ModuleBase_WidgetBoolValue();
/// Saves the internal parameters to the given feature
- /// \param theFeature a model feature to be changed
- virtual bool storeValue(FeaturePtr theFeature) const;
+ /// \param theObject a model feature to be changed
+ virtual bool storeValue(ObjectPtr theObject) const;
- virtual bool restoreValue(FeaturePtr theFeature);
+ virtual bool restoreValue(ObjectPtr theObject);
/// Returns list of widget controls
/// \return a control list
{
}
-bool ModuleBase_WidgetDoubleValue::storeValue(FeaturePtr theFeature) const
+bool ModuleBase_WidgetDoubleValue::storeValue(ObjectPtr theObject) const
{
- DataPtr aData = theFeature->data();
+ DataPtr aData = theObject->data();
AttributeDoublePtr aReal = aData->real(attributeID());
if (aReal->value() != mySpinBox->value()) {
aReal->setValue(mySpinBox->value());
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
}
return true;
}
-bool ModuleBase_WidgetDoubleValue::restoreValue(FeaturePtr theFeature)
+bool ModuleBase_WidgetDoubleValue::restoreValue(ObjectPtr theObject)
{
- DataPtr aData = theFeature->data();
+ DataPtr aData = theObject->data();
AttributeDoublePtr aRef = aData->real(attributeID());
bool isBlocked = mySpinBox->blockSignals(true);
virtual ~ModuleBase_WidgetDoubleValue();
/// Saves the internal parameters to the given feature
- /// \param theFeature a model feature to be changed
- virtual bool storeValue(FeaturePtr theFeature) const;
+ /// \param theObject a model feature to be changed
+ virtual bool storeValue(ObjectPtr theObject) const;
- virtual bool restoreValue(FeaturePtr theFeature);
+ virtual bool restoreValue(ObjectPtr theObject);
/// Returns list of widget controls
/// \return a control list
if (theValue) {
ModuleBase_WidgetValueFeature* aFeatureValue =
dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
- if (aFeatureValue)
- isDone = setFeature(aFeatureValue->feature());
+ // TODO
+// if (aFeatureValue)
+// isDone = setFeature(aFeatureValue->feature());
}
return isDone;
}
bool ModuleBase_WidgetFeature::setFeature(const FeaturePtr& theFeature)
{
- if (!theFeature || !myFeatureKinds.contains(theFeature->getKind().c_str()))
+ if (!myFeatureKinds.contains(theFeature->getKind().c_str()))
return false;
myFeature = theFeature;
- myEditor->setText(theFeature ? theFeature->data()->getName().c_str() : "");
+ myEditor->setText(theFeature ? theFeature->data()->name().c_str() : "");
emit valuesChanged();
return true;
}
-bool ModuleBase_WidgetFeature::storeValue(FeaturePtr theFeature) const
+bool ModuleBase_WidgetFeature::storeValue(ObjectPtr theObject) const
{
- boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
+ if (!aFeature)
+ return false;
+ boost::shared_ptr<ModelAPI_Data> aData = aFeature->data();
boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(attributeID()));
ModuleBase_WidgetFeature* that = (ModuleBase_WidgetFeature*) this;
- aRef->setFeature(myFeature);
- theFeature->execute();
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+ aRef->setObject(myFeature);
+ aFeature->execute();
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
return true;
}
-bool ModuleBase_WidgetFeature::restoreValue(FeaturePtr theFeature)
+bool ModuleBase_WidgetFeature::restoreValue(ObjectPtr theObject)
{
- boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ boost::shared_ptr<ModelAPI_Data> aData = theObject->data();
boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(attributeID()));
- myFeature = aRef->feature();
- myEditor->setText(myFeature ? myFeature->data()->getName().c_str() : "");
- return true;
+ FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aRef->object());
+ if (aFeature) {
+ myFeature = aFeature;
+ myEditor->setText(myFeature ? myFeature->data()->name().c_str() : "");
+ return true;
+ }
+ return false;
}
QWidget* ModuleBase_WidgetFeature::getControl() const
/// Saves the internal parameters to the given feature
/// \param theFeature a model feature to be changed
- virtual bool storeValue(FeaturePtr theFeature) const;
+ virtual bool storeValue(ObjectPtr theObject) const;
- virtual bool restoreValue(FeaturePtr theFeature);
+ virtual bool restoreValue(ObjectPtr theObject);
/// Returns the internal parent wiget control, that can be shown anywhere
/// \returns the widget
/// Fill the widget values by given point
/// \param thePoint the point
/// \return the boolean result of the feature set
- bool setFeature(const FeaturePtr& theFeature);
+ bool setFeature(const FeaturePtr& theObject);
/// Returns current widget feature
/// \return the feature
- const FeaturePtr& feature() const { return myFeature; }
+ const FeaturePtr feature() const { return myFeature; }
/// Returns the widget editor
/// \return the editor
dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
if (aFeatureValue) {
boost::shared_ptr<GeomAPI_Pnt2d> aValuePoint = aFeatureValue->point();
- FeaturePtr aValueFeature = aFeatureValue->feature();
+ //TODO
+/* FeaturePtr aValueFeature = aFeatureValue->feature();
if (aValueFeature) {
isDone = setFeature(aValueFeature);
}
}
if (aFPoint)
isDone = setAttribute(aFPoint);
- }
+ }*/
}
}
return isDone;
ModuleBase_WidgetFeatureOrAttribute* that = (ModuleBase_WidgetFeatureOrAttribute*) this;
if (feature())
- aRef->setFeature(feature());
+ aRef->setObject(feature());
else if (myAttribute)
aRef->setAttr(myAttribute);
theFeature->execute();
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
return true;
}
boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(attributeID()));
- FeaturePtr aFeature = aRef->feature();
- setFeature(aFeature);
- myAttribute = aRef->attr();
+ FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aRef->object());
+ if (aFeature) {
+ setFeature(aFeature);
+ myAttribute = aRef->attr();
- std::string aText = "";
- if (aFeature)
- aText = aFeature->data()->getName().c_str();
- else if (myAttribute)
- aText = myAttribute->attributeType().c_str();
+ std::string aText = "";
+ if (aFeature)
+ aText = aFeature->data()->name().c_str();
+ else if (myAttribute)
+ aText = myAttribute->attributeType().c_str();
- editor()->setText(aText.c_str());
- return true;
+ editor()->setText(aText.c_str());
+ return true;
+ }
+ return false;
}
bool ModuleBase_WidgetFeatureOrAttribute::setAttribute(const boost::shared_ptr<ModelAPI_Attribute>& theAttribute)
emit valuesChanged();
}
-bool ModuleBase_WidgetPoint2D::storeValue(FeaturePtr theFeature) const
+bool ModuleBase_WidgetPoint2D::storeValue(ObjectPtr theObject) const
{
- boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ boost::shared_ptr<ModelAPI_Data> aData = theObject->data();
boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(attributeID()));
ModuleBase_WidgetPoint2D* that = (ModuleBase_WidgetPoint2D*) this;
bool isBlocked = that->blockSignals(true);
aPoint->setValue(myXSpin->value(), myYSpin->value());
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
that->blockSignals(isBlocked);
return true;
}
-bool ModuleBase_WidgetPoint2D::restoreValue(FeaturePtr theFeature)
+bool ModuleBase_WidgetPoint2D::restoreValue(ObjectPtr theObject)
{
- boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ boost::shared_ptr<ModelAPI_Data> aData = theObject->data();
boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(attributeID()));
return ModuleBase_ModelWidget::eventFilter(theObject, theEvent);
}
-bool ModuleBase_WidgetPoint2D::initFromPrevious(FeaturePtr theFeature)
+bool ModuleBase_WidgetPoint2D::initFromPrevious(ObjectPtr theObject)
{
if (myOptionParam.length() == 0)
return false;
- boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ boost::shared_ptr<ModelAPI_Data> aData = theObject->data();
boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(myOptionParam));
if (aPoint) {
this->blockSignals(isBlocked);
emit valuesChanged();
- emit storedPoint2D(theFeature, myOptionParam);
+ emit storedPoint2D(theObject, myOptionParam);
return true;
}
return false;
virtual bool setValue(ModuleBase_WidgetValue* theValue);
/// Saves the internal parameters to the given feature
- /// \param theFeature a model feature to be changed
- virtual bool storeValue(FeaturePtr theFeature) const;
+ /// \param theObject a model feature to be changed
+ virtual bool storeValue(ObjectPtr theObject) const;
- virtual bool restoreValue(FeaturePtr theFeature);
+ virtual bool restoreValue(ObjectPtr theObject);
/// Returns the internal parent wiget control, that can be shown anywhere
/// \returns the widget
/// \param theEvent the processed event
virtual bool eventFilter(QObject *theObject, QEvent *theEvent);
- bool initFromPrevious(FeaturePtr theFeature);
+ bool initFromPrevious(ObjectPtr theObject);
signals:
/// Signal about the point 2d set to the feature
/// \param the feature
/// \param the attribute of the feature
- void storedPoint2D(FeaturePtr theFeature, const std::string& theAttribute);
+ void storedPoint2D(ObjectPtr theObject, const std::string& theAttribute);
protected:
/// Fill the widget values by given point
dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
if (aFeatureValue) {
boost::shared_ptr<GeomAPI_Pnt2d> aPnt = aFeatureValue->point();
- FeaturePtr aFeature = aFeatureValue->feature();
+ // TODO
+ /*FeaturePtr aFeature = aFeatureValue->feature();
if (aFeature && aPnt) {
setPoint(aFeature, aPnt);
isDone = true;
- }
+ }*/
}
}
return isDone;
#include "ModuleBase_WidgetSelector.h"
#include "ModuleBase_IWorkshop.h"
+#include "ModuleBase_Tools.h"
#include <Events_Loop.h>
#include <Model_Events.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Object.h>
+#include <ModelAPI_Result.h>
#include <ModelAPI_AttributeReference.h>
#include <Config_WidgetAPI.h>
}
//********************************************************************
-bool ModuleBase_WidgetSelector::storeValue(FeaturePtr theFeature) const
+bool ModuleBase_WidgetSelector::storeValue(ObjectPtr theObject) const
{
- DataPtr aData = theFeature->data();
+ DataPtr aData = theObject->data();
boost::shared_ptr<ModelAPI_AttributeReference> aRef =
boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(aData->attribute(attributeID()));
- FeaturePtr aFeature = aRef->value();
- if (!(aFeature && aFeature->isSame(mySelectedFeature))) {
- aRef->setValue(mySelectedFeature);
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+ ObjectPtr aObject = aRef->value();
+ if (!(aObject && aObject->isSame(mySelectedObject))) {
+ aRef->setValue(mySelectedObject);
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
}
return true;
}
//********************************************************************
-bool ModuleBase_WidgetSelector::restoreValue(FeaturePtr theFeature)
+bool ModuleBase_WidgetSelector::restoreValue(ObjectPtr theObject)
{
- DataPtr aData = theFeature->data();
+ DataPtr aData = theObject->data();
boost::shared_ptr<ModelAPI_AttributeReference> aRef = aData->reference(attributeID());
bool isBlocked = this->blockSignals(true);
- mySelectedFeature = aRef->value();
+ mySelectedObject = aRef->value();
updateSelectionName();
this->blockSignals(isBlocked);
//********************************************************************
void ModuleBase_WidgetSelector::onSelectionChanged()
{
- QList<FeaturePtr> aFeatures = myWorkshop->selectedFeatures();
- if (aFeatures.size() > 0) {
- FeaturePtr aFeature = aFeatures.first();
- if ((!mySelectedFeature) && (!aFeature))
+ QList<ObjectPtr> aObjects = myWorkshop->selectedObjects();
+ if (aObjects.size() > 0) {
+ ObjectPtr aObject = aObjects.first();
+ if ((!mySelectedObject) && (!aObject))
return;
- if (mySelectedFeature && aFeature && mySelectedFeature->isSame(aFeature))
+ if (mySelectedObject && aObject && mySelectedObject->isSame(aObject))
return;
// Check that the selection corresponds to selection type
- if (!isAccepted(aFeature)) return;
+ if (!isAccepted(aObject)) return;
- mySelectedFeature = aFeature;
- if (mySelectedFeature) {
+ mySelectedObject = aObject;
+ if (mySelectedObject) {
updateSelectionName();
activateSelection(false);
raisePanel();
}
//********************************************************************
-bool ModuleBase_WidgetSelector::isAccepted(const FeaturePtr theFeature) const
+bool ModuleBase_WidgetSelector::isAccepted(const ObjectPtr theResult) const
{
- boost::shared_ptr<GeomAPI_Shape> aShapePtr = theFeature->data()->shape();
+ ResultPtr aResult = boost::dynamic_pointer_cast<ModelAPI_Result>(theResult);
+ boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModuleBase_Tools::shape(aResult);
if (!aShapePtr) return false;
TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
if (aShape.IsNull()) return false;
//********************************************************************
void ModuleBase_WidgetSelector::updateSelectionName()
{
- if (mySelectedFeature) {
- std::string aName;
- if (mySelectedFeature->data())
- aName = mySelectedFeature->data()->getName();
- else
- aName = boost::dynamic_pointer_cast<ModelAPI_Object>(mySelectedFeature)->getName();
+ if (mySelectedObject) {
+ std::string aName = mySelectedObject->data()->name();
myTextLine->setText(QString::fromStdString(aName));
} else
#include "ModuleBase.h"
#include "ModuleBase_ModelWidget.h"
-#include <ModelAPI_Feature.h>
+#include <ModelAPI_Object.h>
#include <TopAbs_ShapeEnum.hxx>
virtual ~ModuleBase_WidgetSelector();
/// Saves the internal parameters to the given feature
- /// \param theFeature a model feature to be changed
- virtual bool storeValue(FeaturePtr theFeature) const;
+ /// \param theObject a model feature to be changed
+ virtual bool storeValue(ObjectPtr theObject) const;
- virtual bool restoreValue(FeaturePtr theFeature);
+ virtual bool restoreValue(ObjectPtr theObject);
/// Returns the internal parent wiget control, that can be shown anywhere
/// \returns the widget
void setActivationOnStart(bool toActivate) { myActivateOnStart = toActivate; }
bool activateOnStart() const { return myActivateOnStart; }
- FeaturePtr selectedFeature() const { return mySelectedFeature; }
+ ObjectPtr selectedFeature() const { return mySelectedObject; }
public slots:
void enableOthersControls(bool toEnable) const;
void updateSelectionName();
void raisePanel() const;
- bool isAccepted(const FeaturePtr theFeature) const;
+ bool isAccepted(const ObjectPtr theObject) const;
static TopAbs_ShapeEnum shapeType(const QString& theType);
bool myActivateOnStart;
- FeaturePtr mySelectedFeature;
+ ObjectPtr mySelectedObject;
QStringList myShapeTypes;
};
{
}
-void ModuleBase_WidgetValueFeature::setFeature(const FeaturePtr& theFeature)
+void ModuleBase_WidgetValueFeature::setResult(const ResultPtr& theFeature)
{
- myFeature = theFeature;
+ myResult = theFeature;
}
-const FeaturePtr& ModuleBase_WidgetValueFeature::feature() const
+const ResultPtr& ModuleBase_WidgetValueFeature::result() const
{
- return myFeature;
+ return myResult;
}
void ModuleBase_WidgetValueFeature::setPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint)
#include <ModuleBase.h>
#include <ModuleBase_WidgetValue.h>
-#include <ModelAPI_Feature.h>
+#include <ModelAPI_Result.h>
#include <boost/shared_ptr.hpp>
/// Fill the widget values by given point
/// \param thePoint the point
- void setFeature(const FeaturePtr& theFeature);
+ void setResult(const ResultPtr& theFeature);
/// Returns the widget values by given point
/// \return theFeature the current feature
- const FeaturePtr& feature() const;
+ const ResultPtr& result() const;
/// Fill the widget values by given point
/// \param thePoint the point
const boost::shared_ptr<GeomAPI_Pnt2d>& point() const;
private:
- FeaturePtr myFeature;
+ ResultPtr myResult;
boost::shared_ptr<GeomAPI_Pnt2d> myPoint;
};
: myModule(theModule)
{
Events_Loop* aLoop = Events_Loop::loop();
- aLoop->registerListener(this, aLoop->eventByName(EVENT_FEATURE_UPDATED));
- aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_CREATED));
- aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_DELETED));
+ aLoop->registerListener(this, aLoop->eventByName(EVENT_OBJECT_UPDATED));
+ aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+ aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
}
PartSet_Listener::~PartSet_Listener()
void PartSet_Listener::processEvent(const Events_Message* theMessage)
{
QString aType = QString(theMessage->eventID().eventText());
- if (aType == EVENT_FEATURE_UPDATED ||
- aType == EVENT_FEATURE_CREATED)
+ if (aType == EVENT_OBJECT_UPDATED ||
+ aType == EVENT_OBJECT_CREATED)
{
- const ModelAPI_FeatureUpdatedMessage* aUpdMsg =
- dynamic_cast<const ModelAPI_FeatureUpdatedMessage*>(theMessage);
- std::set<FeaturePtr > aFeatures = aUpdMsg->features();
- std::set<FeaturePtr >::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
+ const ModelAPI_ObjectUpdatedMessage* aUpdMsg =
+ dynamic_cast<const ModelAPI_ObjectUpdatedMessage*>(theMessage);
+ std::set<ObjectPtr > aFeatures = aUpdMsg->features();
+ std::set<ObjectPtr >::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
for (; anIt != aLast; anIt++) {
- FeaturePtr aFeature = *anIt;
- if (myModule->workshop()->displayer()->isVisible(aFeature) ||
- aType == EVENT_FEATURE_CREATED) {
- myModule->visualizePreview(aFeature, true, false);
- //if (aType == EVENT_FEATURE_CREATED)
+ ObjectPtr aObject = *anIt;
+ FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
+ if (aFeature) {
+ if (myModule->workshop()->displayer()->isVisible(aFeature->firstResult()) ||
+ aType == EVENT_OBJECT_CREATED) {
+ myModule->visualizePreview(aFeature->firstResult(), true, false);
+ //if (aType == EVENT_OBJECT_CREATED)
myModule->activateFeature(aFeature, true);
+ }
}
}
myModule->workshop()->displayer()->updateViewer();
}
- if (aType == EVENT_FEATURE_DELETED)
+ if (aType == EVENT_OBJECT_DELETED)
{
- const ModelAPI_FeatureDeletedMessage* aDelMsg =
- dynamic_cast<const ModelAPI_FeatureDeletedMessage*>(theMessage);
+ const ModelAPI_ObjectDeletedMessage* aDelMsg =
+ dynamic_cast<const ModelAPI_ObjectDeletedMessage*>(theMessage);
boost::shared_ptr<ModelAPI_Document> aDoc = aDelMsg->document();
std::set<std::string> aGroups = aDelMsg->groups();
for (; anIt != aLast; anIt++) {
std::string aGroup = *anIt;
if (aGroup.compare(SketchPlugin_Sketch::ID()) == 0) { // Update only Sketch group
- myModule->workshop()->displayer()->eraseDeletedFeatures();
+ myModule->workshop()->displayer()->eraseDeletedResults();
myModule->updateCurrentPreview(aGroup);
}
}
//!! Test registering of validators
PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
-
aFactory->registerValidator("PartSet_DistanceValidator", new PartSet_DistanceValidator);
- aFactory->assignValidator("PartSet_DistanceValidator", "SketchConstraintDistance");
-
aFactory->registerValidator("PartSet_LengthValidator", new PartSet_LengthValidator);
- aFactory->assignValidator("PartSet_LengthValidator", "SketchConstraintLength");
+ aFactory->registerValidator("PartSet_PerpendicularValidator", new PartSet_PerpendicularValidator);
+ aFactory->registerValidator("PartSet_ParallelValidator", new PartSet_ParallelValidator);
+ aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator);
}
void PartSet_Module::featureCreated(QAction* theFeature)
void PartSet_Module::onContextMenuCommand(const QString& theId, bool isChecked)
{
- QFeatureList aFeatures = myWorkshop->selector()->selection()->selectedFeatures();
+ QList<ObjectPtr> aFeatures = myWorkshop->selector()->selection()->selectedObjects();
if (theId == "EDIT_CMD" && (aFeatures.size() > 0)) {
- editFeature(aFeatures.first());
+ FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aFeatures.first());
+ if (aFeature)
+ editFeature(aFeature);
}
}
activateFeature((*anIt), false);
}
}
- aDisplayer->stopSelection(theFeatures, isStop, false);
+ QResultList aResults;
+ foreach(FeaturePtr aFeature, theFeatures) {
+ if (aFeature->results().size() > 0) {
+ std::list<ResultPtr>& aResList = aFeature->results();
+ std::list<ResultPtr>::iterator aIt;
+ for (aIt = aResList.begin(); aIt != aResList.end(); ++aIt)
+ aResults.append(*aIt);
+ }
+ }
+ aDisplayer->stopSelection(aResults, isStop, false);
XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
aViewer->enableSelection(!isStop);
aDisplayer->updateViewer();
}
-void PartSet_Module::onSetSelection(const QFeatureList& theFeatures)
+void PartSet_Module::onSetSelection(const QResultList& theFeatures)
{
XGUI_Displayer* aDisplayer = myWorkshop->displayer();
aDisplayer->setSelected(theFeatures, false);
void PartSet_Module::onFeatureConstructed(FeaturePtr theFeature, int theMode)
{
bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Hide;
- visualizePreview(theFeature, isDisplay, false);
+ // TODO visualizePreview(theFeature, isDisplay, false);
if (!isDisplay) {
ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
FeaturePtr aSketch;
std::list<FeaturePtr>::const_iterator anIt = aList.begin(),
aLast = aList.end();
for (; anIt != aLast; anIt++)
- visualizePreview(*anIt, false, false);
+ visualizePreview((*anIt)->firstResult(), false, false);
aDisplayer->updateViewer();
}
}
Events_Loop::loop()->send(aMessage);
}
-void PartSet_Module::visualizePreview(FeaturePtr theFeature, bool isDisplay,
+void PartSet_Module::visualizePreview(ResultPtr theFeature, bool isDisplay,
const bool isUpdateViewer)
{
ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
if (aPreviewOp) {
XGUI_Displayer* aDisplayer = myWorkshop->displayer();
- aDisplayer->activateInLocalContext(theFeature, aPreviewOp->getSelectionModes(theFeature),
+ aDisplayer->activateInLocalContext(theFeature->firstResult(), aPreviewOp->getSelectionModes(theFeature),
isUpdateViewer);
}
}
boost::dynamic_pointer_cast<SketchPlugin_Feature>(*anIt);
if (!aSPFeature)
continue;
- visualizePreview(*anIt, true, false);
- aDisplayer->activateInLocalContext(*anIt, aModes, false);
+ visualizePreview((*anIt)->firstResult(), true, false);
+ aDisplayer->activateInLocalContext((*anIt)->firstResult(), aModes, false);
}
aDisplayer->updateViewer();
}
if (!theFeature)
return;
-// if (theFeature->getKind() == SketchPlugin_Sketch::ID()) {
- FeaturePtr aFeature = theFeature;
- if (XGUI_Tools::isModelObject(aFeature)) {
- ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
- aFeature = aObject->featureRef();
- }
-
- if (aFeature) {
- onLaunchOperation(aFeature->getKind(), aFeature);
- updateCurrentPreview(aFeature->getKind());
- }
+// if (theFeature->getKind() == SKETCH_KIND) {
+ //FeaturePtr aFeature = theFeature;
+ //if (XGUI_Tools::isModelObject(aFeature)) {
+ // ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
+ // aFeature = aObject->featureRef();
+ //}
+
+ //if (aFeature) {
+ onLaunchOperation(theFeature->getKind(), theFeature);
+ updateCurrentPreview(theFeature->getKind());
+ //}
// }
}
/// \param theFeature the feature instance to be displayed
/// \param isDisplay the state whether the presentation should be displayed or erased
/// \param isUpdateViewer the flag whether the viewer should be updated
- void visualizePreview(FeaturePtr theFeature, bool isDisplay,
+ void visualizePreview(ResultPtr theResult, bool isDisplay,
const bool isUpdateViewer = true);
/// Activates the feature in the displayer
/// SLOT, to set selection
/// \param theFeatures a list of features to be selected
- void onSetSelection(const QFeatureList& theFeatures);
+ void onSetSelection(const QResultList& theFeatures);
/// SLOT, to close the viewer local context
void onCloseLocalContext();
}
}
}
- FeaturePtr aFeature;
+ ResultPtr aFeature;
if (!theSelected.empty()) {
ModuleBase_ViewerPrs aPrs = theSelected.front();
- aFeature = aPrs.feature();
+ aFeature = aPrs.result();
}
- else
- aFeature = feature(); // for the widget distance only
+ // TODO
+ //else
+ // aFeature = feature(); // for the widget distance only
- bool isApplyed = setWidgetValue(aFeature, aX, anY);
+ // TODO
+ /*bool isApplyed = setWidgetValue(aFeature, aX, anY);
if (isApplyed) {
flushUpdated();
emit activateNextWidget(myActiveWidget);
- }
+ }*/
}
void PartSet_OperationFeatureCreate::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
if ((myPreSelection.size() > 0) && myActiveWidget) {
const ModuleBase_ViewerPrs& aPrs = myPreSelection.front();
ModuleBase_WidgetValueFeature aValue;
- aValue.setFeature(aPrs.feature());
+ aValue.setResult(aPrs.result());
if (myActiveWidget->setValue(&aValue)) {
myPreSelection.remove(aPrs);
emit activateNextWidget(myActiveWidget);
bool PartSet_OperationFeatureCreate::setWidgetValue(FeaturePtr theFeature, double theX, double theY)
{
ModuleBase_WidgetValueFeature* aValue = new ModuleBase_WidgetValueFeature();
- aValue->setFeature(theFeature);
+ aValue->setResult(theFeature->firstResult());
aValue->setPoint(boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY)));
bool isApplyed = myActiveWidget->setValue(aValue);
const std::list<ModuleBase_ViewerPrs>& theSelected,
const std::list<ModuleBase_ViewerPrs>& theHighlighted)
{
- FeaturePtr aFeature;
+ ResultPtr aFeature;
if (!theHighlighted.empty())
- aFeature = theHighlighted.front().feature();
+ aFeature = theHighlighted.front().result();
if (!aFeature && !theSelected.empty()) // changed for a constrain
- aFeature = theSelected.front().feature();
-
- if (!aFeature || aFeature != feature())
+ aFeature = theSelected.front().result();
+ // TODO
+ /*if (!aFeature || aFeature != feature())
{
commit();
emit featureConstructed(feature(), FM_Deactivation);
bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
if(aHasShift && !theHighlighted.empty()) {
- QFeatureList aSelected;
+ QResultList aSelected;
+ // TODO
aSelected.push_back(feature());
- aSelected.push_back(theHighlighted.front().feature());
+ aSelected.push_back(theHighlighted.front().result());
emit setSelection(aSelected);
}
+ // TODO
else if (aFeature) {
restartOperation(PartSet_OperationFeatureEdit::Type(), aFeature);
}
- }
+ }*/
}
void PartSet_OperationFeatureEdit::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
void PartSet_OperationFeatureEdit::sendFeatures()
{
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_MOVED);
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
FeaturePtr aFeature = feature();
ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
// deselected in the viewer by blockSelection signal in the startOperation method.
bool isSelected = false;
std::list<ModuleBase_ViewerPrs>::const_iterator anIt = theSelected.begin(), aLast = theSelected.end();
- for (; anIt != aLast && !isSelected; anIt++) {
+ // TODO
+ /*for (; anIt != aLast && !isSelected; anIt++) {
isSelected = (*anIt).feature() == feature();
- }
+ }*/
if (!isSelected)
myFeatures = theHighlighted;
else
aSketchFeature->move(aDeltaX, aDeltaY);
std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end();
- for (; anIt != aLast; anIt++) {
+ // TODO
+ /*for (; anIt != aLast; anIt++) {
FeaturePtr aFeature = (*anIt).feature();
if (!aFeature || aFeature == feature())
continue;
aSketchFeature = boost::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
aSketchFeature->move(aDeltaX, aDeltaY);
- }
+ }*/
}
sendFeatures();
std::list<ModuleBase_ViewerPrs> aFeatures = myFeatures;
commit();
std::list<ModuleBase_ViewerPrs>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
- for (; anIt != aLast; anIt++) {
+ // TODO
+ /*for (; anIt != aLast; anIt++) {
FeaturePtr aFeature = (*anIt).feature();
if (aFeature) {
emit featureConstructed(aFeature, FM_Deactivation);
}
- }
+ }*/
}
void PartSet_OperationFeatureEditMulti::startOperation()
QFeatureList aFeatureList;
std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(),
aLast = myFeatures.end();
- for(; anIt != aLast; anIt++)
- aFeatureList.append((*anIt).feature());
+ /*for(; anIt != aLast; anIt++)
+ aFeatureList.append((*anIt).feature());*/
if (isBlocked) {
emit setSelection(QFeatureList());
emit stopSelection(aFeatureList, true);
void PartSet_OperationFeatureEditMulti::sendFeatures()
{
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_MOVED);
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
std::list<FeaturePtr > aFeatures;
std::list<ModuleBase_ViewerPrs>::const_iterator anIt = myFeatures.begin(), aLast = myFeatures.end();
- for (; anIt != aLast; anIt++) {
+ // TODO
+ /*for (; anIt != aLast; anIt++) {
FeaturePtr aFeature = (*anIt).feature();
if (!aFeature)
continue;
ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
- }
+ }*/
Events_Loop::loop()->flush(anEvent);
flushUpdated();
}
return;
if (theHighlighted.size() == 1) {
- FeaturePtr aFeature = theHighlighted.front().feature();
+ ResultPtr aFeature = theHighlighted.front().result();
if (aFeature) {
std::string anOperationType = PartSet_OperationFeatureEdit::Type();
if (theSelected.size() > 1)
anOperationType = PartSet_OperationFeatureEditMulti::Type();
- restartOperation(anOperationType, aFeature);
+ // TODO restartOperation(anOperationType, aFeature);
}
}
else
/// It is empty and we have to use the process mouse release to start edition operation
/// for these objects
if (theSelected.size() == 1) {
- FeaturePtr aFeature = theSelected.front().feature();
- if (aFeature)
- restartOperation(PartSet_OperationFeatureEdit::Type(), aFeature);
+ ResultPtr aFeature = theSelected.front().result();
+ // TODO
+ //if (aFeature)
+ // restartOperation(PartSet_OperationFeatureEdit::Type(), aFeature);
}
}
}
boost::shared_ptr<ModelAPI_AttributeRefList> aRefList =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(aData->attribute(SketchPlugin_Sketch::FEATURES_ID()));
- return aRefList->list();
+ std::list<ObjectPtr> aList = aRefList->list();
+ std::list<ObjectPtr>::iterator aIt;
+ std::list<FeaturePtr> aFeaList;
+ for (aIt = aList.begin(); aIt != aList.end(); ++aIt) {
+ FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(*aIt);
+ if (aFeature)
+ aFeaList.push_back(aFeature);
+ }
+ return aFeaList;
}
void PartSet_OperationSketch::stopOperation()
#include <PartSet_OperationSketchBase.h>
#include <PartSet_Tools.h>
+#include <ModelAPI_ResultBody.h>
#include <SketchPlugin_Feature.h>
#include <V3d_View.hxx>
{
boost::shared_ptr<SketchPlugin_Feature> aFeature =
boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
- if (!aFeature)
- return boost::shared_ptr<GeomAPI_Shape>();
- return aFeature->preview();
+ if (aFeature) {
+ ResultPtr aRes = aFeature->firstResult();
+ ResultBodyPtr aBody = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(aRes);
+ if (aBody)
+ return aBody->shape();
+ }
+ return boost::shared_ptr<GeomAPI_Shape>();
}
std::list<FeaturePtr> PartSet_OperationSketchBase::subFeatures() const
#include <ModelAPI_Document.h>
static double myTestDelta;
-static FeaturePtr myTestFeature;
+static ResultPtr myTestObject;
#include <AIS_InteractiveContext.hxx>
#include <AIS_Shape.hxx>
void PartSet_TestOCC::testSelection(XGUI_Workshop* theWorkshop)
{
- if (!myTestFeature) {
+ if (!myTestObject) {
PartSet_TestOCC::createTestLine(theWorkshop);
PartSet_TestOCC::moveMouse(theWorkshop->viewer()->AISContext(),
theWorkshop->viewer()->activeView());
PartSet_TestOCC::changeTestLine(theWorkshop);
}
- boost::shared_ptr<GeomAPI_AISObject> anIO = theWorkshop->displayer()->getAISObject(myTestFeature);
+ boost::shared_ptr<GeomAPI_AISObject> anIO = theWorkshop->displayer()->getAISObject(myTestObject);
if (!anIO->empty()) {
theWorkshop->viewer()->AISContext()->MoveTo(0, 0, theWorkshop->viewer()->activeView());
theWorkshop->viewer()->AISContext()->Select(0, 0, 2500, 2500, theWorkshop->viewer()->activeView());
boost::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
boost::shared_ptr<GeomAPI_AISObject> anAIS = aSPFeature->getAISObject(aPrevAIS);
if (!anAIS->empty())
- aDisplayer->redisplay(aFeature, anAIS, false);
+ aDisplayer->redisplay(aFeature->firstResult(), anAIS, false);
std::list<int> aModes;
aModes.push_back(TopAbs_VERTEX);
aModes.push_back(TopAbs_EDGE);
- aDisplayer->activateInLocalContext(aFeature, aModes, true);
+ aDisplayer->activateInLocalContext(aFeature->firstResult(), aModes, true);
// change the line
/*double aDelta = -200;
//aModes.push_back(TopAbs_VERTEX);
//aModes.push_back(TopAbs_EDGE);
//aDisplayer->activateInLocalContext(aFeature, aModes, true);
- myTestFeature = aFeature;
+ myTestObject = aFeature->firstResult();
- QFeatureList aFeatureList;
- aFeatureList.append(myTestFeature);
+ QResultList aFeatureList;
+ aFeatureList.append(myTestObject);
aDisplayer->setSelected(aFeatureList, true);
}
}
void PartSet_TestOCC::changeTestLine(XGUI_Workshop* theWorkshop)
{
// change the line
- if (!myTestFeature)
+ if (!myTestObject)
return;
- FeaturePtr aFeature = myTestFeature;
+ ResultPtr aFeature = myTestObject;
myTestDelta = myTestDelta - 50;
double aDelta = myTestDelta;
- PartSet_Tools::setFeaturePoint(aFeature, -100/*aDelta*/, -100/*aDelta*/, SketchPlugin_Line::START_ID());
- PartSet_Tools::setFeaturePoint(aFeature, 200/*aDelta*2*/, 200/*aDelta*2*/, SketchPlugin_Line::END_ID());
- boost::shared_ptr<GeomAPI_Shape> aPreview = PartSet_OperationSketchBase::preview(aFeature);
+ // TODO
+ //PartSet_Tools::setFeaturePoint(aFeature, -100/*aDelta*/, -100/*aDelta*/, LINE_ATTR_START);
+ //PartSet_Tools::setFeaturePoint(aFeature, 200/*aDelta*2*/, 200/*aDelta*2*/, LINE_ATTR_END);
+ //boost::shared_ptr<GeomAPI_Shape> aPreview = PartSet_OperationSketchBase::preview(aFeature);
boost::shared_ptr<GeomAPI_AISObject> aPrevAIS;
boost::shared_ptr<SketchPlugin_Feature> aSPFeature =
//aDisplayer->activateInLocalContext(aFeature, aModes, true);
/*QFeatureList aFeatureList;
- aFeatureList.append(myTestFeature);
+ aFeatureList.append(myTestObject);
theWorkshop->displayer()->setSelected(aFeatureList, true);*/
theWorkshop->displayer()->updateViewer();
{
theContext->MoveTo(10, 10, theView);
theContext->Select();
-}
\ No newline at end of file
+}
ModuleBase_ViewerPrs aPrs;
for (; anIt != aLast; anIt++) {
aPrs = *anIt;
- if (!aPrs.feature())
+ if (!aPrs.result())
continue;
boost::shared_ptr<SketchPlugin_Feature> aSketchFeature =
- boost::dynamic_pointer_cast<SketchPlugin_Feature>(aPrs.feature());
+ boost::dynamic_pointer_cast<SketchPlugin_Feature>(aPrs.result());
if (!aSketchFeature)
continue;
double aDelta = aSketchFeature->distanceToPoint(
boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, anY)));
if (aMinDelta < 0 || aMinDelta > aDelta) {
aMinDelta = aDelta;
- aDeltaFeature = aPrs.feature();
+ // TODO aDeltaFeature = aPrs.result();
}
}
return aDeltaFeature;
boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(theAttribute));
if (anAttr) {
- aFeature = anAttr->feature();
+ aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->object());
if (!theKind.empty() && aFeature && aFeature->getKind() != theKind) {
aFeature = FeaturePtr();
}
boost::shared_ptr<ModelAPI_AttributeRefList> aRefList =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(aData->attribute(SketchPlugin_Sketch::FEATURES_ID()));
- std::list<FeaturePtr > aFeatures = aRefList->list();
- std::list<FeaturePtr >::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
+ std::list<ObjectPtr > aFeatures = aRefList->list();
+ std::list<ObjectPtr >::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
std::list<boost::shared_ptr<ModelAPI_Attribute> > anAttiributes;
boost::shared_ptr<GeomAPI_Pnt2d> aClickedPoint = boost::shared_ptr<GeomAPI_Pnt2d>
(new GeomAPI_Pnt2d(theClickedX, theClickedY));
for (; anIt != aLast; anIt++)
{
- FeaturePtr aFeature = *anIt;
+ FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(*anIt);
// find the given point in the feature attributes
anAttiributes = aFeature->data()->attributes(GeomDataAPI_Point2D::type());
std::list<boost::shared_ptr<ModelAPI_Attribute> >::const_iterator anIt = anAttiributes.begin(),
#include "PartSet_Validators.h"
+#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <BRep_Tool.hxx>
+#include <GeomAdaptor_Curve.hxx>
+#include <GeomAbs_CurveType.hxx>
+
#include <list>
-int shapesNb(const ModuleBase_ISelection* theSelection, TopAbs_ShapeEnum theType)
+int shapesNbPoints(const ModuleBase_ISelection* theSelection)
{
std::list<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
std::list<ModuleBase_ViewerPrs>::iterator it;
aPrs = *it;
const TopoDS_Shape& aShape = aPrs.shape();
if (!aShape.IsNull()) {
- if (aShape.ShapeType() == theType)
+ if (aShape.ShapeType() == TopAbs_VERTEX)
aCount++;
}
}
return aCount;
}
+int shapesNbLines(const ModuleBase_ISelection* theSelection)
+{
+ std::list<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
+ std::list<ModuleBase_ViewerPrs>::iterator it;
+ ModuleBase_ViewerPrs aPrs;
+ int aCount = 0;
+ for (it = aList.begin(); it != aList.end(); ++it) {
+ aPrs = *it;
+ const TopoDS_Shape& aShape = aPrs.shape();
+ if (!aShape.IsNull()) {
+ if (aShape.ShapeType() == TopAbs_EDGE) {
+ TopoDS_Edge aEdge = TopoDS::Edge(aShape);
+ Standard_Real aStart, aEnd;
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd);
+ GeomAdaptor_Curve aAdaptor(aCurve);
+ if (aAdaptor.GetType() == GeomAbs_Line)
+ aCount++;
+ }
+ }
+ }
+ return aCount;
+}
+
bool PartSet_DistanceValidator::isValid(const ModuleBase_ISelection* theSelection) const
{
- int aCount = shapesNb(theSelection, TopAbs_VERTEX);
+ int aCount = shapesNbPoints(theSelection);
return (aCount > 0) && (aCount < 3);
}
bool PartSet_LengthValidator::isValid(const ModuleBase_ISelection* theSelection) const
{
- int aCount = shapesNb(theSelection, TopAbs_EDGE);
- return (aCount == 1);
-}
\ No newline at end of file
+ int aCount = shapesNbLines(theSelection);
+ return (aCount > 0) && (aCount < 2);
+}
+
+bool PartSet_PerpendicularValidator::isValid(const ModuleBase_ISelection* theSelection) const
+{
+ int aCount = shapesNbLines(theSelection);
+ return (aCount > 0) && (aCount < 3);
+}
+
+bool PartSet_ParallelValidator::isValid(const ModuleBase_ISelection* theSelection) const
+{
+ int aCount = shapesNbLines(theSelection);
+ return (aCount > 0) && (aCount < 3);
+}
+
+bool PartSet_RadiusValidator::isValid(const ModuleBase_ISelection* theSelection) const
+{
+ std::list<ModuleBase_ViewerPrs> aList = theSelection->getSelected();
+ std::list<ModuleBase_ViewerPrs>::iterator it;
+ ModuleBase_ViewerPrs aPrs;
+ int aCount = 0;
+ for (it = aList.begin(); it != aList.end(); ++it) {
+ aPrs = *it;
+ const TopoDS_Shape& aShape = aPrs.shape();
+ if (!aShape.IsNull()) {
+ if (aShape.ShapeType() == TopAbs_EDGE) {
+ TopoDS_Edge aEdge = TopoDS::Edge(aShape);
+ Standard_Real aStart, aEnd;
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aEdge, aStart, aEnd);
+ GeomAdaptor_Curve aAdaptor(aCurve);
+ if (aAdaptor.GetType() == GeomAbs_Circle)
+ aCount++;
+ }
+ }
+ }
+ return (aCount > 0) && (aCount < 2);
+}
#include <ModuleBase_SelectionValidator.h>
#include <ModuleBase_ISelection.h>
+//! A class to validate a selection for Distance constraint operation
class PartSet_DistanceValidator: public ModuleBase_SelectionValidator
{
public:
PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
};
+//! A class to validate a selection for Length constraint operation
class PartSet_LengthValidator: public ModuleBase_SelectionValidator
{
public:
PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
};
+//! A class to validate a selection for Perpendicular constraint operation
+class PartSet_PerpendicularValidator: public ModuleBase_SelectionValidator
+{
+public:
+ PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+};
+
+//! A class to validate a selection for Perpendicular constraint operation
+class PartSet_ParallelValidator: public ModuleBase_SelectionValidator
+{
+public:
+ PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+};
+
+//! A class to validate a selection for Perpendicular constraint operation
+class PartSet_RadiusValidator: public ModuleBase_SelectionValidator
+{
+public:
+ PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+};
+
#endif
/// Saves the internal parameters to the given feature
/// \param theFeature a model feature to be changed
- virtual bool storeValue(FeaturePtr theFeature) const { return true;}
+ virtual bool storeValue(ObjectPtr theFeature) const { return true;}
- virtual bool restoreValue(FeaturePtr theFeature) { return true;}
+ virtual bool restoreValue(ObjectPtr theFeature) { return true;}
/// Returns list of widget controls
/// \return a control list
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(PartSetPlugin_Part::DOC_REF())->value() == aPManager->currentDocument())
break;
aSource.reset();
}
if (aSource) {
boost::shared_ptr<ModelAPI_Document> aCopy =
- aPManager->copy(aSource->data()->docRef(PartSetPlugin_Part::DOC_REF())->value(), data()->getName());
- aRef->setFeature(aSource);
+ aPManager->copy(aSource->data()->docRef(PartSetPlugin_Part::DOC_REF())->value(), data()->name());
+ aRef->setObject(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(data());
+ setResult(aResult);
}
}
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() == PartSetPlugin_Part::ID()) {
boost::shared_ptr<PartSetPlugin_Part> aPart =
boost::static_pointer_cast<PartSetPlugin_Part>(aFeature);
#include "SketchPlugin_Arc.h"
#include "SketchPlugin_Sketch.h"
#include <ModelAPI_Data.h>
+#include <ModelAPI_ResultConstruction.h>
#include <GeomAPI_Circ2d.h>
#include <GeomAPI_Pnt2d.h>
-
#include <GeomDataAPI_Point2D.h>
#include <GeomDataAPI_Dir.h>
-
#include <GeomAlgoAPI_PointBuilder.h>
#include <GeomAlgoAPI_EdgeBuilder.h>
#include <GeomAlgoAPI_CompoundBuilder.h>
}
void SketchPlugin_Arc::execute()
-{
-}
-
-const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Arc::preview()
{
SketchPlugin_Sketch* aSketch = sketch();
if (aSketch) {
aShapes.push_back(aCircleShape);
}
boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
- setPreview(aCompound);
+ // store the result
+ boost::shared_ptr<ModelAPI_ResultConstruction> aConstr =
+ document()->createConstruction(data());
+ aConstr->setShape(aCompound);
+ results().push_back(aConstr);
}
}
- return getPreview();
-}
-
-boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_Arc::getAISObject(
- boost::shared_ptr<GeomAPI_AISObject> thePrevious)
-{
- return prepareAISShape(thePrevious);
}
void SketchPlugin_Arc::move(double theDeltaX, double theDeltaY)
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
{static std::string MY_KIND = SketchPlugin_Arc::ID(); return MY_KIND;}
- /// Returns to which group in the document must be added feature
- SKETCHPLUGIN_EXPORT virtual const std::string& getGroup()
- {static std::string MY_GROUP = SketchPlugin_Sketch::ID(); return MY_GROUP;}
-
- /// Creates a new part document if needed
+ /// Creates an arc-shape
SKETCHPLUGIN_EXPORT virtual void execute();
/// Request for initialization of data model of the feature: adding all attributes
SKETCHPLUGIN_EXPORT virtual void initAttributes();
- /// Returns the sketch preview
- SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
-
/// Returns the AIS preview
- SKETCHPLUGIN_EXPORT virtual boost::shared_ptr<GeomAPI_AISObject> getAISObject(
- boost::shared_ptr<GeomAPI_AISObject> thePrevious);
-
- /// Adds sub-feature of the higher level feature (sub-element of the sketch)
- /// \param theFeature sub-feature
- SKETCHPLUGIN_EXPORT virtual const void addSub(
- const FeaturePtr& theFeature) {};
+ virtual boost::shared_ptr<GeomAPI_AISObject> getAISObject(
+ boost::shared_ptr<GeomAPI_AISObject> thePrevious)
+ {return simpleAISObject(firstResult(), thePrevious);}
/// Moves the feature
/// \param theDeltaX the delta for X coordinate is moved
#include "SketchPlugin_Circle.h"
#include "SketchPlugin_Sketch.h"
#include <ModelAPI_Data.h>
+#include <ModelAPI_ResultConstruction.h>
#include <GeomAPI_Pnt2d.h>
-
#include <GeomDataAPI_Point2D.h>
#include <GeomDataAPI_Dir.h>
-
#include <GeomAlgoAPI_PointBuilder.h>
#include <GeomAlgoAPI_EdgeBuilder.h>
#include <GeomAlgoAPI_CompoundBuilder.h>
-
#include <ModelAPI_AttributeDouble.h>
SketchPlugin_Circle::SketchPlugin_Circle()
}
void SketchPlugin_Circle::execute()
-{
-}
-
-const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Circle::preview()
{
SketchPlugin_Sketch* aSketch = sketch();
if (aSketch) {
}
}
boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
- setPreview(aCompound);
+ // store the result
+ boost::shared_ptr<ModelAPI_ResultConstruction> aConstr =
+ document()->createConstruction(data());
+ aConstr->setShape(aCompound);
+ setResult(aConstr);
}
- return getPreview();
-}
-
-boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_Circle::getAISObject(
- boost::shared_ptr<GeomAPI_AISObject> thePrevious)
-{
- return prepareAISShape(thePrevious);
}
void SketchPlugin_Circle::move(double theDeltaX, double theDeltaY)
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
{static std::string MY_KIND = SketchPlugin_Circle::ID(); return MY_KIND;}
- /// Returns to which group in the document must be added feature
- SKETCHPLUGIN_EXPORT virtual const std::string& getGroup()
- {static std::string MY_GROUP = SketchPlugin_Sketch::ID(); return MY_GROUP;}
-
/// Creates a new part document if needed
SKETCHPLUGIN_EXPORT virtual void execute();
/// Request for initialization of data model of the feature: adding all attributes
SKETCHPLUGIN_EXPORT virtual void initAttributes();
- /// Returns the sketch preview
- SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
-
/// Returns the AIS preview
- SKETCHPLUGIN_EXPORT virtual boost::shared_ptr<GeomAPI_AISObject> getAISObject(
- boost::shared_ptr<GeomAPI_AISObject> thePrevious);
+ virtual boost::shared_ptr<GeomAPI_AISObject> getAISObject(
+ boost::shared_ptr<GeomAPI_AISObject> thePrevious)
+ {return simpleAISObject(firstResult(), thePrevious);}
/// Adds sub-feature of the higher level feature (sub-element of the sketch)
/// \param theFeature sub-feature
{
return thePrevious;
}
-
-const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Constraint::preview()
-{
- return getPreview();
-}
-
SKETCHPLUGIN_EXPORT virtual const void addSub(
const FeaturePtr& theFeature) {}
- /// \brief Returns the sketch preview
- SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
-
/// Returns the AIS preview
SKETCHPLUGIN_EXPORT virtual boost::shared_ptr<GeomAPI_AISObject> getAISObject(
boost::shared_ptr<GeomAPI_AISObject> thePrevious);
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
{static std::string MY_KIND = SketchPlugin_ConstraintCoincidence::ID(); return MY_KIND;}
- /// \brief Returns to which group in the document must be added feature
- SKETCHPLUGIN_EXPORT virtual const std::string& getGroup()
- {static std::string MY_GROUP = SketchPlugin_Sketch::ID(); return MY_GROUP;}
-
/// \brief Creates a new part document if needed
SKETCHPLUGIN_EXPORT virtual void execute();
boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theData->attribute(theAttribute));
if (anAttr)
- aFeature = anAttr->feature();
+ aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->object());
if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID())
aPointAttr = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
{static std::string MY_KIND = SketchPlugin_ConstraintDistance::ID(); return MY_KIND;}
- /// \brief Returns to which group in the document must be added feature
- SKETCHPLUGIN_EXPORT virtual const std::string& getGroup()
- {static std::string MY_GROUP = SketchPlugin_Sketch::ID(); return MY_GROUP;}
-
/// \brief Creates a new part document if needed
SKETCHPLUGIN_EXPORT virtual void execute();
boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(data()->attribute(SketchPlugin_Constraint::ENTITY_A()));
- FeaturePtr aFeature = aRef->feature();
+ ObjectPtr aFeature = aRef->object();
if (aFeature) {
// set length value
boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(data()->attribute(SketchPlugin_Constraint::ENTITY_A()));
if (!anAttr)
return thePrevious;
- FeaturePtr aFeature = anAttr->feature();
+ FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->object());
if (!aFeature || aFeature->getKind() != SketchPlugin_Line::ID())
return thePrevious;
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
{static std::string MY_KIND = SketchPlugin_ConstraintLength::ID(); return MY_KIND;}
- /// \brief Returns to which group in the document must be added feature
- SKETCHPLUGIN_EXPORT virtual const std::string& getGroup()
- {static std::string MY_GROUP = SketchPlugin_Sketch::ID(); return MY_GROUP;}
-
/// \brief Creates a new part document if needed
SKETCHPLUGIN_EXPORT virtual void execute();
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_Data.h>
+#include <ModelAPI_ResultConstruction.h>
#include <SketchPlugin_Line.h>
#include <SketchPlugin_Sketch.h>
{
}
-const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_ConstraintParallel::preview()
-{
- /// \todo Preview for parallel constraint
- return getPreview();
-}
-
-
boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_ConstraintParallel::getAISObject(
boost::shared_ptr<GeomAPI_AISObject> thePrevious)
{
boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr2 =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
- if (!anAttr1 || !anAttr1->isFeature() ||
- !anAttr2 || !anAttr2->isFeature())
+ if (!anAttr1 || !anAttr1->isObject() ||
+ !anAttr2 || !anAttr2->isObject())
return thePrevious;
boost::shared_ptr<SketchPlugin_Line> aLine1Feature =
- boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr1->feature());
+ boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr1->object());
boost::shared_ptr<SketchPlugin_Line> aLine2Feature =
- boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr2->feature());
+ boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr2->object());
if (!aLine1Feature || !aLine2Feature)
return thePrevious;
boost::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
- boost::shared_ptr<GeomAPI_Shape> aLine1 = aLine1Feature->preview();
- boost::shared_ptr<GeomAPI_Shape> aLine2 = aLine2Feature->preview();
+ boost::shared_ptr<GeomAPI_Shape> aLine1, aLine2;
+ boost::shared_ptr<ModelAPI_ResultConstruction> aConst1 =
+ boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aLine1Feature->firstResult());
+ if (aConst1) aLine1 = aConst1->shape();
+ boost::shared_ptr<ModelAPI_ResultConstruction> aConst2 =
+ boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aLine1Feature->firstResult());
+ if (aConst2) aLine2 = aConst2->shape();
boost::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr =
boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
{static std::string MY_KIND = SketchPlugin_ConstraintParallel::ID(); return MY_KIND;}
- /// \brief Returns to which group in the document must be added feature
- SKETCHPLUGIN_EXPORT virtual const std::string& getGroup()
- {static std::string MY_GROUP = SketchPlugin_Sketch::ID(); return MY_GROUP;}
-
/// \brief Creates a new part document if needed
SKETCHPLUGIN_EXPORT virtual void execute();
/// \brief Request for initialization of data model of the feature: adding all attributes
SKETCHPLUGIN_EXPORT virtual void initAttributes();
- /// \brief Returns the sketch preview
- SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
-
/// Returns the AIS preview
SKETCHPLUGIN_EXPORT virtual boost::shared_ptr<GeomAPI_AISObject> getAISObject(
boost::shared_ptr<GeomAPI_AISObject> thePrevious);
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_Data.h>
+#include <ModelAPI_ResultConstruction.h>
#include <SketchPlugin_Line.h>
#include <SketchPlugin_Sketch.h>
{
}
-const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_ConstraintPerpendicular::preview()
-{
- /// \todo Preview for perpendicular constraint
- return getPreview();
-}
-
boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_ConstraintPerpendicular::getAISObject(
boost::shared_ptr<GeomAPI_AISObject> thePrevious)
{
boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr2 =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
- if (!anAttr1 || !anAttr1->isFeature() ||
- !anAttr2 || !anAttr2->isFeature())
+ if (!anAttr1 || !anAttr1->isObject() ||
+ !anAttr2 || !anAttr2->isObject())
return thePrevious;
boost::shared_ptr<SketchPlugin_Line> aLine1Feature =
- boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr1->feature());
+ boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr1->object());
boost::shared_ptr<SketchPlugin_Line> aLine2Feature =
- boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr2->feature());
+ boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr2->object());
if (!aLine1Feature || !aLine2Feature)
return thePrevious;
boost::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
- boost::shared_ptr<GeomAPI_Shape> aLine1 = aLine1Feature->preview();
- boost::shared_ptr<GeomAPI_Shape> aLine2 = aLine2Feature->preview();
+ boost::shared_ptr<GeomAPI_Shape> aLine1, aLine2;
+ boost::shared_ptr<ModelAPI_ResultConstruction> aConst1 =
+ boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aLine1Feature->firstResult());
+ if (aConst1) aLine1 = aConst1->shape();
+ boost::shared_ptr<ModelAPI_ResultConstruction> aConst2 =
+ boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aLine1Feature->firstResult());
+ if (aConst2) aLine2 = aConst2->shape();
boost::shared_ptr<GeomAPI_AISObject> anAIS = thePrevious;
if (!anAIS)
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
{static std::string MY_KIND = SketchPlugin_ConstraintPerpendicular::ID(); return MY_KIND;}
- /// \brief Returns to which group in the document must be added feature
- SKETCHPLUGIN_EXPORT virtual const std::string& getGroup()
- {static std::string MY_GROUP = SketchPlugin_Sketch::ID(); return MY_GROUP;}
-
/// \brief Creates a new part document if needed
SKETCHPLUGIN_EXPORT virtual void execute();
/// \brief Request for initialization of data model of the feature: adding all attributes
SKETCHPLUGIN_EXPORT virtual void initAttributes();
- /// \brief Returns the sketch preview
- SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
-
/// Returns the AIS preview
SKETCHPLUGIN_EXPORT virtual boost::shared_ptr<GeomAPI_AISObject> getAISObject(
boost::shared_ptr<GeomAPI_AISObject> thePrevious);
boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(data()->attribute(SketchPlugin_Constraint::ENTITY_A()));
- FeaturePtr aFeature = aRef->feature();
+ FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aRef->object());
if (aFeature) {
double aRadius = 0;
boost::shared_ptr<ModelAPI_Data> aData = aFeature->data();
boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
if (!anAttr)
return thePrevious;
- FeaturePtr aFeature = anAttr->feature();
+ FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->object());
std::string aKind = aFeature ? aFeature->getKind() : "";
if (aKind != SketchPlugin_Circle::ID() && aKind != SketchPlugin_Arc::ID())
return thePrevious;
boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(data()->attribute(SketchPlugin_Constraint::ENTITY_A()));
- FeaturePtr aFeature = aRef->feature();
+ FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aRef->object());
if (!aFeature)
return;
std::string aCenterAttrName;
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
{static std::string MY_KIND = SketchPlugin_ConstraintRadius::ID(); return MY_KIND;}
- /// \brief Returns to which group in the document must be added feature
- SKETCHPLUGIN_EXPORT virtual const std::string& getGroup()
- {static std::string MY_GROUP = SketchPlugin_Sketch::ID(); return MY_GROUP;}
-
/// \brief Creates a new part document if needed
SKETCHPLUGIN_EXPORT virtual void execute();
#include <ModelAPI_Data.h>
#include <ModelAPI_Object.h>
#include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_ResultConstruction.h>
SketchPlugin_Feature::SketchPlugin_Feature()
{
mySketch = 0;
}
-void SketchPlugin_Feature::setPreview(const boost::shared_ptr<GeomAPI_Shape>& theShape)
-{
- myPreview = theShape;
-}
-
-const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Feature::getPreview() const
-{
- return myPreview;
-}
-
SketchPlugin_Sketch* SketchPlugin_Feature::sketch()
{
if (!mySketch) {
int aSketches = document()->size("Construction");
for(int a = 0; a < aSketches && !mySketch; a++) {
boost::shared_ptr<SketchPlugin_Sketch> aSketch = boost::
- dynamic_pointer_cast<SketchPlugin_Sketch>(document()->feature("Construction", a, true));
+ dynamic_pointer_cast<SketchPlugin_Sketch>(document()->object("Construction", a));
if (aSketch) {
- std::list<FeaturePtr > aList =
+ std::list<ObjectPtr> aList =
aSketch->data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->list();
- std::list<FeaturePtr >::iterator aSub = aList.begin();
+ std::list<ObjectPtr>::iterator aSub = aList.begin();
for(; aSub != aList.end(); aSub++) {
if ((*aSub)->data()->isEqual(data())) {
mySketch = aSketch.get();
return mySketch;
}
-boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_Feature::prepareAISShape(
- boost::shared_ptr<GeomAPI_AISObject> thePrevious)
+boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_Feature::simpleAISObject(
+ boost::shared_ptr<ModelAPI_Result> theRes, boost::shared_ptr<GeomAPI_AISObject> thePrevious)
{
- boost::shared_ptr<GeomAPI_Shape> aPreview = preview();
+ boost::shared_ptr<ModelAPI_ResultConstruction> aConstr =
+ boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theRes);
+
+ boost::shared_ptr<GeomAPI_Shape> aPreview;
+ if (aConstr) aPreview = aConstr->shape();
+
boost::shared_ptr<GeomAPI_AISObject> aResult = thePrevious;
if (!aResult)
aResult = boost::shared_ptr<GeomAPI_AISObject>(new GeomAPI_AISObject());
#include <ModelAPI_Feature.h>
#include <GeomAPI_Shape.h>
#include <GeomAPI_AISObject.h>
+#include <ModelAPI_Document.h>
class SketchPlugin_Sketch;
class GeomAPI_Pnt2d;
class SketchPlugin_Feature: public ModelAPI_Feature
{
public:
- /// Returns the sketch preview
- /// \param theSketch the owner of this feature
- /// \return the built preview
- SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview() = 0;
-
/// Returns the AIS preview
SKETCHPLUGIN_EXPORT virtual boost::shared_ptr<GeomAPI_AISObject> getAISObject(
boost::shared_ptr<GeomAPI_AISObject> thePrevious) = 0;
+ /// Simple creation of interactive object by the result of the object
+ static boost::shared_ptr<GeomAPI_AISObject> simpleAISObject(
+ boost::shared_ptr<ModelAPI_Result> theRes, boost::shared_ptr<GeomAPI_AISObject> thePrevious);
+
/// Adds sub-feature of the higher level feature (sub-element of the sketch)
/// \param theFeature sub-feature
SKETCHPLUGIN_EXPORT virtual const void addSub(
- const FeaturePtr& theFeature) = 0;
+ const FeaturePtr& theFeature) {};
/// Returns true if this feature must be displayed in the history (top level of Part tree)
SKETCHPLUGIN_EXPORT virtual bool isInHistory() {return false;}
virtual double distanceToPoint(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) = 0;
protected:
- /// Set the shape to the internal preview field
- /// \param theShape a preview shape
- void setPreview(const boost::shared_ptr<GeomAPI_Shape>& theShape); ///< the preview shape
- /// Return the shape from the internal preview field
- /// \return theShape a preview shape
- const boost::shared_ptr<GeomAPI_Shape>& getPreview() const;
- /// Common method for other features to produce AIS shape
- boost::shared_ptr<GeomAPI_AISObject> prepareAISShape(
- boost::shared_ptr<GeomAPI_AISObject> thePrevious);
/// Sets the higher-level feature for the sub-feature (sketch for line)
void setSketch(SketchPlugin_Sketch* theSketch) {mySketch = theSketch;}
/// Returns the sketch of this feature
#include "SketchPlugin_Line.h"
#include "SketchPlugin_Sketch.h"
#include <ModelAPI_Data.h>
+#include <ModelAPI_ResultConstruction.h>
#include <GeomAPI_Pnt.h>
#include <GeomAPI_Lin2d.h>
}
void SketchPlugin_Line::execute()
-{
-}
-
-const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Line::preview()
{
SketchPlugin_Sketch* aSketch = sketch();
if (aSketch) {
boost::shared_ptr<GeomAPI_Pnt> anEnd(aSketch->to3D(anEndAttr->x(), anEndAttr->y()));
// make linear edge
boost::shared_ptr<GeomAPI_Shape> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd);
- setPreview(anEdge);
+ // store the result
+ boost::shared_ptr<ModelAPI_ResultConstruction> aConstr =
+ document()->createConstruction(data());
+ aConstr->setShape(anEdge);
+ setResult(aConstr);
}
}
- return getPreview();
}
-boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_Line::getAISObject(
- boost::shared_ptr<GeomAPI_AISObject> thePrevious)
-{
- return prepareAISShape(thePrevious);
-}
-
-
void SketchPlugin_Line::move(double theDeltaX, double theDeltaY)
{
boost::shared_ptr<ModelAPI_Data> aData = data();
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
{static std::string MY_KIND = SketchPlugin_Line::ID(); return MY_KIND;}
- /// Returns to which group in the document must be added feature
- SKETCHPLUGIN_EXPORT virtual const std::string& getGroup()
- {static std::string MY_GROUP = SketchPlugin_Sketch::ID(); return MY_GROUP;}
-
/// Creates a new part document if needed
SKETCHPLUGIN_EXPORT virtual void execute();
/// Request for initialization of data model of the feature: adding all attributes
SKETCHPLUGIN_EXPORT virtual void initAttributes();
- /// Returns the sketch preview
- SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
-
/// Returns the AIS preview
SKETCHPLUGIN_EXPORT virtual boost::shared_ptr<GeomAPI_AISObject> getAISObject(
- boost::shared_ptr<GeomAPI_AISObject> thePrevious);
-
- /// Adds sub-feature of the higher level feature (sub-element of the sketch)
- /// \param theFeature sub-feature
- SKETCHPLUGIN_EXPORT virtual const void addSub(
- const FeaturePtr& theFeature) {};
+ boost::shared_ptr<GeomAPI_AISObject> thePrevious)
+ {return simpleAISObject(firstResult(), thePrevious);}
/// Moves the feature
/// \param theDeltaX the delta for X coordinate is moved
#include "SketchPlugin_Sketch.h"
#include <ModelAPI_Data.h>
+#include <ModelAPI_ResultConstruction.h>
#include <GeomAPI_Pnt2d.h>
}
void SketchPlugin_Point::execute()
-{
-}
-
-const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Point::preview()
{
SketchPlugin_Sketch* aSketch = sketch();
if (aSketch) {
boost::shared_ptr<GeomAPI_Pnt> aPoint3D(aSketch->to3D(aPoint->x(), aPoint->y()));
// make a visible point
boost::shared_ptr<GeomAPI_Shape> aPointShape = GeomAlgoAPI_PointBuilder::point(aPoint3D);
- setPreview(aPointShape);
+ boost::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
+ aConstr->setShape(aPointShape);
+ setResult(aConstr);
}
- return getPreview();
-}
-
-boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_Point::getAISObject(
- boost::shared_ptr<GeomAPI_AISObject> thePrevious)
-{
- return prepareAISShape(thePrevious);
}
void SketchPlugin_Point::move(double theDeltaX, double theDeltaY)
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
{static std::string MY_KIND = SketchPlugin_Point::ID(); return MY_KIND;}
- /// Returns to which group in the document must be added feature
- SKETCHPLUGIN_EXPORT virtual const std::string& getGroup()
- {static std::string MY_GROUP = SketchPlugin_Sketch::ID(); return MY_GROUP;}
-
/// Creates a new part document if needed
SKETCHPLUGIN_EXPORT virtual void execute();
/// Request for initialization of data model of the feature: adding all attributes
SKETCHPLUGIN_EXPORT virtual void initAttributes();
- /// Returns the sketch preview
- SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
-
/// Returns the AIS preview
- SKETCHPLUGIN_EXPORT virtual boost::shared_ptr<GeomAPI_AISObject> getAISObject(
- boost::shared_ptr<GeomAPI_AISObject> thePrevious);
-
- /// Adds sub-feature of the higher level feature (sub-element of the sketch)
- /// \param theFeature sub-feature
- SKETCHPLUGIN_EXPORT virtual const void addSub(
- const FeaturePtr& theFeature) {};
+ virtual boost::shared_ptr<GeomAPI_AISObject> getAISObject(
+ boost::shared_ptr<GeomAPI_AISObject> thePrevious)
+ {return simpleAISObject(firstResult(), thePrevious);}
/// Moves the feature
/// \param theDeltaX the delta for X coordinate is moved
#include <GeomAlgoAPI_FaceBuilder.h>
#include <GeomAlgoAPI_CompoundBuilder.h>
#include <GeomAlgoAPI_SketchBuilder.h>
+#include <ModelAPI_ResultConstruction.h>
const int SKETCH_PLANE_COLOR = Colors::COLOR_BROWN; /// the plane edge color
void SketchPlugin_Sketch::execute()
{
+ if (!isPlaneSet()) {
+ std::list<boost::shared_ptr<GeomAPI_Shape> > aFaces;
+
+ addPlane(1, 0, 0, aFaces); // YZ plane
+ addPlane(0, 1, 0, aFaces); // XZ plane
+ addPlane(0, 0, 1, aFaces); // XY plane
+ boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aFaces);
+ boost::shared_ptr<ModelAPI_ResultConstruction> aConstr =
+ document()->createConstruction(data());
+ aConstr->setShape(aCompound);
+ setResult(aConstr);
+ return;
+ }
if (!data()->isValid())
return ;
boost::shared_ptr<ModelAPI_AttributeRefList> aRefList =
boost::shared_ptr<GeomDataAPI_Dir> aNorm =
boost::dynamic_pointer_cast<GeomDataAPI_Dir>(data()->attribute(SketchPlugin_Sketch::NORM_ID()));
- std::list<boost::shared_ptr<ModelAPI_Feature> > aFeatures = aRefList->list();
+ std::list<ObjectPtr> aFeatures = aRefList->list();
if (aFeatures.empty())
return ;
- std::list<boost::shared_ptr<ModelAPI_Feature> >::const_iterator anIt = aFeatures.begin(),
- aLast = aFeatures.end();
-
+ std::list<ObjectPtr>::const_iterator anIt = aFeatures.begin(), aLast = aFeatures.end();
boost::shared_ptr<SketchPlugin_Feature> aFeature;
std::list< boost::shared_ptr<GeomAPI_Shape> > aFeaturesPreview;
for (; anIt != aLast; anIt++) {
aFeature = boost::dynamic_pointer_cast<SketchPlugin_Feature>(*anIt);
- boost::shared_ptr<GeomAPI_Shape> aPreview = aFeature->preview();
- if (aPreview)
- aFeaturesPreview.push_back(aPreview);
+ boost::shared_ptr<ModelAPI_ResultConstruction> aRes =
+ boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aFeature->firstResult());
+ if (aRes) {
+ boost::shared_ptr<GeomAPI_Shape> aShape = aRes->shape();
+ if (aShape)
+ aFeaturesPreview.push_back(aShape);
+ }
}
if (aFeaturesPreview.empty())
aLoops.insert(aLoops.end(), aWires.begin(), aWires.end());
boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aLoops);
- data()->store(aCompound);
+ boost::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
+ aConstr->setShape(aCompound);
+ setResult(aConstr);
}
boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_Sketch::getAISObject(
boost::shared_ptr<GeomAPI_AISObject> thePrevious)
{
- boost::shared_ptr<GeomAPI_AISObject> anAIS = prepareAISShape(thePrevious);
- anAIS->setColor(SKETCH_PLANE_COLOR);
- anAIS->setWidth(SKETCH_WIDTH);
+ boost::shared_ptr<GeomAPI_AISObject> aResult = simpleAISObject(firstResult(), thePrevious);
+ aResult->setColor(SKETCH_PLANE_COLOR);
+ aResult->setWidth(SKETCH_WIDTH);
//anAIS->Redisplay();
- return anAIS;
-}
-
-const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Sketch::preview()
-{
- if (isPlaneSet()) {
- setPreview(boost::shared_ptr<GeomAPI_Shape>());
- }
- else {
- std::list<boost::shared_ptr<GeomAPI_Shape> > aFaces;
-
- addPlane(1, 0, 0, aFaces); // YZ plane
- addPlane(0, 1, 0, aFaces); // XZ plane
- addPlane(0, 0, 1, aFaces); // XY plane
- boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aFaces);
- setPreview(aCompound);
- }
- return getPreview();
+ return aResult;
}
const void SketchPlugin_Sketch::addSub(const FeaturePtr& theFeature)
SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
{static std::string MY_KIND = SketchPlugin_Sketch::ID(); return MY_KIND;}
- /// Returns to which group in the document must be added feature
- SKETCHPLUGIN_EXPORT virtual const std::string& getGroup()
- {static std::string MY_GROUP = "Construction"; return MY_GROUP;}
-
/// Creates a new part document if needed
SKETCHPLUGIN_EXPORT virtual void execute();
/// Request for initialization of data model of the feature: adding all attributes
SKETCHPLUGIN_EXPORT virtual void initAttributes();
- /// Returns the sketch preview
- SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
-
/// Returns the AIS preview
SKETCHPLUGIN_EXPORT virtual boost::shared_ptr<GeomAPI_AISObject> getAISObject(
boost::shared_ptr<GeomAPI_AISObject> thePrevious);
<feature_or_attribute_selector id="ConstraintEntityB" label="Last point" tooltip="Select an point in the viewer" keysequence="SketchPoint Point2D"/>
<point_selector id="ConstraintFlyoutValuePnt" internal="1"/>
<doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue"/>
+ <validator id="PartSet_DistanceValidator"/>
</feature>
<feature id="SketchConstraintLength" title="Length" tooltip="Create constraint for the given length of a line segment">
<label title="Select a line on which to calculate lenght" tooltip="Select a line on which to calculate lenght"/>
<feature_selector id="ConstraintEntityA" label="Line" tooltip="Select an line in the viewer" keysequence="SketchLine"/>
<point_selector id="ConstraintFlyoutValuePnt" internal="1"/>
<doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue"/>
+ <validator id="PartSet_LengthValidator"/>
</feature>
<feature id="SketchConstraintRadius" title="Radius" tooltip="Create constraint for the given radius of a circle or an arc">
<label title="Select a circle or an arc on which to calculate radius" tooltip="Select a circle or an arc on which to calculate radius"/>
<feature_selector id="ConstraintEntityA" label="Circle or Arc" tooltip="Select a circle or an arc in the viewer" keysequence="SketchCircle SketchArc"/>
<point_selector id="ConstraintFlyoutValuePnt" internal="1"/>
<doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue"/>
+ <validator id="PartSet_RadiusValidator"/>
</feature>
<feature id="SketchConstraintParallel" title="Parallel" tooltip="Create constraint defining two parallel lines">
<feature_selector id="ConstraintEntityA" label="First line" tooltip="Select an line in the viewer" keysequence="SketchLine"/>
<feature_selector id="ConstraintEntityB" label="Last line" tooltip="Select an line in the viewer" keysequence="SketchLine"/>
<point_selector id="ConstraintFlyoutValuePnt" internal="1"/>
+ <validator id="PartSet_ParallelValidator"/>
</feature>
<feature id="SketchConstraintPerpendicular" title="Perpendicular" tooltip="Create constraint defining two perpendicular lines">
<feature_selector id="ConstraintEntityA" label="First line" tooltip="Select an line in the viewer" keysequence="SketchLine"/>
<feature_selector id="ConstraintEntityB" label="Last line" tooltip="Select an line in the viewer" keysequence="SketchLine"/>
<point_selector id="ConstraintFlyoutValuePnt" internal="1"/>
+ <validator id="PartSet_PerpendicularValidator"/>
</feature>
</group>
</workbench>
theConstraint->data()->attribute(SketchPlugin_Constraint::ATTRIBUTE(indAttr))
);
if (!anAttr) continue;
- if (anAttr->isFeature() && anAttr->feature())
+ if (anAttr->isObject() && anAttr->object())
{ // verify posiible entities
- const std::string& aKind = anAttr->feature()->getKind();
+ const std::string& aKind = boost::dynamic_pointer_cast<ModelAPI_Feature>
+ (anAttr->object())->getKind();
if (aKind.compare(SketchPlugin_Point::ID()) == 0)
{
myAttributesList[aNbPoints++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr);
theConstraint->data()->attribute(SketchPlugin_Constraint::ATTRIBUTE(indAttr))
);
if (!anAttr) continue;
- if (anAttr->isFeature() && anAttr->feature() &&
- anAttr->feature()->getKind().compare(SketchPlugin_Line::ID()) == 0)
+ if (anAttr->isObject() && anAttr->object() &&
+ boost::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->object())->getKind().
+ compare(SketchPlugin_Line::ID()) == 0)
{
myAttributesList[aNbLines++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr);
break;
boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
theConstraint->data()->attribute(SketchPlugin_Constraint::ATTRIBUTE(indAttr))
);
- if (!anAttr || !anAttr->isFeature() || !anAttr->feature()) continue;
- const std::string& aKind = anAttr->feature()->getKind();
+ if (!anAttr || !anAttr->isObject() || !anAttr->object()) continue;
+ const std::string& aKind = boost::dynamic_pointer_cast<ModelAPI_Feature>
+ (anAttr->object())->getKind();
if (aKind.compare(SketchPlugin_Line::ID()) == 0)
{
myAttributesList[aNbEntities++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr);
boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
theConstraint->data()->attribute(SketchPlugin_Constraint::ATTRIBUTE(indAttr))
);
- if (!anAttr || !anAttr->isFeature() || !anAttr->feature()) continue;
- const std::string& aKind = anAttr->feature()->getKind();
+ if (!anAttr || !anAttr->isObject() || !anAttr->object()) continue;
+ const std::string& aKind = boost::dynamic_pointer_cast<ModelAPI_Feature>
+ (anAttr->object())->getKind();
if (aKind.compare(SketchPlugin_Circle::ID()) == 0 || aKind.compare(SketchPlugin_Arc::ID()) == 0)
{
myAttributesList[aNbEntities++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr);
theConstraint->data()->attribute(SketchPlugin_Constraint::ATTRIBUTE(i))
);
if (!aCAttrRef) continue;
- if (!aCAttrRef->isFeature() &&
+ if (!aCAttrRef->isObject() &&
myEntityAttrMap.find(aCAttrRef->attr()) != myEntityAttrMap.end())
return true;
- if (aCAttrRef->isFeature() &&
- myEntityFeatMap.find(aCAttrRef->feature()) != myEntityFeatMap.end())
+ if (aCAttrRef->isObject() &&
+ myEntityFeatMap.find(boost::dynamic_pointer_cast<ModelAPI_Feature>(aCAttrRef->object()))
+ != myEntityFeatMap.end())
return true;
}
// For the length constraint the start and end points of the line should be added to the entities list instead of line
if (aConstrType == SLVS_C_PT_PT_DISTANCE && theConstraint->getKind().compare(SketchPlugin_ConstraintLength::ID()) == 0)
{
- boost::shared_ptr<ModelAPI_Data> aData = aConstrAttr->feature()->data();
+ boost::shared_ptr<ModelAPI_Data> aData = aConstrAttr->object()->data();
aConstrEnt[indAttr] = changeEntity(aData->attribute(SketchPlugin_Line::START_ID()));
aConstrEnt[indAttr+1] = changeEntity(aData->attribute(SketchPlugin_Line::END_ID()));
- myEntityFeatMap[aConstrAttr->feature()] = 0; // measured object is added into the map of objects to avoid problems with interaction betwee constraint and group
+ // measured object is added into the map of objects to avoid problems with interaction betwee constraint and group
+ myEntityFeatMap[boost::dynamic_pointer_cast<ModelAPI_Feature>(aConstrAttr->object())] = 0;
break; // there should be no other entities
}
- else if (aConstrAttr->isFeature())
- aConstrEnt[indAttr] = changeEntity(aConstrAttr->feature());
+ else if (aConstrAttr->isObject())
+ aConstrEnt[indAttr] = changeEntity(boost::dynamic_pointer_cast<ModelAPI_Feature>(aConstrAttr->object()));
else
aConstrEnt[indAttr] = changeEntity(aConstrAttr->attr());
}
bool isUpd = (*anAttrIter == theEntity);
boost::shared_ptr<ModelAPI_AttributeRefAttr> aRefAttr =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttrIter);
- if (aRefAttr && !aRefAttr->isFeature() && aRefAttr->attr() == theEntity)
+ if (aRefAttr && !aRefAttr->isObject() && aRefAttr->attr() == theEntity)
isUpd = true;
if (isUpd)
{
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
ModelAPI_EventCreator::get()->sendUpdated(aConstrIter->first, anEvent);
break;
}
{
boost::shared_ptr<ModelAPI_AttributeRefAttr> aRefAttr =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttrIter);
- if (aRefAttr && aRefAttr->isFeature() && aRefAttr->feature() == theFeature)
+ if (aRefAttr && aRefAttr->isObject() && aRefAttr->object() == theFeature)
{
- static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
ModelAPI_EventCreator::get()->sendUpdated(aConstrIter->first, anEvent);
break;
}
myGroups.clear();
// Register in event loop
- Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_CREATED));
- Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
- Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_DELETED));
- Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_MOVED));
+ Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+ Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+ Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
+ Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_MOVED));
}
SketchSolver_ConstraintManager::~SketchSolver_ConstraintManager()
// ============================================================================
void SketchSolver_ConstraintManager::processEvent(const Events_Message* theMessage)
{
- if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_CREATED) ||
- theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_UPDATED) ||
- theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_MOVED))
+ if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED) ||
+ theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED) ||
+ theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_MOVED))
{
- const ModelAPI_FeatureUpdatedMessage* anUpdateMsg =
- dynamic_cast<const ModelAPI_FeatureUpdatedMessage*>(theMessage);
- std::set< FeaturePtr > aFeatures = anUpdateMsg->features();
+ const ModelAPI_ObjectUpdatedMessage* anUpdateMsg =
+ dynamic_cast<const ModelAPI_ObjectUpdatedMessage*>(theMessage);
+ std::set< ObjectPtr > aFeatures = anUpdateMsg->features();
bool isModifiedEvt =
- theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_MOVED);
+ 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);
+ if (!aFeature) continue;
// 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(SketchPlugin_Sketch::ID()) == 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);
- if (aFeature)
- updateEntity(aFeature);
+ boost::shared_ptr<SketchPlugin_Feature> aSFeature =
+ boost::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
+ if (aSFeature)
+ updateEntity(aSFeature);
}
}
}
// Solve the set of constraints
resolveConstraints();
}
- else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_DELETED))
+ 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 SketchPlugin_Sketch::ID() in groups. The constraint groups should be updated when an object removed from Sketch
boost::shared_ptr<ModelAPI_AttributeRefList> aWPFeatures =
boost::dynamic_pointer_cast<ModelAPI_AttributeRefList>(aWP->data()->attribute(SketchPlugin_Sketch::FEATURES_ID()));
- std::list< FeaturePtr > aFeaturesList = aWPFeatures->list();
- std::list< FeaturePtr >::const_iterator anIter;
+ std::list< ObjectPtr >& aFeaturesList = aWPFeatures->list();
+ std::list< ObjectPtr >::const_iterator anIter;
for (anIter = aFeaturesList.begin(); anIter != aFeaturesList.end(); anIter++)
if (*anIter == theConstraint)
return aWP; // workplane is found
(*aGroupIter)->resolveConstraints();
// Features may be updated => send events
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
}
#include <ModelAPI_Data.h>
#include <ModelAPI_AttributeDocRef.h>
#include <ModelAPI_Object.h>
+#include <ModelAPI_ResultPart.h>
#include <QAction>
#include <QContextMenuEvent>
{
QMenu* aMenu = new QMenu();
XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
- QFeatureList aFeatures = aSelMgr->selection()->selectedFeatures();
- if (aFeatures.size() == 1) {
+ QList<ObjectPtr> aObjects = aSelMgr->selection()->selectedObjects();
+ if (aObjects.size() == 1) {
PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
- FeaturePtr aFeature = aFeatures.first();
+ ObjectPtr aObject = aObjects.first();
//Process Feature
- if (aFeature) {
- if (aFeature->getKind() == PartSetPlugin_Part::ID()) {
- ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
- DocumentPtr aFeaDoc = aObject->featureRef()->data()->docRef("PartDocument")->value();
+ if (aObject) {
+ ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
+ if (aPart) {
+ DocumentPtr aFeaDoc = aPart->document();
if (aMgr->currentDocument() == aFeaDoc)
aMenu->addAction(action("DEACTIVATE_PART_CMD"));
else
aMenu->addAction(action("ACTIVATE_PART_CMD"));
} else {
- aMenu->addAction(action("EDIT_CMD"));
-
- XGUI_Displayer* aDisplayer = myWorkshop->displayer();
- if (aDisplayer->isVisible(aFeature))
- aMenu->addAction(action("HIDE_CMD"));
- else
- aMenu->addAction(action("SHOW_CMD"));
+ ResultPtr aResult = boost::dynamic_pointer_cast<ModelAPI_Result>(aObject);
+ if (aResult) {
+ aMenu->addAction(action("EDIT_CMD"));
+
+ XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+ if (aDisplayer->isVisible(aResult))
+ aMenu->addAction(action("HIDE_CMD"));
+ else
+ aMenu->addAction(action("SHOW_CMD"));
+ }
}
aMenu->addAction(action("DELETE_CMD"));
aMenu->addSeparator();
void XGUI_ContextMenuMgr::addViewerItems(QMenu* theMenu) const
{
XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
- QFeatureList aFeatures = aSelMgr->selection()->selectedFeatures();
- if (aFeatures.size() > 0) {
- if (aFeatures.size() == 1)
+ QList<ObjectPtr> aObjects = aSelMgr->selection()->selectedObjects();
+ if (aObjects.size() > 0) {
+ if (aObjects.size() == 1)
theMenu->addAction(action("EDIT_CMD"));
bool isVisible = false;
- foreach(FeaturePtr aFeature, aFeatures) {
- if (myWorkshop->displayer()->isVisible(aFeature)) {
+ foreach(ObjectPtr aObject, aObjects) {
+ ResultPtr aRes = boost::dynamic_pointer_cast<ModelAPI_Result>(aObject);
+ if (aRes && myWorkshop->displayer()->isVisible(aRes)) {
isVisible = true;
break;
}
#include <ModelAPI_Document.h>
#include <ModelAPI_Feature.h>
+#include <ModelAPI_ResultPart.h>
#include <QAbstractItemModel>
#include <QColor>
//! Returns Feature object by the given Model index.
//! Returns 0 if the given index is not index of a feature
- virtual FeaturePtr feature(const QModelIndex& theIndex) const = 0;
+ virtual ObjectPtr object(const QModelIndex& theIndex) const = 0;
//! Returns QModelIndex which corresponds to the given feature
//! If the feature is not found then index is not valid
- virtual QModelIndex featureIndex(const FeaturePtr& theFeature) const = 0;
+ virtual QModelIndex objectIndex(const ObjectPtr& theFeature) const = 0;
//! Returns parent index of the given feature
- virtual QModelIndex findParent(const FeaturePtr& theFeature) const = 0;
+ virtual QModelIndex findParent(const ObjectPtr& theObject) const = 0;
//! Returns index corresponded to the group
virtual QModelIndex findGroup(const std::string& theGroup) const = 0;
virtual bool hasDocument(const DocumentPtr& theDoc) const = 0;
//! Return a Part object
- virtual FeaturePtr part() const = 0;
+ virtual ResultPartPtr part() const = 0;
protected:
//! Id of the current part object in the document
#include "XGUI_Viewer.h"
#include "XGUI_Workshop.h"
#include "XGUI_ViewerProxy.h"
-#include "XGUI_Tools.h"
+#include "ModuleBase_Tools.h"
#include <ModelAPI_Document.h>
#include <ModelAPI_Data.h>
{
}
-bool XGUI_Displayer::isVisible(FeaturePtr theFeature)
+bool XGUI_Displayer::isVisible(ResultPtr theResult)
{
- FeaturePtr aFeature = XGUI_Tools::realFeature(theFeature);
- return myFeature2AISObjectMap.find(aFeature) != myFeature2AISObjectMap.end();
+ return myResult2AISObjectMap.find(theResult) != myResult2AISObjectMap.end();
}
-bool XGUI_Displayer::display(FeaturePtr theFeature, bool isUpdateViewer)
+bool XGUI_Displayer::display(ResultPtr theResult, bool isUpdateViewer)
{
- FeaturePtr aFeature = XGUI_Tools::realFeature(theFeature);
- boost::shared_ptr<GeomAPI_Shape> aShapePtr = aFeature->data()->shape();
+ boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModuleBase_Tools::shape(theResult);
if (aShapePtr) {
boost::shared_ptr<GeomAPI_AISObject> anAIS(new GeomAPI_AISObject());
anAIS->createShape(aShapePtr);
- return display(aFeature, anAIS, isUpdateViewer);
+ return display(theResult, anAIS, isUpdateViewer);
}
return false;
}
-bool XGUI_Displayer::display(FeaturePtr theFeature,
+bool XGUI_Displayer::display(ResultPtr theResult,
boost::shared_ptr<GeomAPI_AISObject> theAIS, bool isUpdateViewer)
{
Handle(AIS_InteractiveContext) aContext = AISContext();
Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
if (!anAISIO.IsNull()) {
- myFeature2AISObjectMap[theFeature] = theAIS;
+ myResult2AISObjectMap[theResult] = theAIS;
aContext->Display(anAISIO, isUpdateViewer);
return true;
}
-void XGUI_Displayer::erase(FeaturePtr theFeature,
+void XGUI_Displayer::erase(ResultPtr theResult,
const bool isUpdateViewer)
{
- FeaturePtr aFeature = XGUI_Tools::realFeature(theFeature);
-
- if (myFeature2AISObjectMap.find(aFeature) == myFeature2AISObjectMap.end())
+ if (myResult2AISObjectMap.find(theResult) == myResult2AISObjectMap.end())
return;
Handle(AIS_InteractiveContext) aContext = AISContext();
- boost::shared_ptr<GeomAPI_AISObject> anObject = myFeature2AISObjectMap[aFeature];
+ boost::shared_ptr<GeomAPI_AISObject> anObject = myResult2AISObjectMap[theResult];
if (anObject) {
Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
if (!anAIS.IsNull()) {
}
}
- myFeature2AISObjectMap.erase(aFeature);
+ myResult2AISObjectMap.erase(theResult);
}
-bool XGUI_Displayer::redisplay(FeaturePtr theFeature,
+bool XGUI_Displayer::redisplay(ResultPtr theFeature,
boost::shared_ptr<GeomAPI_AISObject> theAIS,
const bool isUpdateViewer)
{
//aContext->SetPixelTolerance(MOUSE_SENSITIVITY_IN_PIXEL);
}
// display or redisplay presentation
- boost::shared_ptr<GeomAPI_AISObject> anObj = myFeature2AISObjectMap[theFeature];
+ boost::shared_ptr<GeomAPI_AISObject> anObj = myResult2AISObjectMap[theFeature];
if (isVisible(theFeature) && anObj && !anObj->empty()) {
aContext->RecomputeSelectionOnly(anAIS);
}
else {
- myFeature2AISObjectMap[theFeature] = theAIS;
+ myResult2AISObjectMap[theFeature] = theAIS;
aContext->Display(anAIS, false);
isCreated = true;
}
return isCreated;
}
-bool XGUI_Displayer::redisplay(FeaturePtr theFeature, bool isUpdateViewer)
+bool XGUI_Displayer::redisplay(ResultPtr theResult, bool isUpdateViewer)
{
- FeaturePtr aFeature = XGUI_Tools::realFeature(theFeature);
- if (!isVisible(aFeature))
+ if (!isVisible(theResult))
return false;
- boost::shared_ptr<GeomAPI_Shape> aShapePtr = aFeature->data()->shape();
+ boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModuleBase_Tools::shape(theResult);
if (aShapePtr) {
- boost::shared_ptr<GeomAPI_AISObject> aAISObj = getAISObject(aFeature);
+ boost::shared_ptr<GeomAPI_AISObject> aAISObj = getAISObject(theResult);
Handle(AIS_Shape) aAISShape = Handle(AIS_Shape)::DownCast(aAISObj->impl<Handle(AIS_InteractiveObject)>());
if (!aAISShape.IsNull()) {
aAISShape->Set(aShapePtr->impl<TopoDS_Shape>());
return false;
}
-void XGUI_Displayer::activateInLocalContext(FeaturePtr theFeature,
+void XGUI_Displayer::activateInLocalContext(ResultPtr theResult,
const std::list<int>& theModes, const bool isUpdateViewer)
{
Handle(AIS_InteractiveContext) aContext = AISContext();
}
// display or redisplay presentation
Handle(AIS_InteractiveObject) anAIS;
- if (isVisible(theFeature))
+ if (isVisible(theResult))
{
- boost::shared_ptr<GeomAPI_AISObject> anObj = myFeature2AISObjectMap[theFeature];
+ boost::shared_ptr<GeomAPI_AISObject> anObj = myResult2AISObjectMap[theResult];
if (anObj)
anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
}
updateViewer();
}
-void XGUI_Displayer::stopSelection(const QFeatureList& theFeatures, const bool isStop,
+void XGUI_Displayer::stopSelection(const QResultList& theResults, const bool isStop,
const bool isUpdateViewer)
{
Handle(AIS_InteractiveContext) aContext = AISContext();
Handle(AIS_Shape) anAIS;
- QFeatureList::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end();
- FeaturePtr aFeature;
+ QResultList::const_iterator anIt = theResults.begin(), aLast = theResults.end();
+ ResultPtr aFeature;
for (; anIt != aLast; anIt++) {
aFeature = *anIt;
if (isVisible(aFeature))
- anAIS = Handle(AIS_Shape)::DownCast(myFeature2AISObjectMap[aFeature]->impl<Handle(AIS_InteractiveObject)>());
+ anAIS = Handle(AIS_Shape)::DownCast(myResult2AISObjectMap[aFeature]->impl<Handle(AIS_InteractiveObject)>());
if (anAIS.IsNull())
continue;
updateViewer();
}
-void XGUI_Displayer::setSelected(const QFeatureList& theFeatures, const bool isUpdateViewer)
+void XGUI_Displayer::setSelected(const QResultList& theResults, const bool isUpdateViewer)
{
Handle(AIS_InteractiveContext) aContext = AISContext();
// we need to unhighligth objects manually in the current local context
aLocalContext->UnhilightLastDetected(myWorkshop->viewer()->activeView());
aContext->ClearSelected();
- foreach(FeaturePtr aFeature, theFeatures) {
- FeaturePtr aRFeature = XGUI_Tools::realFeature(aFeature);
- if (myFeature2AISObjectMap.find(aRFeature) == myFeature2AISObjectMap.end())
+ foreach(ResultPtr aResult, theResults) {
+ if (myResult2AISObjectMap.find(aResult) == myResult2AISObjectMap.end())
return;
- boost::shared_ptr<GeomAPI_AISObject> anObj = myFeature2AISObjectMap[aRFeature];
+ boost::shared_ptr<GeomAPI_AISObject> anObj = myResult2AISObjectMap[aResult];
if (anObj)
{
Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
Handle(AIS_InteractiveObject) anIO = anIter.Value();
ic->Erase(anIO, false);
}
- myFeature2AISObjectMap.clear();
+ myResult2AISObjectMap.clear();
if (isUpdateViewer)
updateViewer();
}*/
-void XGUI_Displayer::eraseDeletedFeatures(const bool isUpdateViewer)
+void XGUI_Displayer::eraseDeletedResults(const bool isUpdateViewer)
{
Handle(AIS_InteractiveContext) aContext = AISContext();
- FeatureToAISMap::const_iterator aFIt = myFeature2AISObjectMap.begin(),
- aFLast = myFeature2AISObjectMap.end();
- std::list<FeaturePtr> aRemoved;
+ ResultToAISMap::const_iterator aFIt = myResult2AISObjectMap.begin(),
+ aFLast = myResult2AISObjectMap.end();
+ std::list<ResultPtr> aRemoved;
for (; aFIt != aFLast; aFIt++)
{
- FeaturePtr aFeature = (*aFIt).first;
+ ResultPtr aFeature = (*aFIt).first;
if (!aFeature || !aFeature->data() || !aFeature->data()->isValid()) {
boost::shared_ptr<GeomAPI_AISObject> anObj = (*aFIt).second;
if (!anObj) continue;
}
}
}
- std::list<FeaturePtr>::const_iterator anIt = aRemoved.begin(),
+ std::list<ResultPtr>::const_iterator anIt = aRemoved.begin(),
aLast = aRemoved.end();
for (; anIt != aLast; anIt++) {
- myFeature2AISObjectMap.erase(myFeature2AISObjectMap.find(*anIt));
+ myResult2AISObjectMap.erase(myResult2AISObjectMap.find(*anIt));
}
if (isUpdateViewer)
}
boost::shared_ptr<GeomAPI_AISObject> XGUI_Displayer::getAISObject(
- FeaturePtr theFeature) const
+ ResultPtr theFeature) const
{
boost::shared_ptr<GeomAPI_AISObject> anIO;
- if (myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end())
- anIO = (myFeature2AISObjectMap.find(theFeature))->second;
+ if (myResult2AISObjectMap.find(theFeature) != myResult2AISObjectMap.end())
+ anIO = (myResult2AISObjectMap.find(theFeature))->second;
return anIO;
}
-FeaturePtr XGUI_Displayer::getFeature(Handle(AIS_InteractiveObject) theIO) const
+ResultPtr XGUI_Displayer::getResult(Handle(AIS_InteractiveObject) theIO) const
{
- FeaturePtr aFeature;
- FeatureToAISMap::const_iterator aFIt = myFeature2AISObjectMap.begin(),
- aFLast = myFeature2AISObjectMap.end();
+ ResultPtr aFeature;
+ ResultToAISMap::const_iterator aFIt = myResult2AISObjectMap.begin(),
+ aFLast = myResult2AISObjectMap.end();
for (; aFIt != aFLast && !aFeature; aFIt++) {
boost::shared_ptr<GeomAPI_AISObject> anObj = (*aFIt).second;
if (!anObj) continue;
#include <AIS_InteractiveContext.hxx>
#include <NCollection_List.hxx>
-#include <ModelAPI_Feature.h>
+#include <ModelAPI_Result.h>
#include <ModuleBase_Definitions.h>
#include <ModuleBase_ViewerPrs.h>
/// Returns the feature visibility state.
/// \param theFeature a feature instance
- bool isVisible(FeaturePtr theFeature);
+ bool isVisible(ResultPtr theResult);
/// Display the feature. Obtain the visualized object from the feature.
/// \param theFeature a feature instance
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
/// Returns true if the Feature succesfully displayed
- bool display(FeaturePtr theFeature, bool isUpdateViewer = true);
+ bool display(ResultPtr theFeature, bool isUpdateViewer = true);
/// Display the feature and a shape. This shape would be associated to the given feature
/// \param theFeature a feature instance
/// \param theAIS AIS presentation
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
/// Returns true if the Feature succesfully displayed
- bool display(FeaturePtr theFeature, boost::shared_ptr<GeomAPI_AISObject> theAIS, bool isUpdateViewer = true);
+ bool display(ResultPtr theResult, boost::shared_ptr<GeomAPI_AISObject> theAIS, bool isUpdateViewer = true);
/// Display the shape and activate selection of sub-shapes
/// \param theFeature a feature instance
/// \param theAIS an AIS object
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
/// \returns true if the presentation is created
- bool redisplay(FeaturePtr theFeature,
+ bool redisplay(ResultPtr theFeature,
boost::shared_ptr<GeomAPI_AISObject> theAIS,
const bool isUpdateViewer = true);
* \param theFeature a feature instance
* \param isUpdateViewer the parameter whether the viewer should be update immediatelly
*/
- bool redisplay(FeaturePtr theFeature, bool isUpdateViewer = true);
+ bool redisplay(ResultPtr theFeature, bool isUpdateViewer = true);
/// Redisplay the shape and activate selection of sub-shapes
/// \param theFeature a feature instance
/// \param theShape a shape
/// \param theMode a list of local selection modes
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
- void activateInLocalContext(FeaturePtr theFeature,
+ void activateInLocalContext(ResultPtr theFeature,
const std::list<int>& theModes, const bool isUpdateViewer = true);
/// Stop the current selection and color the given features to the selection color
/// \param theFeatures a list of features to be disabled
/// \param theToStop the boolean state whether it it stopped or non stopped
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
- void stopSelection(const QFeatureList& theFeatures, const bool isStop,
+ void stopSelection(const QResultList& theFeatures, const bool isStop,
const bool isUpdateViewer);
/**
* \param theFeatures a list of features to be selected
* isUpdateViewer the parameter whether the viewer should be update immediatelly
*/
- void setSelected(const QFeatureList& theFeatures, bool isUpdateViewer = true);
+ void setSelected(const QResultList& theFeatures, bool isUpdateViewer = true);
/// Erase the feature and a shape.
/// \param theFeature a feature instance
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
- void erase(FeaturePtr theFeature, const bool isUpdateViewer = true);
+ void erase(ResultPtr theResult, const bool isUpdateViewer = true);
/// Erase all presentations
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
/// Erase AIS interactive objects, which has an empty feature in the internal map
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
- void eraseDeletedFeatures(const bool isUpdateViewer = true);
+ void eraseDeletedResults(const bool isUpdateViewer = true);
/// Deactivates selection of sub-shapes
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
/// Searches the interactive object by feature
/// \param theFeature the feature or NULL if it not visualized
/// \return theIO an interactive object
- boost::shared_ptr<GeomAPI_AISObject> getAISObject(FeaturePtr theFeature) const;
+ boost::shared_ptr<GeomAPI_AISObject> getAISObject(ResultPtr theFeature) const;
/// Searches the feature by interactive object
/// \param theIO an interactive object
/// \return feature the feature or NULL if it not visualized
- FeaturePtr getFeature(Handle(AIS_InteractiveObject) theIO) const;
+ ResultPtr getResult(Handle(AIS_InteractiveObject) theIO) const;
protected:
/// Deactivate local selection
protected:
XGUI_Workshop* myWorkshop;
- typedef std::map<FeaturePtr, boost::shared_ptr<GeomAPI_AISObject> > FeatureToAISMap;
- FeatureToAISMap myFeature2AISObjectMap;
+ typedef std::map<ResultPtr, boost::shared_ptr<GeomAPI_AISObject> > ResultToAISMap;
+ ResultToAISMap myResult2AISObjectMap;
};
#include <ModelAPI_Document.h>
#include <ModelAPI_Feature.h>
#include <ModelAPI_Data.h>
+#include <ModelAPI_ResultPart.h>
#include <Model_Events.h>
#include <ModelAPI_Object.h>
: QAbstractItemModel(theParent), myActivePart(0)
{
// Register in event loop
- Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_CREATED));
- Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
- Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_DELETED));
+ Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+ Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+ Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
// Create a top part of data tree model
myModel = new XGUI_TopDataModel(this);
DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
// Created object event *******************
- if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_CREATED)) {
- const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
- std::set<FeaturePtr> aFeatures = aUpdMsg->features();
+ if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
+ const Model_ObjectUpdatedMessage* aUpdMsg = dynamic_cast<const Model_ObjectUpdatedMessage*>(theMessage);
+ std::set<ObjectPtr> aFeatures = aUpdMsg->features();
- std::set<FeaturePtr>::const_iterator aIt;
+ std::set<ObjectPtr>::const_iterator aIt;
for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
- FeaturePtr aFeature = (*aIt);
+ ObjectPtr aFeature = (*aIt);
DocumentPtr aDoc = aFeature->document();
if (aDoc == aRootDoc) { // If root objects
- if (aFeature->getGroup().compare(ModelAPI_Document::PARTS_GROUP()) == 0) { // Update only Parts group
+ if (aFeature->groupName().compare(ModelAPI_ResultPart::group()) == 0) { // Update only Parts group
// Add a new part
int aStart = myPartModels.size();
XGUI_PartDataModel* aModel = new XGUI_PartDataModel(this);
}
}
// Deleted object event ***********************
- } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_DELETED)) {
- const Model_FeatureDeletedMessage* aUpdMsg = dynamic_cast<const Model_FeatureDeletedMessage*>(theMessage);
+ } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
+ const Model_ObjectDeletedMessage* aUpdMsg = dynamic_cast<const Model_ObjectDeletedMessage*>(theMessage);
DocumentPtr aDoc = aUpdMsg->document();
std::set<std::string> aGroups = aUpdMsg->groups();
for (aIt = aGroups.begin(); aIt != aGroups.end(); ++aIt) {
std::string aGroup = (*aIt);
if (aDoc == aRootDoc) { // If root objects
- if (aGroup.compare(ModelAPI_Document::PARTS_GROUP()) == 0) { // Updsate only Parts group
+ if (aGroup.compare(ModelAPI_ResultPart::group()) == 0) { // Updsate only Parts group
int aStart = myPartModels.size() - 1;
removeSubModel(aStart);
removeRow(aStart, partFolderNode());
}
}
// Deleted object event ***********************
- } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_UPDATED)) {
- //const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
- //FeaturePtr aFeature = aUpdMsg->feature();
+ } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {
+ //const Model_ObjectUpdatedMessage* aUpdMsg = dynamic_cast<const Model_ObjectUpdatedMessage*>(theMessage);
+ //ObjectPtr aFeature = aUpdMsg->feature();
//DocumentPtr aDoc = aFeature->document();
// TODO: Identify the necessary index by the modified feature
beginResetModel();
clearModelIndexes();
- int aNbParts = aRootDoc->size(ModelAPI_Document::PARTS_GROUP());
+ int aNbParts = aRootDoc->size(ModelAPI_ResultPart::group());
if (myPartModels.size() != aNbParts) { // resize internal models
while (myPartModels.size() > aNbParts) {
delete myPartModels.last();
{
int aOffset = historyOffset();
DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
- FeaturePtr aFeature = aRootDoc->feature(ModelAPI_Document::FEATURES_GROUP(), theIndex.row() - aOffset);
+ ObjectPtr aObj = aRootDoc->object(ModelAPI_Feature::group(), theIndex.row() - aOffset);
+ FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
if (!aFeature)
return QVariant();
switch (theRole) {
case Qt::DisplayRole:
if (aFeature)
- return aFeature->data()->getName().c_str();
+ return aFeature->data()->name().c_str();
else
return QVariant();
case Qt::DecorationRole:
// Size of external models
int aVal = historyOffset();
// Plus history size
- aVal += aRootDoc->size(ModelAPI_Document::FEATURES_GROUP());
+ aVal += aRootDoc->size(ModelAPI_Feature::group());
return aVal;
}
if (theParent.internalId() == PartsFolder) {
myIndexes.clear();
}
-FeaturePtr XGUI_DocumentDataModel::feature(const QModelIndex& theIndex) const
+ObjectPtr XGUI_DocumentDataModel::object(const QModelIndex& theIndex) const
{
if (theIndex.internalId() == PartsFolder)
- return FeaturePtr();
+ return ObjectPtr();
if (theIndex.internalId() == HistoryNode) {
DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
int aOffset = historyOffset();
- return aRootDoc->feature(ModelAPI_Document::FEATURES_GROUP(), theIndex.row() - aOffset);
+ return aRootDoc->object(ModelAPI_Feature::group(), theIndex.row() - aOffset);
}
QModelIndex* aIndex = toSourceModelIndex(theIndex);
if (!isSubModel(aIndex->model()))
- return FeaturePtr();
+ return ObjectPtr();
const XGUI_FeaturesModel* aModel = dynamic_cast<const XGUI_FeaturesModel*>(aIndex->model());
- return aModel->feature(*aIndex);
+ return aModel->object(*aIndex);
}
bool XGUI_DocumentDataModel::insertRows(int theRow, int theCount, const QModelIndex& theParent)
return false;
}
-FeaturePtr XGUI_DocumentDataModel::activePart() const
+ResultPartPtr XGUI_DocumentDataModel::activePart() const
{
if (myActivePart)
return myActivePart->part();
- return FeaturePtr();
+ return ResultPartPtr();
}
void XGUI_DocumentDataModel::deactivatePart()
Qt::ItemFlags XGUI_DocumentDataModel::flags(const QModelIndex& theIndex) const
{
Qt::ItemFlags aFlags = QAbstractItemModel::flags(theIndex);
- if (feature(theIndex)) {
+ if (object(theIndex)) {
aFlags |= Qt::ItemIsEditable;
}
return aFlags;
}
-QModelIndex XGUI_DocumentDataModel::partIndex(const FeaturePtr& theFeature) const
+QModelIndex XGUI_DocumentDataModel::partIndex(const ResultPartPtr& theObject) const
{
- FeaturePtr aFeature = XGUI_Tools::realFeature(theFeature);
-
int aRow = -1;
XGUI_PartModel* aModel = 0;
foreach (XGUI_PartModel* aPartModel, myPartModels) {
aRow++;
- if (aPartModel->part() == aFeature) {
+ if (aPartModel->part() == theObject) {
aModel = aPartModel;
break;
}
return QModelIndex();
}
-QModelIndex XGUI_DocumentDataModel::featureIndex(const FeaturePtr theFeature) const
+QModelIndex XGUI_DocumentDataModel::objectIndex(const ObjectPtr theObject) const
{
// Check that this feature belongs to root document
DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
- DocumentPtr aDoc = theFeature->document();
+ DocumentPtr aDoc = theObject->document();
if (aDoc == aRootDoc) {
// This feature belongs to histrory or top model
- if (theFeature->isInHistory()) {
+ if (theObject->isInHistory()) {
int aId;
- for (aId = 0; aId < aRootDoc->size(ModelAPI_Document::FEATURES_GROUP()); aId++) {
- if (theFeature == aRootDoc->feature(ModelAPI_Document::FEATURES_GROUP(), aId))
+ for (aId = 0; aId < aRootDoc->size(ModelAPI_Feature::group()); aId++) {
+ if (theObject == aRootDoc->object(ModelAPI_Feature::group(), aId))
break;
}
return index(aId + historyOffset(), 0, QModelIndex());
} else {
- QModelIndex aIndex = myModel->featureIndex(theFeature);
+ QModelIndex aIndex = myModel->objectIndex(theObject);
return aIndex.isValid()?
createIndex(aIndex.row(), aIndex.column(), (void*)getModelIndex(aIndex)) :
QModelIndex();
}
}
if (aPartModel) {
- QModelIndex aIndex = aPartModel->featureIndex(theFeature);
+ QModelIndex aIndex = aPartModel->objectIndex(theObject);
return aIndex.isValid()?
createIndex(aIndex.row(), aIndex.column(), (void*)getModelIndex(aIndex)) :
QModelIndex();
#include "XGUI.h"
#include <ModuleBase_Definitions.h>
+#include <ModelAPI_ResultPart.h>
-#include <QAbstractItemModel>
#include <Events_Listener.h>
+#include <QAbstractItemModel>
#include <QList>
class ModelAPI_Document;
Qt::ItemFlags flags(const QModelIndex& theIndex) const;
- //! Returns Feature object by the given Model index.
- //! Returns 0 if the given index is not index of a feature
- FeaturePtr feature(const QModelIndex& theIndex) const;
+ //! Returns an object by the given Model index.
+ //! Returns 0 if the given index is not index of an object
+ ObjectPtr object(const QModelIndex& theIndex) const;
- QModelIndex featureIndex(const FeaturePtr theFeature) const;
+ QModelIndex objectIndex(const ObjectPtr theObject) const;
- //! Returns QModelIndex which corresponds to the given feature if this is a part
- //! If the feature is not found then index is not valid
- QModelIndex partIndex(const FeaturePtr& theFeature) const;
+ //! Returns QModelIndex which corresponds to the given part
+ //! If the object is not found then index is not valid
+ QModelIndex partIndex(const ResultPartPtr& thePart) const;
//! Activates a part data model if the index is a Part node index.
//! Returns true if active part changed.
bool activatedIndex(const QModelIndex& theIndex);
- //! Retrurns Feature which corresponds to active part
- FeaturePtr activePart() const;
+ //! Retrurns active part
+ ResultPartPtr activePart() const;
//! Retrurns QModelIndex of active part
QModelIndex activePartIndex() const { return myActivePartIndex; }
}
-QFeatureList XGUI_ModuleConnector::selectedFeatures() const
+QList<ObjectPtr> XGUI_ModuleConnector::selectedObjects() const
{
- return myWorkshop->selector()->selection()->selectedFeatures();
+ return myWorkshop->selector()->selection()->selectedObjects();
}
ModuleBase_IModule* XGUI_ModuleConnector::module() const
virtual Handle(AIS_InteractiveContext) AISContext() const;
//! Returns list of currently selected data objects
- virtual QFeatureList selectedFeatures() const;
+ virtual QList<ObjectPtr> selectedObjects() const;
//! Returns instance of loaded module
virtual ModuleBase_IModule* module() const;
XGUI_DocumentDataModel* aModel = dataModel();
QModelIndexList::const_iterator aIt;
for (aIt = aIndexes.constBegin(); aIt != aIndexes.constEnd(); ++aIt) {
- FeaturePtr aFeature = aModel->feature(*aIt);
- if (aFeature)
- mySelectedData.append(aFeature);
+ ObjectPtr aObject = aModel->object(*aIt);
+ if (aObject)
+ mySelectedData.append(aObject);
}
emit selectionChanged();
}
QLineEdit* aEditor = dynamic_cast<QLineEdit*>(theEditor);
if (aEditor) {
QString aRes = aEditor->text();
- FeaturePtr aFeature = mySelectedData.first();
+ ObjectPtr aFeature = mySelectedData.first();
PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
aMgr->rootDocument()->startOperation();
- if (!XGUI_Tools::isModelObject(aFeature))
- aFeature->data()->setName(qPrintable(aRes));
- else
- boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature)->setName(qPrintable(aRes));
+ aFeature->data()->setName(qPrintable(aRes));
aMgr->rootDocument()->finishOperation();
}
}
aLabelWgt->setFrameShadow(myTreeView->frameShadow());
connect(myTreeView, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
- connect(myTreeView, SIGNAL(activePartChanged(FeaturePtr)), this, SLOT(onActivePartChanged(FeaturePtr)));
- connect(myTreeView, SIGNAL(activePartChanged(FeaturePtr)), this, SIGNAL(activePartChanged(FeaturePtr)));
+ connect(myTreeView, SIGNAL(activePartChanged(ObjectPtr)), this, SLOT(onActivePartChanged(ObjectPtr)));
+ connect(myTreeView, SIGNAL(activePartChanged(ObjectPtr)), this, SIGNAL(activePartChanged(ObjectPtr)));
connect(myActiveDocLbl, SIGNAL(customContextMenuRequested(const QPoint&)),
this, SLOT(onLabelContextMenuRequested(const QPoint&)));
connect(myTreeView, SIGNAL(contextMenuRequested(QContextMenuEvent*)),
this, SLOT(onContextMenuRequested(QContextMenuEvent*)));
- onActivePartChanged(FeaturePtr());
+ onActivePartChanged(ObjectPtr());
// Create internal actions
QAction* aAction = new QAction(QIcon(":pictures/rename_edit.png"), tr("Rename"), this);
}
//***************************************************
-void XGUI_ObjectsBrowser::onActivePartChanged(FeaturePtr thePart)
+void XGUI_ObjectsBrowser::onActivePartChanged(ObjectPtr thePart)
{
QPalette aPalet = myActiveDocLbl->palette();
if (thePart) {
myTreeView->setExpanded(myDocModel->activePartIndex(), false);
}
myDocModel->deactivatePart();
- onActivePartChanged(FeaturePtr());
- emit activePartChanged(FeaturePtr());
+ onActivePartChanged(ObjectPtr());
+ emit activePartChanged(ObjectPtr());
}
} else {
// End of editing by mouse click
}
//***************************************************
-void XGUI_ObjectsBrowser::activatePart(const FeaturePtr& thePart)
+void XGUI_ObjectsBrowser::activatePart(const ResultPartPtr& thePart)
{
if (thePart) {
QModelIndex aIndex = myDocModel->partIndex(thePart);
if (myDocModel->activePartIndex().isValid()) {
myTreeView->setExpanded(aIndex.parent(), true);
myTreeView->setExpanded(aIndex, true);
- onActivePartChanged(myDocModel->feature(aIndex));
+ onActivePartChanged(myDocModel->object(aIndex));
} else {
- onActivePartChanged(FeaturePtr());
+ onActivePartChanged(ObjectPtr());
}
}
} else {
if (aIndex.isValid()) {
myDocModel->activatedIndex(aIndex);
myTreeView->setExpanded(aIndex, false);
- onActivePartChanged(FeaturePtr());
+ onActivePartChanged(ObjectPtr());
}
}
}
//***************************************************
void XGUI_ObjectsBrowser::onContextMenuRequested(QContextMenuEvent* theEvent)
{
- myFeaturesList = myTreeView->selectedFeatures();
- bool toEnable = myFeaturesList.size() > 0;
+ myObjectsList = myTreeView->selectedObjects();
+ bool toEnable = myObjectsList.size() > 0;
foreach(QAction* aCmd, actions()) {
aCmd->setEnabled(toEnable);
}
//***************************************************
void XGUI_ObjectsBrowser::onLabelContextMenuRequested(const QPoint& thePnt)
{
- myFeaturesList.clear();
+ myObjectsList.clear();
//Empty feature pointer means that selected root document
- myFeaturesList.append(FeaturePtr());
+ myObjectsList.append(ObjectPtr());
foreach(QAction* aCmd, actions()) {
aCmd->setEnabled(true);
//***************************************************
void XGUI_ObjectsBrowser::onEditItem()
{
- if (myFeaturesList.size() > 0) {
- FeaturePtr aFeature = myFeaturesList.first();
+ if (myObjectsList.size() > 0) {
+ ObjectPtr aFeature = myObjectsList.first();
if (aFeature) { // Selection happens in TreeView
// Find index which corresponds the feature
QModelIndex aIndex;
foreach(QModelIndex aIdx, selectedIndexes()) {
- FeaturePtr aFea = dataModel()->feature(aIdx);
- if (dataModel()->feature(aIdx)->isSame(aFeature)) {
+ ObjectPtr aFea = dataModel()->object(aIdx);
+ if (dataModel()->object(aIdx)->isSame(aFeature)) {
aIndex = aIdx;
break;
}
//***************************************************
void XGUI_ObjectsBrowser::onSelectionChanged()
{
- myFeaturesList = myTreeView->selectedFeatures();
+ myObjectsList = myTreeView->selectedObjects();
emit selectionChanged();
}
}
//***************************************************
-void XGUI_ObjectsBrowser::setFeaturesSelected(const QFeatureList& theFeatures)
+void XGUI_ObjectsBrowser::setObjectsSelected(const QList<ObjectPtr>& theObjects)
{
QList<QModelIndex> theIndexes;
QItemSelectionModel* aSelectModel = myTreeView->selectionModel();
aSelectModel->clear();
- foreach(FeaturePtr aFeature, theFeatures) {
- QModelIndex aIndex = myDocModel->featureIndex(aFeature);
+ foreach(ObjectPtr aFeature, theObjects) {
+ QModelIndex aIndex = myDocModel->objectIndex(aFeature);
if (aIndex.isValid()) {
aSelectModel->select(aIndex, QItemSelectionModel::Select);
}
#include "XGUI.h"
#include <ModuleBase_Definitions.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_ResultPart.h>
#include <QWidget>
#include <QTreeView>
XGUI_DataTree(QWidget* theParent);
virtual ~XGUI_DataTree();
- //! Returns list of currently selected features
- QFeatureList selectedFeatures() const { return mySelectedData; }
+ //! Returns list of currently selected objects
+ QList<ObjectPtr> selectedObjects() const { return mySelectedData; }
XGUI_DocumentDataModel* dataModel() const;
signals:
//! Emited when selection is changed
void selectionChanged();
- void activePartChanged(FeaturePtr thePart);
+ void activePartChanged(ObjectPtr thePart);
//! Emited on context menu request
void contextMenuRequested(QContextMenuEvent* theEvent);
private:
//! List of currently selected data
- QFeatureList mySelectedData;
+ QList<ObjectPtr> mySelectedData;
};
//! Returns Model which provides access to data objects
XGUI_DocumentDataModel* dataModel() const { return myDocModel; }
- //! Returns list of currently selected features
- QFeatureList selectedFeatures() const { return myFeaturesList; }
+ //! Returns list of currently selected objects
+ QList<ObjectPtr> selectedObjects() const { return myObjectsList; }
- void setFeaturesSelected(const QFeatureList& theFeatures);
+ void setObjectsSelected(const QList<ObjectPtr>& theObjects);
//! Returns currently selected indexes
QModelIndexList selectedIndexes() const { return myTreeView->selectionModel()->selectedIndexes(); }
XGUI_DataTree* treeView() const { return myTreeView; }
//! Activates currently selected part. Signal activePartChanged will not be sent
- void activatePart(const FeaturePtr& thePart);
+ void activatePart(const ResultPartPtr& thePart);
void rebuildDataTree();
void selectionChanged();
//! Emited when current active document is changed
- void activePartChanged(FeaturePtr thePart);
+ void activePartChanged(ObjectPtr thePart);
//! Emited on context menu request
void contextMenuRequested(QContextMenuEvent* theEvent);
virtual bool eventFilter(QObject* obj, QEvent* theEvent);
private slots:
- void onActivePartChanged(FeaturePtr thePart);
+ void onActivePartChanged(ObjectPtr thePart);
void onContextMenuRequested(QContextMenuEvent* theEvent);
void onLabelContextMenuRequested(const QPoint& thePnt);
QLineEdit* myActiveDocLbl;
XGUI_DataTree* myTreeView;
- QFeatureList myFeaturesList;
+ QList<ObjectPtr> myObjectsList;
};
#endif
\ No newline at end of file
#include <ModelAPI_PluginManager.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_Feature.h>
+#include <ModelAPI_Result.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_AttributeDocRef.h>
#include <ModelAPI_Object.h>
+#include <ModelAPI_ResultPart.h>
+#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_ResultParameters.h>
#include <QIcon>
#include <QBrush>
-//FeaturePtr featureObj(const FeaturePtr& theFeature)
+//ObjectPtr featureObj(const ObjectPtr& theFeature)
//{
// ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(theFeature);
// if (aObject)
case ParamObject:
{
DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
- FeaturePtr aFeature = aRootDoc->feature(ModelAPI_Document::PARAMETERS_GROUP(), theIndex.row());
- if (aFeature)
- return boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature)->getName().c_str();
+ ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultParameters::group(), theIndex.row());
+ if (aObject)
+ return boost::dynamic_pointer_cast<ModelAPI_Object>(aObject)->data()->name().c_str();
}
case ConstructFolder:
return tr("Constructions") + QString(" (%1)").arg(rowCount(theIndex));
case ConstructObject:
{
DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
- FeaturePtr aFeature = aRootDoc->feature(ModelAPI_Document::CONSTRUCTIONS_GROUP(), theIndex.row());
- if (aFeature)
- return boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature)->getName().c_str();
+ ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultConstruction::group(), theIndex.row());
+ if (aObject)
+ return boost::dynamic_pointer_cast<ModelAPI_Object>(aObject)->data()->name().c_str();
}
}
break;
case ConstructFolder:
return QIcon(":pictures/constr_folder.png");
case ConstructObject:
- {
- DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
- FeaturePtr aFeature = aRootDoc->feature(ModelAPI_Document::CONSTRUCTIONS_GROUP(), theIndex.row());
- if (aFeature)
- return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind()));
- }
+ return QIcon(":pictures/constr_object.png");
+ //{
+ // DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
+ // ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultConstruction::group(), theIndex.row());
+ // if (aObject)
+ // return QIcon(XGUI_Workshop::featureIcon(aObject->getKind()));
+ //}
}
break;
DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
if (theParent.internalId() == ParamsFolder)
- return aRootDoc->size(ModelAPI_Document::PARAMETERS_GROUP());
+ return aRootDoc->size(ModelAPI_ResultParameters::group());
if (theParent.internalId() == ConstructFolder)
- return aRootDoc->size(ModelAPI_Document::CONSTRUCTIONS_GROUP());
-
+ return aRootDoc->size(ModelAPI_ResultConstruction::group());
return 0;
}
return rowCount(theParent) > 0;
}
-FeaturePtr XGUI_TopDataModel::feature(const QModelIndex& theIndex) const
+ObjectPtr XGUI_TopDataModel::object(const QModelIndex& theIndex) const
{
switch (theIndex.internalId()) {
case ParamsFolder:
case ConstructFolder:
- return FeaturePtr();
+ return ObjectPtr();
case ParamObject:
{
DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
- return aRootDoc->feature(ModelAPI_Document::PARAMETERS_GROUP(), theIndex.row());
+ return aRootDoc->object(ModelAPI_ResultParameters::group(), theIndex.row());
}
case ConstructObject:
{
DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
- return aRootDoc->feature(ModelAPI_Document::CONSTRUCTIONS_GROUP(), theIndex.row());
+ return aRootDoc->object(ModelAPI_ResultConstruction::group(), theIndex.row());
}
}
- return FeaturePtr();
+ return ObjectPtr();
}
-QModelIndex XGUI_TopDataModel::findParent(const FeaturePtr& theFeature) const
+QModelIndex XGUI_TopDataModel::findParent(const ObjectPtr& theObject) const
{
- return findGroup(theFeature->getGroup().c_str());
+ return findGroup(theObject->groupName().c_str());
}
QModelIndex XGUI_TopDataModel::findGroup(const std::string& theGroup) const
{
- if (theGroup.compare(ModelAPI_Document::PARAMETERS_GROUP()) == 0)
+ if (theGroup.compare(ModelAPI_ResultParameters::group()) == 0)
return createIndex(0, 0, (qint32) ParamsFolder);
- if (theGroup.compare(ModelAPI_Document::CONSTRUCTIONS_GROUP()) == 0)
+ if (theGroup.compare(ModelAPI_ResultConstruction::group()) == 0)
return createIndex(1, 0, (qint32) ConstructFolder);
return QModelIndex();
}
-QModelIndex XGUI_TopDataModel::featureIndex(const FeaturePtr& theFeature) const
+QModelIndex XGUI_TopDataModel::objectIndex(const ObjectPtr& theObject) const
{
QModelIndex aIndex;
- if (theFeature) {
+ if (theObject) {
DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
- std::string aGroup = theFeature->getGroup();
+ std::string aGroup = theObject->groupName();
int aNb = aRootDoc->size(aGroup);
int aRow = -1;
for (int i = 0; i < aNb; i++) {
- if (aRootDoc->feature(aGroup, i) == theFeature) {
+ if (aRootDoc->object(aGroup, i) == theObject) {
aRow = i;
break;
}
}
if (aRow != -1) {
- if (aGroup.compare(ModelAPI_Document::PARAMETERS_GROUP()) == 0)
+ if (aGroup.compare(ModelAPI_ResultParameters::group()) == 0)
return createIndex(aRow, 0, (qint32) ParamObject);
- if (aGroup.compare(ModelAPI_Document::CONSTRUCTIONS_GROUP()) == 0)
+ if (aGroup.compare(ModelAPI_ResultConstruction::group()) == 0)
return createIndex(aRow, 0, (qint32) ConstructObject);
}
}
case MyRoot:
{
DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
- FeaturePtr aFeature = aRootDoc->feature(ModelAPI_Document::PARTS_GROUP(), myId);
- if (aFeature)
- return boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature)->getName().c_str();
+ ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), myId);
+ if (aObject)
+ return boost::dynamic_pointer_cast<ModelAPI_Object>(aObject)->data()->name().c_str();
}
case ParamsFolder:
return tr("Parameters") + QString(" (%1)").arg(rowCount(theIndex));
return tr("Bodies") + QString(" (%1)").arg(rowCount(theIndex));
case ParamObject:
{
- FeaturePtr aFeature = featureDocument()->feature(ModelAPI_Document::PARAMETERS_GROUP(), theIndex.row());
- if (aFeature)
- return boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature)->getName().c_str();
+ ObjectPtr aObject = partDocument()->object(ModelAPI_ResultParameters::group(), theIndex.row());
+ if (aObject)
+ return boost::dynamic_pointer_cast<ModelAPI_Object>(aObject)->data()->name().c_str();
}
case ConstructObject:
{
- FeaturePtr aFeature = featureDocument()->feature(ModelAPI_Document::CONSTRUCTIONS_GROUP(), theIndex.row());
- if (aFeature)
- return boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature)->getName().c_str();
+ ObjectPtr aObject = partDocument()->object(ModelAPI_ResultConstruction::group(), theIndex.row());
+ if (aObject)
+ return boost::dynamic_pointer_cast<ModelAPI_Object>(aObject)->data()->name().c_str();
}
case HistoryObject:
{
- FeaturePtr aFeature = featureDocument()->feature(ModelAPI_Document::FEATURES_GROUP(), theIndex.row() - 3);
- if (aFeature)
- return aFeature->data()->getName().c_str();
+ ObjectPtr aObject = partDocument()->object(ModelAPI_Feature::group(), theIndex.row() - 3);
+ if (aObject)
+ return aObject->data()->name().c_str();
}
}
break;
case BodiesFolder:
return QIcon(":pictures/constr_folder.png");
case ConstructObject:
- {
- FeaturePtr aFeature = featureDocument()->feature(ModelAPI_Document::CONSTRUCTIONS_GROUP(), theIndex.row());
- if (aFeature)
- return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind()));
- }
+ return QIcon(":pictures/constr_object.png");
+ //{
+ // ObjectPtr aObject = partDocument()->object(ModelAPI_ResultConstruction::group(), theIndex.row());
+ // if (aObject)
+ // return QIcon(XGUI_Workshop::featureIcon(aObject->getKind()));
+ //}
case HistoryObject:
{
- FeaturePtr aFeature = featureDocument()->feature(ModelAPI_Document::FEATURES_GROUP(), theIndex.row() - 3);
+ ObjectPtr aObject = partDocument()->object(ModelAPI_Feature::group(), theIndex.row() - 3);
+ FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
if (aFeature)
return QIcon(XGUI_Workshop::featureIcon(aFeature->getKind()));
}
{
if (!parent.isValid()) {
DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
- if (aRootDoc->feature(ModelAPI_Document::PARTS_GROUP(), myId))
+ if (aRootDoc->object(ModelAPI_ResultPart::group(), myId))
return 1;
else
return 0;
}
switch (parent.internalId()) {
case MyRoot:
- return 3 + featureDocument()->size(ModelAPI_Document::FEATURES_GROUP());
+ return 3 + partDocument()->size(ModelAPI_Feature::group());
case ParamsFolder:
- return featureDocument()->size(ModelAPI_Document::PARAMETERS_GROUP());
+ return partDocument()->size(ModelAPI_ResultParameters::group());
case ConstructFolder:
- return featureDocument()->size(ModelAPI_Document::CONSTRUCTIONS_GROUP());
+ return partDocument()->size(ModelAPI_ResultConstruction::group());
case BodiesFolder:
return 0;
}
}
-DocumentPtr XGUI_PartDataModel::featureDocument() const
+DocumentPtr XGUI_PartDataModel::partDocument() const
{
DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
- FeaturePtr aFeature = aRootDoc->feature(ModelAPI_Document::PARTS_GROUP(), myId, true);
- return aFeature->data()->docRef("PartDocument")->value();
+ ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), myId);
+ return aObject->data()->docRef("PartDocument")->value();
}
-FeaturePtr XGUI_PartDataModel::feature(const QModelIndex& theIndex) const
+ObjectPtr XGUI_PartDataModel::object(const QModelIndex& theIndex) const
{
switch (theIndex.internalId()) {
case MyRoot:
{
DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
- return aRootDoc->feature(ModelAPI_Document::PARTS_GROUP(), myId);
+ return aRootDoc->object(ModelAPI_ResultPart::group(), myId);
}
case ParamsFolder:
case ConstructFolder:
case BodiesFolder:
- return FeaturePtr();
+ return ObjectPtr();
case ParamObject:
- return featureDocument()->feature(ModelAPI_Document::PARAMETERS_GROUP(), theIndex.row());
+ return partDocument()->object(ModelAPI_ResultParameters::group(), theIndex.row());
case ConstructObject:
- return featureDocument()->feature(ModelAPI_Document::CONSTRUCTIONS_GROUP(), theIndex.row());
+ return partDocument()->object(ModelAPI_ResultConstruction::group(), theIndex.row());
//case BodiesObject:
- // return featureDocument()->feature(ModelAPI_Document::CONSTRUCTIONS_GROUP(), theIndex.row());
+ // return partDocument()->feature(ModelAPI_ResultConstruction::group(), theIndex.row());
case HistoryObject:
- return featureDocument()->feature(ModelAPI_Document::FEATURES_GROUP(), theIndex.row() - 3);
+ return partDocument()->object(ModelAPI_Feature::group(), theIndex.row() - 3);
}
- return FeaturePtr();
+ return ObjectPtr();
}
bool XGUI_PartDataModel::hasDocument(const DocumentPtr& theDoc) const
{
- return (featureDocument() == theDoc);
+ return (partDocument() == theDoc);
}
-QModelIndex XGUI_PartDataModel::findParent(const FeaturePtr& theFeature) const
+QModelIndex XGUI_PartDataModel::findParent(const ObjectPtr& theObject) const
{
- return findGroup(theFeature->getGroup().c_str());
+ return findGroup(theObject->groupName().c_str());
}
QModelIndex XGUI_PartDataModel::findGroup(const std::string& theGroup) const
{
- if (theGroup.compare(ModelAPI_Document::PARAMETERS_GROUP()) == 0)
+ if (theGroup.compare(ModelAPI_ResultParameters::group()) == 0)
return createIndex(0, 0, (qint32) ParamsFolder);
- if (theGroup.compare(ModelAPI_Document::CONSTRUCTIONS_GROUP()) == 0)
+ if (theGroup.compare(ModelAPI_ResultConstruction::group()) == 0)
return createIndex(1, 0, (qint32) ConstructFolder);
return QModelIndex();
}
-FeaturePtr XGUI_PartDataModel::part() const
+ResultPartPtr XGUI_PartDataModel::part() const
{
DocumentPtr aRootDoc = ModelAPI_PluginManager::get()->rootDocument();
- return aRootDoc->feature(ModelAPI_Document::PARTS_GROUP(), myId, true);
+ ObjectPtr aObj = aRootDoc->object(ModelAPI_ResultPart::group(), myId);
+ return boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
}
-QModelIndex XGUI_PartDataModel::featureIndex(const FeaturePtr& theFeature) const
+QModelIndex XGUI_PartDataModel::objectIndex(const ObjectPtr& theObject) const
{
QModelIndex aIndex;
- if (theFeature) {
- if (part() == theFeature)
+ if (theObject) {
+ if (part() == theObject)
return aIndex;
//std::string aGroup = theFeature->getGroup();
- DocumentPtr aDoc = theFeature->document();
- int aNb = aDoc->size(ModelAPI_Document::FEATURES_GROUP());
+ DocumentPtr aDoc = theObject->document();
+ int aNb = aDoc->size(ModelAPI_Feature::group());
int aRow = -1;
for (int i = 0; i < aNb; i++) {
- if (aDoc->feature(ModelAPI_Document::FEATURES_GROUP(), i) == theFeature) {
+ if (aDoc->object(ModelAPI_Feature::group(), i) == theObject) {
aRow = i;
break;
}
}
if (aRow != -1) {
return createIndex(aRow + 3, 0, (qint32) HistoryObject);
-/* if (aGroup.compare(PARAMETERS_GROUP) == 0)
+/* if (aGroup.compare(ModelAPI_ResultParameters::group()) == 0)
return createIndex(aRow, 0, (qint32) ParamObject);
- if (aGroup.compare(CONSTRUCTIONS_GROUP) == 0)
+ if (aGroup.compare(ModelAPI_ResultConstruction::group()) == 0)
return createIndex(aRow, 0, (qint32) ConstructObject);*/
}
}
virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
- //! Returns Feature object by the given Model index.
- //! Returns 0 if the given index is not index of a feature
- virtual FeaturePtr feature(const QModelIndex& theIndex) const;
+ //! Returns object by the given Model index.
+ //! Returns 0 if the given index is not index of a object
+ virtual ObjectPtr object(const QModelIndex& theIndex) const;
- //! Returns QModelIndex which corresponds to the given feature
- //! If the feature is not found then index is not valid
- virtual QModelIndex featureIndex(const FeaturePtr& theFeature) const;
+ //! Returns QModelIndex which corresponds to the given object
+ //! If the object is not found then index is not valid
+ virtual QModelIndex objectIndex(const ObjectPtr& theObject) const;
- //! Returns parent index of the given feature
- virtual QModelIndex findParent(const FeaturePtr& theFeature) const;
+ //! Returns parent index of the given object
+ virtual QModelIndex findParent(const ObjectPtr& theObject) const;
//! Returns index corresponded to the group
virtual QModelIndex findGroup(const std::string& theGroup) const;
virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
- //! Returns Feature object by the given Model index.
- //! Returns 0 if the given index is not index of a feature
- virtual FeaturePtr feature(const QModelIndex& theIndex) const;
+ //! Returns object by the given Model index.
+ //! Returns 0 if the given index is not index of a object
+ virtual ObjectPtr object(const QModelIndex& theIndex) const;
- //! Returns QModelIndex which corresponds to the given feature
- //! If the feature is not found then index is not valid
- virtual QModelIndex featureIndex(const FeaturePtr& theFeature) const;
+ //! Returns QModelIndex which corresponds to the given object
+ //! If the object is not found then index is not valid
+ virtual QModelIndex objectIndex(const ObjectPtr& theObject) const;
//! Returns true if the given document is a sub-document of this tree
virtual bool hasDocument(const DocumentPtr& theDoc) const;
- //! Returns parent index of the given feature
- virtual QModelIndex findParent(const FeaturePtr& theFeature) const;
+ //! Returns parent index of the given object
+ virtual QModelIndex findParent(const ObjectPtr& theObject) const;
//! Returns index corresponded to the group
virtual QModelIndex findGroup(const std::string& theGroup) const;
//! Return a Part object
- virtual FeaturePtr part() const;
+ virtual ResultPartPtr part() const;
private:
//! Returns document of the current part
- DocumentPtr featureDocument() const;
+ DocumentPtr partDocument() const;
//! Types of QModelIndexes
enum DataIds {
std::list<ModuleBase_ViewerPrs> XGUI_Selection::getSelected(int theShapeTypeToSkip) const
{
- std::set<FeaturePtr> aPrsFeatures;
+ std::set<ResultPtr> aPrsFeatures;
std::list<ModuleBase_ViewerPrs> aPresentations;
Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
if (theShapeTypeToSkip >= 0 && !aShape.IsNull() && aShape.ShapeType() == theShapeTypeToSkip)
continue;
- FeaturePtr aFeature = myWorkshop->displayer()->getFeature(anIO);
+ ResultPtr aFeature = myWorkshop->displayer()->getResult(anIO);
if (aPrsFeatures.find(aFeature) != aPrsFeatures.end())
continue;
Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
std::list<ModuleBase_ViewerPrs> XGUI_Selection::getHighlighted(int theShapeTypeToSkip) const
{
- std::set<FeaturePtr > aPrsFeatures;
+ std::set<ResultPtr> aPrsFeatures;
std::list<ModuleBase_ViewerPrs> aPresentations;
Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
if (theShapeTypeToSkip >= 0 && !aShape.IsNull() && aShape.ShapeType() == theShapeTypeToSkip)
continue;
- FeaturePtr aFeature = myWorkshop->displayer()->getFeature(anIO);
- if (aPrsFeatures.find(aFeature) != aPrsFeatures.end())
+ ResultPtr aResult = myWorkshop->displayer()->getResult(anIO);
+ if (aPrsFeatures.find(aResult) != aPrsFeatures.end())
continue;
- aPresentations.push_back(ModuleBase_ViewerPrs(aFeature, aShape, NULL));
- aPrsFeatures.insert(aFeature);
+ aPresentations.push_back(ModuleBase_ViewerPrs(aResult, aShape, NULL));
+ aPrsFeatures.insert(aResult);
}
return aPresentations;
}
-QFeatureList XGUI_Selection::selectedFeatures() const
+QList<ObjectPtr> XGUI_Selection::selectedObjects() const
{
- return myWorkshop->objectBrowser()->selectedFeatures();
- //QFeatureList aSelectedList;
-
- //Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
- //for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
- // Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
- // FeaturePtr aFeature = myWorkshop->displayer()->getFeature(anIO);
- // if (aFeature)
- // aSelectedList.append(aFeature);
- //}
- //return aSelectedList;
+ return myWorkshop->objectBrowser()->selectedObjects();
+}
+
+QResultList XGUI_Selection::selectedResults() const
+{
+ QResultList aSelectedList;
+
+ Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
+ for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
+ Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
+ ResultPtr aResult = myWorkshop->displayer()->getResult(anIO);
+ if (aResult)
+ aSelectedList.append(aResult);
+ }
+ return aSelectedList;
}
/// Returns a list of viewer selected presentations
/// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build
/// \return list of presentations
- std::list<ModuleBase_ViewerPrs> getSelected(int theShapeTypeToSkip = -1) const;
+ virtual std::list<ModuleBase_ViewerPrs> getSelected(int theShapeTypeToSkip = -1) const;
/// Returns a list of viewer highlited presentations
/// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build
/// \return list of presentations
- std::list<ModuleBase_ViewerPrs> getHighlighted(int theShapeTypeToSkip = -1) const;
+ virtual std::list<ModuleBase_ViewerPrs> getHighlighted(int theShapeTypeToSkip = -1) const;
/**
- * Returns list of features currently selected in 3d viewer
+ * Returns list of currently selected objects
*/
- QFeatureList selectedFeatures() const;
+ virtual QList<ObjectPtr> selectedObjects() const;
+
+ /**
+ * Returns list of currently selected results
+ */
+ virtual QResultList selectedResults() const;
//! Returns list of currently selected QModelIndexes
- QModelIndexList selectedIndexes() const;
+ virtual QModelIndexList selectedIndexes() const;
//! Returns list of currently selected AIS objects
- void selectedAISObjects(AIS_ListOfInteractive& theList) const;
+ virtual void selectedAISObjects(AIS_ListOfInteractive& theList) const;
//! Returns list of currently selected shapes
- void selectedShapes(NCollection_List<TopoDS_Shape>& theList) const;
+ virtual void selectedShapes(NCollection_List<TopoDS_Shape>& theList) const;
private:
XGUI_Workshop* myWorkshop;
#include <ModelAPI_PluginManager.h>
#include <ModelAPI_AttributeDocRef.h>
#include <ModelAPI_Data.h>
+#include <ModelAPI_Result.h>
+#include <ModelAPI_Object.h>
//**************************************************************
void XGUI_SelectionMgr::onObjectBrowserSelection()
{
- QFeatureList aFeatures = myWorkshop->objectBrowser()->selectedFeatures();
+ QList<ObjectPtr> aObjects = myWorkshop->objectBrowser()->selectedObjects();
+ QResultList aResults;
+ foreach(ObjectPtr aObject, aObjects) {
+ ResultPtr aRes = boost::dynamic_pointer_cast<ModelAPI_Result>(aObject);
+ if (aRes)
+ aResults.append(aRes);
+ }
XGUI_Displayer* aDisplayer = myWorkshop->displayer();
- aDisplayer->setSelected(aFeatures);
+ aDisplayer->setSelected(aResults);
emit selectionChanged();
}
//**************************************************************
void XGUI_SelectionMgr::onViewerSelection()
{
- QFeatureList aFeatures;
+ QList<ObjectPtr> aFeatures;
Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
- FeaturePtr aFeature = myWorkshop->displayer()->getFeature(anIO);
- if (aFeature)
- aFeatures.append(aFeature);
+ ResultPtr aResult = myWorkshop->displayer()->getResult(anIO);
+ if (aResult)
+ aFeatures.append(aResult);
}
- myWorkshop->objectBrowser()->setFeaturesSelected(aFeatures);
+ myWorkshop->objectBrowser()->setObjectsSelected(aFeatures);
emit selectionChanged();
}
XGUI_Selection* selection() const { return mySelection; }
- //! Returns list of currently selected data objects
- //QFeatureList selectedFeatures() const;
-
- //! Returns list of currently selected QModelIndexes
- //QModelIndexList selectedIndexes() const;
-
- //! Returns list of currently selected AIS objects
- //void selectedAISObjects(AIS_ListOfInteractive& theList) const;
-
- //! Returns list of currently selected shapes
- //void selectedShapes(NCollection_List<TopoDS_Shape>& theList) const;
-
//! Connects the manager to all viewers accessible by Workshop
void connectViewers();
#include <TopoDS_Shape.hxx>
#include <ModelAPI_Object.h>
+#include <GeomAPI_Shape.h>
#include <QDir>
}
//******************************************************************
-FeaturePtr realFeature(const FeaturePtr theFeature)
+/*FeaturePtr realFeature(const FeaturePtr theFeature)
{
if (theFeature->data()) {
return theFeature;
ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(theFeature);
return aObject->featureRef();
}
-}
+}*/
+
}
#include <boost/shared_ptr.hpp>
-class TopoDS_Shape;
/*!
\brief Return directory part of the file path.
\param theFeature a feature
*/
std::string XGUI_EXPORT featureInfo(FeaturePtr theFeature);
-
- /**
- * Returns pointer on real feature
- */
- FeaturePtr realFeature(const FeaturePtr theFeature);
}
#endif
#include <ModelAPI_AttributeDocRef.h>
#include <ModelAPI_Object.h>
#include <ModelAPI_Validator.h>
+#include <ModelAPI_ResultPart.h>
#include <PartSetPlugin_Part.h>
aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_LOADED));
// TODO Is it good to use non standard event within workshop?
aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED));
- aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
- aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_CREATED));
- aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_TO_REDISPLAY));
+ aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+ aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+ aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
activateModule();
if (myMainWindow) {
}
// Process creation of Part
- if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_CREATED)) {
- const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
+ if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
+ const Model_ObjectUpdatedMessage* aUpdMsg = dynamic_cast<const Model_ObjectUpdatedMessage*>(theMessage);
onFeatureCreatedMsg(aUpdMsg);
}
// Redisplay feature
- if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_TO_REDISPLAY)) {
- const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
+ if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
+ const Model_ObjectUpdatedMessage* aUpdMsg = dynamic_cast<const Model_ObjectUpdatedMessage*>(theMessage);
onFeatureRedisplayMsg(aUpdMsg);
}
//Update property panel on corresponding message. If there is no current operation (no
//property panel), or received message has different feature to the current - do nothing.
- if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_UPDATED)) {
- const Model_FeatureUpdatedMessage* anUpdateMsg =
- dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
+ if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {
+ const Model_ObjectUpdatedMessage* anUpdateMsg =
+ dynamic_cast<const Model_ObjectUpdatedMessage*>(theMessage);
onFeatureUpdatedMsg(anUpdateMsg);
}
}
//******************************************************
-void XGUI_Workshop::onFeatureUpdatedMsg(const Model_FeatureUpdatedMessage* theMsg)
+void XGUI_Workshop::onFeatureUpdatedMsg(const Model_ObjectUpdatedMessage* theMsg)
{
- std::set<FeaturePtr> aFeatures = theMsg->features();
+ std::set<ObjectPtr> aFeatures = theMsg->features();
if (myOperationMgr->hasOperation())
{
FeaturePtr aCurrentFeature = myOperationMgr->currentOperation()->feature();
- std::set<FeaturePtr>::const_iterator aIt;
+ std::set<ObjectPtr>::const_iterator aIt;
for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
- FeaturePtr aNewFeature = (*aIt);
+ ObjectPtr aNewFeature = (*aIt);
if(aNewFeature == aCurrentFeature) {
myPropertyPanel->updateContentWidget(aCurrentFeature);
break;
}
//******************************************************
-void XGUI_Workshop::onFeatureRedisplayMsg(const Model_FeatureUpdatedMessage* theMsg)
+void XGUI_Workshop::onFeatureRedisplayMsg(const Model_ObjectUpdatedMessage* theMsg)
{
- std::set<FeaturePtr> aFeatures = theMsg->features();
- std::set<FeaturePtr>::const_iterator aIt;
+ std::set<ObjectPtr> aFeatures = theMsg->features();
+ std::set<ObjectPtr>::const_iterator aIt;
bool isDisplayed = false;
for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
- FeaturePtr aFeature = (*aIt);
- if (aFeature->getKind() != PartSetPlugin_Part::ID()) {
- isDisplayed = myDisplayer->redisplay(aFeature, false);
+ ResultPtr aRes = boost::dynamic_pointer_cast<ModelAPI_Result>(*aIt);
+ if (aRes) {
+ isDisplayed = myDisplayer->redisplay(aRes, false);
}
}
if (isDisplayed)
}
//******************************************************
-void XGUI_Workshop::onFeatureCreatedMsg(const Model_FeatureUpdatedMessage* theMsg)
+void XGUI_Workshop::onFeatureCreatedMsg(const Model_ObjectUpdatedMessage* theMsg)
{
- std::set<FeaturePtr> aFeatures = theMsg->features();
+ std::set<ObjectPtr> aFeatures = theMsg->features();
- std::set<FeaturePtr>::const_iterator aIt;
+ std::set<ObjectPtr>::const_iterator aIt;
bool aHasPart = false;
bool isDisplayed = false;
for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
- FeaturePtr aFeature = (*aIt);
- if (aFeature->getKind() == PartSetPlugin_Part::ID()) {
+ ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(*aIt);
+ if (aPart) {
aHasPart = true;
//break;
} else {
- isDisplayed = myDisplayer->display(aFeature, false);
+ ResultPtr aRes = boost::dynamic_pointer_cast<ModelAPI_Result>(*aIt);
+ if (aRes)
+ isDisplayed = myDisplayer->display(aRes, false);
}
}
if (isDisplayed)
}
//******************************************************
-void XGUI_Workshop::changeCurrentDocument(FeaturePtr thePart)
+void XGUI_Workshop::changeCurrentDocument(ObjectPtr theObj)
{
PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
- if (thePart) {
- DocumentPtr aFeaDoc;
- if (!XGUI_Tools::isModelObject(thePart)) {
- aFeaDoc = thePart->data()->docRef("PartDocument")->value();
- } else {
- ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(thePart);
- aFeaDoc = aObject->featureRef()->data()->docRef("PartDocument")->value();
- }
- if (aFeaDoc)
- aMgr->setCurrentDocument(aFeaDoc);
+ if (theObj) {
+ DocumentPtr aPartDoc = theObj->document();
+ if (aPartDoc)
+ aMgr->setCurrentDocument(aPartDoc);
} else {
aMgr->setCurrentDocument(aMgr->rootDocument());
}
//**************************************************************
void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
{
- QFeatureList aFeatures = mySelector->selection()->selectedFeatures();
- if ((theId == "ACTIVATE_PART_CMD") && (aFeatures.size() > 0))
- activatePart(aFeatures.first());
- else if (theId == "DEACTIVATE_PART_CMD")
- activatePart(FeaturePtr());
+ QList<ObjectPtr> aObjects = mySelector->selection()->selectedObjects();
+ if ((theId == "ACTIVATE_PART_CMD") && (aObjects.size() > 0)) {
+ ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aObjects.first());
+ if (aPart)
+ activatePart(aPart);
+ } else if (theId == "DEACTIVATE_PART_CMD")
+ activatePart(ResultPartPtr());
else if (theId == "DELETE_CMD")
- deleteFeatures(aFeatures);
+ deleteObjects(aObjects);
else if (theId == "SHOW_CMD")
- showFeatures(aFeatures, true);
+ showObjects(aObjects, true);
else if (theId == "HIDE_CMD")
- showFeatures(aFeatures, false);
+ showObjects(aObjects, false);
}
//**************************************************************
}
//**************************************************************
-void XGUI_Workshop::activatePart(FeaturePtr theFeature)
+void XGUI_Workshop::activatePart(ResultPartPtr theFeature)
{
changeCurrentDocument(theFeature);
myObjectBrowser->activatePart(theFeature);
{
PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
DocumentPtr aDoc = aMgr->rootDocument();
- FeaturePtr aLastPart = aDoc->feature(ModelAPI_Document::PARTS_GROUP(),
- aDoc->size(ModelAPI_Document::PARTS_GROUP()) - 1, true);
- activatePart(aLastPart);
+ std::string aGrpName = ModelAPI_ResultPart::group();
+ ObjectPtr aLastPart = aDoc->object(aGrpName, aDoc->size(aGrpName) - 1);
+ ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aLastPart);
+ if (aPart)
+ activatePart(aPart);
}
//**************************************************************
-void XGUI_Workshop::deleteFeatures(QFeatureList theList)
+void XGUI_Workshop::deleteObjects(const QList<ObjectPtr>& theList)
{
QMainWindow* aDesktop = isSalomeMode()? salomeConnector()->desktop() : myMainWindow;
QMessageBox::StandardButton aRes = QMessageBox::warning(aDesktop, tr("Delete features"),
tr("Seleted features will be deleted. Continue?"),
QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
- if (aRes == QMessageBox::Yes) {
+ // ToDo: definbe deleting method
+ /* if (aRes == QMessageBox::Yes) {
PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
aMgr->rootDocument()->startOperation();
- foreach (FeaturePtr aFeature, theList) {
- if (aFeature->getKind() == PartSetPlugin_Part::ID()) {
- DocumentPtr aDoc;
- if (!XGUI_Tools::isModelObject(aFeature)) {
- aDoc = aFeature->data()->docRef("PartDocument")->value();
- } else {
- ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
- aDoc = aObject->featureRef()->data()->docRef("PartDocument")->value();
- aFeature = aObject->featureRef();
- }
+ foreach (ObjectPtr aObj, theList) {
+ ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
+ if (aPart) {
+ DocumentPtr aDoc = aPart->document();
if (aDoc == aMgr->currentDocument()) {
aDoc->close();
}
+ aMgr->rootDocument()->removeFeature(aPart->owner());
} else {
- if (XGUI_Tools::isModelObject(aFeature)) {
- ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
- aFeature = aObject->featureRef();
- }
+ aObj->document()->removeFeature(aObj);
}
- if (myDisplayer->isVisible(aFeature))
- myDisplayer->erase(aFeature, false);
- aFeature->document()->removeFeature(aFeature);
}
myDisplayer->updateViewer();
aMgr->rootDocument()->finishOperation();
- }
+ }*/
}
//**************************************************************
-void XGUI_Workshop::showFeatures(QFeatureList theList, bool isVisible)
+void XGUI_Workshop::showObjects(const QList<ObjectPtr>& theList, bool isVisible)
{
- if (isVisible) {
- foreach (FeaturePtr aFeature, theList) {
- myDisplayer->display(aFeature, false);
- }
- } else {
- foreach (FeaturePtr aFeature, theList) {
- myDisplayer->erase(aFeature, false);
+ foreach (ObjectPtr aObj, theList) {
+ ResultPtr aRes = boost::dynamic_pointer_cast<ModelAPI_Result>(aObj);
+ if (aRes) {
+ if (isVisible) {
+ myDisplayer->display(aRes, false);
+ } else {
+ myDisplayer->erase(aRes, false);
+ }
}
}
myDisplayer->updateViewer();
#include "XGUI_Constants.h"
#include <Events_Listener.h>
#include <ModuleBase_Definitions.h>
+#include <ModelAPI_ResultPart.h>
#include <QObject>
#include <QMap>
class QWidget;
class QDockWidget;
-class Model_FeatureUpdatedMessage;
+class Model_ObjectUpdatedMessage;
class QAction;
/**\class XGUI_Workshop
//! Activates or deactivates a part
//! If PartPtr is Null pointer then PartSet will be activated
- void activatePart(FeaturePtr theFeature);
+ void activatePart(ResultPartPtr theFeature);
//! Delete features
- void deleteFeatures(QFeatureList theList);
+ void deleteObjects(const QList<ObjectPtr>& theList);
//! Show the given features in 3d Viewer
- void showFeatures(QFeatureList theList, bool isVisible);
+ void showObjects(const QList<ObjectPtr>& theList, bool isVisible);
ModuleBase_IModule* module() const { return myModule; }
void hideObjectBrowser();
void onFeatureTriggered();
- void changeCurrentDocument(FeaturePtr thePart);
+ void changeCurrentDocument(ObjectPtr theObj);
void activateLastPart();
void connectWithOperation(ModuleBase_Operation* theOperation);
void saveDocument(QString theName);
- void onFeatureUpdatedMsg(const Model_FeatureUpdatedMessage* theMsg);
- void onFeatureCreatedMsg(const Model_FeatureUpdatedMessage* theMsg);
- void onFeatureRedisplayMsg(const Model_FeatureUpdatedMessage* theMsg);
+ void onFeatureUpdatedMsg(const Model_ObjectUpdatedMessage* theMsg);
+ void onFeatureCreatedMsg(const Model_ObjectUpdatedMessage* theMsg);
+ void onFeatureRedisplayMsg(const Model_ObjectUpdatedMessage* theMsg);
QList<QAction*> getModuleCommands() const;
<file>pictures/params_folder.png</file>
<file>pictures/constr_folder.png</file>
+ <file>pictures/constr_object.png</file>
<file>pictures/part_ico.png</file>
<file>pictures/properties.png</file>
<file>pictures/features.png</file>