Model_ResultField::~Model_ResultField()
{
while(mySteps.size() > 0) {
- delete mySteps.back();
+ //delete mySteps.back();
mySteps.pop_back();
}
}
int aNbSteps = stepsSize();
if (mySteps.size() != aNbSteps) {
while(mySteps.size() > aNbSteps) {
- delete mySteps.back();
+ //delete mySteps.back();
mySteps.pop_back();
}
while(mySteps.size() < aNbSteps) {
- mySteps.push_back(new Model_ResultField::Model_FieldStep(this, int(mySteps.size())));
+ mySteps.push_back(FieldStepPtr(new Model_ResultField::Model_FieldStep(this, int(mySteps.size()))));
}
}
}
// used by GUI only
// LCOV_EXCL_START
-ModelAPI_ResultField::ModelAPI_FieldStep* Model_ResultField::step(int theId) const
+std::shared_ptr<ModelAPI_ResultField::ModelAPI_FieldStep> Model_ResultField::step(int theId) const
{
if (theId < mySteps.size()) {
return mySteps[theId];
{
public:
Model_FieldStep(ModelAPI_ResultField* theParent, int theId)
- : myParent(theParent), myId(theId) {};
+ : ModelAPI_ResultField::ModelAPI_FieldStep(), myParent(theParent), myId(theId) {};
virtual ModelAPI_ResultField* field() const { return myParent; }
virtual int id() const { return myId; }
+ virtual std::shared_ptr<ModelAPI_Document> document() const { return myParent->document(); }
+
private:
ModelAPI_ResultField* myParent;
int myId;
/// Returns step object
/// \param theId an id of the object
- MODEL_EXPORT virtual ModelAPI_ResultField::ModelAPI_FieldStep* step(int theId) const;
+ MODEL_EXPORT virtual std::shared_ptr<ModelAPI_ResultField::ModelAPI_FieldStep> step(int theId) const;
/// Removes the stored builders
MODEL_EXPORT virtual ~Model_ResultField();
private:
void updateSteps();
- std::vector<ModelAPI_FieldStep*> mySteps;
+ std::vector<FieldStepPtr> mySteps;
};
#endif
//
#include "ModelAPI_ResultField.h"
+#include "ModelAPI_Events.h"
+#include <Events_Loop.h>
ModelAPI_ResultField::~ModelAPI_ResultField()
{
{
return group();
}
+
+void ModelAPI_ResultField::ModelAPI_FieldStep::setDisplayed(const bool theDisplay)
+{
+ myIsDisplayed = theDisplay;
+ //static Events_Loop* aLoop = Events_Loop::loop();
+ //static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+ //static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
+ //aECreator->sendUpdated(FieldStepPtr(this), EVENT_DISP);
+}
{
public:
- class ModelAPI_FieldStep : public ModelAPI_Entity
+ class ModelAPI_FieldStep : public ModelAPI_Object
{
public:
virtual ModelAPI_ResultField* field() const = 0;
virtual int id() const = 0;
+
+ /// Returns the group identifier of this result
+ inline static std::string group()
+ {
+ static std::string MY_GROUP = "FieldRersultStep";
+ return MY_GROUP;
+ }
+
+ /// Returns the group identifier of this object
+ virtual std::string groupName() { return group(); }
+
+ /// Request for initialization of data model of the object: adding all attributes
+ virtual void initAttributes() {}
+
+ /// Returns the feature is disabled or not.
+ virtual bool isDisabled() { return false; }
+
+ /// Returns true if object must be displayed in the viewer: flag is stored in the
+ /// data model, so on undo/redo, open/save or recreation of object by history-playing it keeps
+ /// the original state in the current transaction.
+ virtual bool isDisplayed() { return myIsDisplayed; }
+
+ /// Sets the displayed/hidden state of the object. If it is changed, sends the "redisplay"
+ /// signal.
+ MODELAPI_EXPORT virtual void setDisplayed(const bool theDisplay);
+
+ protected:
+ /// This method is called just after creation of the object: it must initialize
+ /// all fields, normally initialized in the constructor
+ MODELAPI_EXPORT virtual void init() {}
+
+ private:
+ bool myIsDisplayed;
};
MODELAPI_EXPORT virtual ~ModelAPI_ResultField();
/// Returns step object
/// \param theId an id of the object
- virtual ModelAPI_FieldStep* step(int theId) const = 0;
+ virtual std::shared_ptr<ModelAPI_ResultField::ModelAPI_FieldStep> step(int theId) const = 0;
};
//! Pointer on feature object
}
}
else if (aFieldRes.get()) {
- ModelAPI_ResultField::ModelAPI_FieldStep* aStep = aFieldRes->step(i);
+ FieldStepPtr aStep = aFieldRes->step(i);
if (i < myChildren.size()) {
PartSet_StepNode* aStepNode = static_cast<PartSet_StepNode*>(myChildren.at(i));
- if (aStepNode->entity() != aStep) {
- aStepNode->setEntity(aStep);
+ if (aStepNode->object() != aStep) {
+ aStepNode->setObject(aStep);
}
}
else {
}
}
else {
- ModelAPI_ResultField::ModelAPI_FieldStep* aStep = aFieldRes->step(i);
+ FieldStepPtr aStep = aFieldRes->step(i);
if (i < myChildren.size()) {
PartSet_StepNode* aStepNode = static_cast<PartSet_StepNode*>(myChildren.at(i));
- if (aStepNode->entity() != aStep) {
- aStepNode->setEntity(aStep);
+ if (aStepNode->object() != aStep) {
+ aStepNode->setObject(aStep);
}
}
else {
QVariant PartSet_StepNode::data(int theColumn, int theRole) const
{
if ((theColumn == 1) && (theRole == Qt::DisplayRole)) {
- ModelAPI_ResultField::ModelAPI_FieldStep* aStep =
- dynamic_cast<ModelAPI_ResultField::ModelAPI_FieldStep*>(myEntity);
+ FieldStepPtr aStep =
+ std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(myObject);
return "Step " + QString::number(aStep->id() + 1) + " " +
aStep->field()->textLine(aStep->id()).c_str();
}
- return PartSet_TreeNode::data(theColumn, theRole);
+ return PartSet_ObjectNode::data(theColumn, theRole);
+}
+
+ModuleBase_ITreeNode::VisibilityState PartSet_StepNode::visibilityState() const
+{
+ Qt::ItemFlags aFlags = flags(1);
+ if (aFlags == Qt::ItemFlags())
+ return NoneState;
+
+ ModuleBase_IWorkshop* aWork = workshop();
+ if (aWork->isVisible(myObject))
+ return Visible;
+ else
+ return Hidden;
}
* \ingroup Modules
* Implementation of a node for compsolid representation
*/
-class PartSet_StepNode : public PartSet_TreeNode
+class PartSet_StepNode : public PartSet_ObjectNode
{
public:
- PartSet_StepNode(ModelAPI_Entity* theEnt, ModuleBase_ITreeNode* theParent) :
- PartSet_TreeNode(theParent), myEntity(theEnt) {}
+ PartSet_StepNode(const ObjectPtr& theObj, ModuleBase_ITreeNode* theParent) :
+ PartSet_ObjectNode(theObj, theParent) {}
static std::string typeId()
{
/// Returns the node representation according to theRole.
virtual QVariant data(int theColumn, int theRole) const;
- ModelAPI_Entity* entity() const {
- return myEntity;
- }
-
- void setEntity(ModelAPI_Entity* theEnt) {
- myEntity = theEnt;
- }
-
-private:
- ModelAPI_Entity* myEntity;
+ virtual VisibilityState visibilityState() const;
};
#endif
#include <ModelAPI_Session.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_Tools.h>
+#include <ModelAPI_ResultField.h>
#include <ModuleBase_Tools.h>
#include <ModuleBase_ITreeNode.h>
Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
update(theIndex);
}
+ else {
+ FieldStepPtr aStep =
+ std::dynamic_pointer_cast<ModelAPI_ResultField::ModelAPI_FieldStep>(aObj);
+ if (aStep.get()) {
+ // Only one step from a field can be visible at once
+ int aId = aStep->id();
+ ModelAPI_ResultField* aField = aStep->field();
+ aField->setDisplayed(false);
+ for (int i = 0; i < aField->stepsSize(); i++) {
+ aField->step(i)->setDisplayed(i == aId);
+ static Events_Loop* aLoop = Events_Loop::loop();
+ static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+ static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
+ aECreator->sendUpdated(aField->step(i), EVENT_DISP);
+ }
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+ }
+ }
// Update list of selected objects because this event happens after
// selection event in object browser
if (aObjBrowser) {