// Author: Mikhail PONIKAROV
#include <Model_ResultField.h>
-#include <ModelAPI_AttributeSelectionList.h>
#include <Model_Document.h>
+
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_Feature.h>
+#include <ModelAPI_AttributeIntArray.h>
+#include <ModelAPI_AttributeSelectionList.h>
#include <GeomAlgoAPI_CompoundBuilder.h>
myOwnerData = theOwnerData;
}
+Model_ResultField::~Model_ResultField()
+{
+ while(mySteps.size() > 0) {
+ delete mySteps.back();
+ mySteps.pop_back();
+ }
+}
+
void Model_ResultField::colorConfigInfo(std::string& theSection, std::string& theName,
std::string& theDefault)
{
aResult = GeomAlgoAPI_CompoundBuilder::compound(aSubs);
}
}
+ updateSteps();
}
return aResult;
}
+
+void Model_ResultField::updateSteps()
+{
+ // Update Array of steps
+ int aNbSteps = stepsSize();
+ if (mySteps.size() != aNbSteps) {
+ while(mySteps.size() > aNbSteps) {
+ delete mySteps.back();
+ mySteps.pop_back();
+ }
+ while(mySteps.size() < aNbSteps) {
+ mySteps.push_back(new Model_ResultField::Model_FieldStep(this, mySteps.size()));
+ }
+ }
+}
+
+int Model_ResultField::stepsSize() const
+{
+ if (myOwnerData) {
+ AttributeIntArrayPtr aArray = myOwnerData->intArray("stamps");
+ if (aArray.get()) {
+ return aArray->size();
+ }
+ }
+ return 0;
+}
+
+std::string Model_ResultField::textLine(int theLine) const
+{
+ if (myOwnerData) {
+ AttributeIntArrayPtr aArray = myOwnerData->intArray("stamps");
+ if (aArray.get()) {
+ if (theLine < aArray->size()) {
+ std::ostringstream aStream;
+ aStream << aArray->value(theLine);
+ return aStream.str();
+ }
+ }
+ }
+ return "";
+}
+
+
+ModelAPI_ResultField::ModelAPI_FieldStep* Model_ResultField::step(int theId) const
+{
+ if (theId < mySteps.size()) {
+ return mySteps[theId];
+ }
+ return NULL;
+}
#include "Model.h"
#include <ModelAPI_ResultField.h>
+#include <vector>
/**\class Model_ResultField
* \ingroup DataModel
std::shared_ptr<ModelAPI_Data> myOwnerData; ///< data of owner of this result
public:
+ class Model_FieldStep : public ModelAPI_ResultField::ModelAPI_FieldStep
+ {
+ public:
+ Model_FieldStep(ModelAPI_ResultField* theParent, int theId)
+ : myParent(theParent), myId(theId) {};
+
+ virtual ModelAPI_ResultField* field() const { return myParent; }
+
+ virtual int id() const { return myId; }
+
+ private:
+ ModelAPI_ResultField* myParent;
+ int myId;
+ };
+
/// Retuns the parameters of color definition in the resources config manager
MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName,
std::string& theDefault);
/// Returns the compound of selected entities
MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Shape> shape();
+ /// Returns number of steps
+ MODEL_EXPORT virtual int stepsSize() const;
+
+ /// Returns a text line by its number
+ /// \param theLine a number of line
+ MODEL_EXPORT virtual std::string textLine(int theLine) const;
+
+ /// Returns step object
+ /// \param theId an id of the object
+ MODEL_EXPORT virtual ModelAPI_ResultField::ModelAPI_FieldStep* step(int theId) const;
+
/// Removes the stored builders
- MODEL_EXPORT virtual ~Model_ResultField() {}
+ MODEL_EXPORT virtual ~Model_ResultField();
protected:
/// Makes a body on the given feature data
Model_ResultField(std::shared_ptr<ModelAPI_Data> theOwnerData);
friend class Model_Objects;
+
+private:
+ void updateSteps();
+
+ std::vector<ModelAPI_FieldStep*> mySteps;
};
#endif
#include <ModelAPI_Feature.h>
#include <ModelAPI_CompositeFeature.h>
#include <ModelAPI_ResultCompSolid.h>
+#include <ModelAPI_ResultField.h>
#include <ModelAPI_Tools.h>
#include <Config_FeatureMessage.h>
#define SELECTABLE_COLOR QColor(80, 80, 80)
#define DISABLED_COLOR QColor(200, 200, 200)
+
ResultPartPtr getPartResult(ModelAPI_Object* theObj)
{
ModelAPI_Feature* aFeature = dynamic_cast<ModelAPI_Feature*>(theObj);
for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
ObjectPtr aObject = (*aIt);
if (aObject->data()->isValid()) {
- QModelIndex aIndex = objectIndex(aObject);
- if (aIndex.isValid()) {
- emit dataChanged(aIndex, aIndex);
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObject);
+ if (aFeature.get() && aFeature->firstResult().get()
+ && (aFeature->firstResult()->groupName() == ModelAPI_ResultField::group())) {
+ ResultFieldPtr aResult =
+ std::dynamic_pointer_cast<ModelAPI_ResultField>(aFeature->firstResult());
+ QModelIndex aIndex = objectIndex(aResult);
+ removeRows(0, aResult->stepsSize(), aIndex);
+ } else {
+ QModelIndex aIndex = objectIndex(aObject);
+ if (aIndex.isValid()) {
+ emit dataChanged(aIndex, aIndex);
+ }
}
} else {
rebuildDataTree();
{
if (theIndex.internalId() == 0) // this is a folder
return ObjectPtr();
- ModelAPI_Object* aObj = (ModelAPI_Object*)theIndex.internalPointer();
+ ModelAPI_Object* aObj =
+ dynamic_cast<ModelAPI_Object*>((ModelAPI_Entity*)theIndex.internalPointer());
+ if (!aObj)
+ return ObjectPtr();
if (getSubDocument(aObj)) // the selected index is a folder of sub-document
return ObjectPtr();
}
}
} else {
- ModelAPI_Object* aObj = (ModelAPI_Object*)theIndex.internalPointer();
- switch (theRole) {
- case Qt::DisplayRole:
- {
- if (aObj->groupName() == ModelAPI_ResultParameter::group()) {
- ModelAPI_ResultParameter* aParam = dynamic_cast<ModelAPI_ResultParameter*>(aObj);
- AttributeDoublePtr aValueAttribute =
- aParam->data()->real(ModelAPI_ResultParameter::VALUE());
- QString aVal = QString::number(aValueAttribute->value());
- QString aTitle = QString(aObj->data()->name().c_str());
- return aTitle + " = " + aVal;
+ ModelAPI_Object* aObj =
+ dynamic_cast<ModelAPI_Object*>((ModelAPI_Entity*)theIndex.internalPointer());
+ if (aObj) {
+ switch (theRole) {
+ case Qt::DisplayRole:
+ {
+ if (aObj->groupName() == ModelAPI_ResultParameter::group()) {
+ ModelAPI_ResultParameter* aParam = dynamic_cast<ModelAPI_ResultParameter*>(aObj);
+ AttributeDoublePtr aValueAttribute =
+ aParam->data()->real(ModelAPI_ResultParameter::VALUE());
+ QString aVal = QString::number(aValueAttribute->value());
+ QString aTitle = QString(aObj->data()->name().c_str());
+ return aTitle + " = " + aVal;
+ }
+ QString aSuffix;
+ if (aObj->groupName() == myXMLReader->subType()) {
+ ResultPartPtr aPartRes = getPartResult(aObj);
+ if (aPartRes.get()) {
+ if (aPartRes->partDoc().get() == NULL)
+ aSuffix = " (Not loaded)";
+ }
+ }
+ return aObj->data()->name().c_str() + aSuffix;
}
- QString aSuffix;
- if (aObj->groupName() == myXMLReader->subType()) {
- ResultPartPtr aPartRes = getPartResult(aObj);
- if (aPartRes.get()) {
- if (aPartRes->partDoc().get() == NULL)
- aSuffix = " (Not loaded)";
+ case Qt::DecorationRole:
+ return ModuleBase_IconFactory::get()->getIcon(object(theIndex));
+ }
+ } else {
+ switch (theRole) {
+ case Qt::DisplayRole:
+ {
+ ModelAPI_ResultField::ModelAPI_FieldStep* aStep =
+ dynamic_cast<ModelAPI_ResultField::ModelAPI_FieldStep*>
+ ((ModelAPI_Entity*)theIndex.internalPointer());
+ if (aStep) {
+ return "Step " + QString::number(aStep->id()) + " " +
+ aStep->field()->textLine(aStep->id()).c_str();
}
}
- return aObj->data()->name().c_str() + aSuffix;
+ break;
}
- case Qt::DecorationRole:
- return ModuleBase_IconFactory::get()->getIcon(object(theIndex));
}
}
}
return aDoc->size(aType);
}
} else {
- ModelAPI_Object* aObj = (ModelAPI_Object*)theParent.internalPointer();
+ ModelAPI_Object* aObj =
+ dynamic_cast<ModelAPI_Object*>((ModelAPI_Entity*)theParent.internalPointer());
// Check for Part feature
ResultPartPtr aPartRes = getPartResult(aObj);
if (aPartRes.get()) {
ModelAPI_ResultCompSolid* aCompRes = dynamic_cast<ModelAPI_ResultCompSolid*>(aObj);
if (aCompRes)
return aCompRes->numberOfSubs(true);
+ ModelAPI_ResultField* aFieldRes = dynamic_cast<ModelAPI_ResultField*>(aObj);
+ if (aFieldRes)
+ return aFieldRes->stepsSize();
}
}
}
}
}
} else {
- ModelAPI_Object* aParentObj = (ModelAPI_Object*)theParent.internalPointer();
+ ModelAPI_Object* aParentObj =
+ dynamic_cast<ModelAPI_Object*>((ModelAPI_Entity*)theParent.internalPointer());
// Check for Part feature
ResultPartPtr aPartRes = getPartResult(aParentObj);
dynamic_cast<ModelAPI_ResultCompSolid*>(aParentObj);
if (aCompRes)
aIndex = objectIndex(aCompRes->subResult(theRow));
+ else {
+ ModelAPI_ResultField* aFieldRes =
+ dynamic_cast<ModelAPI_ResultField*>(aParentObj);
+ if (aFieldRes) {
+ aIndex = createIndex(theRow, 0, aFieldRes->step(theRow));
+ }
+ }
}
}
}
if (theIndex == MYLastDeleted)
return QModelIndex();
+ SessionPtr aSession = ModelAPI_Session::get();
quintptr aId = theIndex.internalId();
if (aId != 0) { // The object is not a root folder
ModelAPI_Document* aDoc = getSubDocument(theIndex.internalPointer());
}
ObjectPtr aObj = object(theIndex);
if (!aObj.get()) {
+ // It can b e a step of a field
+ ModelAPI_ResultField::ModelAPI_FieldStep* aStep =
+ dynamic_cast<ModelAPI_ResultField::ModelAPI_FieldStep*>
+ ((ModelAPI_Entity*)theIndex.internalPointer());
+ if (aStep) {
+ ModelAPI_ResultField* aField = aStep->field();
+ DocumentPtr aDoc = aSession->activeDocument();
+ ObjectPtr aFld;
+ for(int i = 0; i < aDoc->size(ModelAPI_ResultField::group()); i++) {
+ aFld = aDoc->object(ModelAPI_ResultField::group(), i);
+ if (aFld.get() == aField)
+ return objectIndex(aFld);
+ }
+ }
// To avoid additional request about index which was already deleted
// If deleted it causes a crash on delete object from Part
MYLastDeleted = theIndex;
}
// Use as ordinary object
std::string aType = aObj->groupName();
- SessionPtr aSession = ModelAPI_Session::get();
DocumentPtr aRootDoc = aSession->moduleDocument();
DocumentPtr aSubDoc = aObj->document();
if (aSubDoc == aRootDoc) {
} else {
aDoc = getSubDocument(theIndex.internalPointer());
if (!aDoc)
- aObj = (ModelAPI_Object*) theIndex.internalPointer();
+ aObj = dynamic_cast<ModelAPI_Object*>((ModelAPI_Entity*)theIndex.internalPointer());
}
if (aObj) {