From 0a261c1d5c56df650e2339b7281ede02bb4f57c0 Mon Sep 17 00:00:00 2001 From: sbh Date: Fri, 3 Apr 2015 20:11:09 +0300 Subject: [PATCH] Result for parameters added --- src/Model/CMakeLists.txt | 2 ++ src/Model/Model_Document.cpp | 18 +++++++++++ src/Model/Model_Document.h | 4 +++ src/Model/Model_ResultParameter.cpp | 32 +++++++++++++++++++ src/Model/Model_ResultParameter.h | 24 ++++++++++++++ src/ModelAPI/CMakeLists.txt | 2 +- src/ModelAPI/ModelAPI.i | 6 ++-- src/ModelAPI/ModelAPI_Document.h | 4 +++ ...arameters.h => ModelAPI_ResultParameter.h} | 18 +++++++---- src/XGUI/XGUI_PartDataModel.cpp | 22 ++++++------- 10 files changed, 111 insertions(+), 21 deletions(-) create mode 100644 src/Model/Model_ResultParameter.cpp create mode 100644 src/Model/Model_ResultParameter.h rename src/ModelAPI/{ModelAPI_ResultParameters.h => ModelAPI_ResultParameter.h} (63%) diff --git a/src/Model/CMakeLists.txt b/src/Model/CMakeLists.txt index ef4c82c12..eef87c35f 100644 --- a/src/Model/CMakeLists.txt +++ b/src/Model/CMakeLists.txt @@ -26,6 +26,7 @@ SET(PROJECT_HEADERS Model_ResultConstruction.h Model_ResultPart.h Model_ResultGroup.h + Model_ResultParameter.h Model_FeatureValidator.h ) @@ -52,6 +53,7 @@ SET(PROJECT_SOURCES Model_ResultConstruction.cpp Model_ResultPart.cpp Model_ResultGroup.cpp + Model_ResultParameter.cpp Model_FeatureValidator.cpp ) diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index 754138db9..0f335a530 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -15,6 +15,7 @@ #include #include #include + #include #include @@ -1222,6 +1223,23 @@ std::shared_ptr Model_Document::createGroup( return aResult; } +std::shared_ptr Model_Document::createParameter( + const std::shared_ptr& theFeatureData, const int theIndex) +{ + TDF_Label aLab = resultLabel(theFeatureData, theIndex); + TDataStd_Comment::Set(aLab, ModelAPI_ResultParameter::group().c_str()); + ObjectPtr anOldObject = object(aLab); + std::shared_ptr aResult; + if (anOldObject) { + aResult = std::dynamic_pointer_cast(anOldObject); + } + if (!aResult) { + aResult = std::shared_ptr(new ModelAPI_ResultParameter); + storeResult(theFeatureData, aResult, theIndex); + } + return aResult; +} + std::shared_ptr Model_Document::feature( const std::shared_ptr& theResult) { diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index 59631304e..453422ffc 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -142,6 +143,9 @@ class Model_Document : public ModelAPI_Document MODEL_EXPORT virtual std::shared_ptr createGroup( const std::shared_ptr& theFeatureData, const int theIndex = 0); + MODEL_EXPORT virtual std::shared_ptr createParameter( + const std::shared_ptr& theFeatureData, const int theIndex = 0); + //! Returns a feature by result (owner of result) MODEL_EXPORT virtual std::shared_ptr feature(const std::shared_ptr& theResult); diff --git a/src/Model/Model_ResultParameter.cpp b/src/Model/Model_ResultParameter.cpp new file mode 100644 index 000000000..641155b1e --- /dev/null +++ b/src/Model/Model_ResultParameter.cpp @@ -0,0 +1,32 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: Model_ResultParameter.h +// Created: 02 Apr 2015 +// Author: Sergey BELASH + +#ifndef MODEL_RESULTPARAMETER_H_ +#define MODEL_RESULTPARAMETER_H_ + +#include "Model.h" +#include + +#include +#include + +/**\class Model_ResultParameter + * \ingroup DataModel + * \brief + */ +class Model_ResultParameter : public ModelAPI_ResultParameter +{ + public: + MODEL_EXPORT virtual ~Model_ResultParameter(); + MODEL_EXPORT virtual void initAttributes(); + + protected: + Model_ResultParameter(); + + friend class Model_Document; +}; + +#endif diff --git a/src/Model/Model_ResultParameter.h b/src/Model/Model_ResultParameter.h new file mode 100644 index 000000000..08c3e2db7 --- /dev/null +++ b/src/Model/Model_ResultParameter.h @@ -0,0 +1,24 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: Model_ResultParameter.cpp +// Created: 02 Apr 2015 +// Author: Sergey BELASH + +#include "Model_ResultParameter.h" + +Model_ResultParameter::~Model_ResultParameter() +{ + +} + +void Model_ResultParameter::initAttributes() +{ + data()->addAttribute(ModelAPI_ResultParameter::VALUE(), + ModelAPI_AttributeDouble::typeId()); +} + + +Model_ResultParameter::Model_ResultParameter() +{ + setIsConcealed(false); +} diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index d20cb1d05..8d1dc9d98 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -32,7 +32,7 @@ SET(PROJECT_HEADERS ModelAPI_ResultBody.h ModelAPI_ResultConstruction.h ModelAPI_ResultGroup.h - ModelAPI_ResultParameters.h + ModelAPI_ResultParameter.h ModelAPI_ResultPart.h ModelAPI_Session.h ModelAPI_Tools.h diff --git a/src/ModelAPI/ModelAPI.i b/src/ModelAPI/ModelAPI.i index bd8cc724a..0c23dc012 100644 --- a/src/ModelAPI/ModelAPI.i +++ b/src/ModelAPI/ModelAPI.i @@ -35,7 +35,7 @@ #include "ModelAPI_ResultConstruction.h" #include "ModelAPI_ResultBody.h" #include "ModelAPI_ResultPart.h" - #include "ModelAPI_ResultParameters.h" + #include "ModelAPI_ResultParameter.h" #include "ModelAPI_ResultGroup.h" #include "ModelAPI_Tools.h" @@ -95,7 +95,7 @@ %shared_ptr(ModelAPI_ResultBody) %shared_ptr(ModelAPI_ResultPart) %shared_ptr(ModelAPI_ResultGroup) -%shared_ptr(ModelAPI_ResultParameters) +%shared_ptr(ModelAPI_ResultParameter) // all supported interfaces %include "ModelAPI_Document.h" @@ -124,7 +124,7 @@ %include "ModelAPI_ResultBody.h" %include "ModelAPI_ResultPart.h" %include "ModelAPI_ResultGroup.h" -%include "ModelAPI_ResultParameters.h" +%include "ModelAPI_ResultParameter.h" %include "ModelAPI_Tools.h" // std::list -> [] diff --git a/src/ModelAPI/ModelAPI_Document.h b/src/ModelAPI/ModelAPI_Document.h index cbb1d5b01..8093123bd 100644 --- a/src/ModelAPI/ModelAPI_Document.h +++ b/src/ModelAPI/ModelAPI_Document.h @@ -21,6 +21,7 @@ class ModelAPI_ResultConstruction; class ModelAPI_ResultBody; class ModelAPI_ResultPart; class ModelAPI_ResultGroup; +class ModelAPI_ResultParameter; class ModelAPI_Data; /**\class ModelAPI_Document @@ -98,6 +99,9 @@ public: virtual std::shared_ptr createGroup( const std::shared_ptr& theFeatureData, const int theIndex = 0) = 0; + virtual std::shared_ptr createParameter( + const std::shared_ptr& theFeatureData, const int theIndex = 0) = 0; + //! Returns a feature by result (owner of result) virtual std::shared_ptr feature( const std::shared_ptr& theResult) = 0; diff --git a/src/ModelAPI/ModelAPI_ResultParameters.h b/src/ModelAPI/ModelAPI_ResultParameter.h similarity index 63% rename from src/ModelAPI/ModelAPI_ResultParameters.h rename to src/ModelAPI/ModelAPI_ResultParameter.h index aae2a15ed..9d877376f 100644 --- a/src/ModelAPI/ModelAPI_ResultParameters.h +++ b/src/ModelAPI/ModelAPI_ResultParameter.h @@ -1,22 +1,22 @@ // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -// File: ModelAPI_ResultParameters.h +// File: ModelAPI_ResultParameter.h // Created: 07 Jul 2014 // Author: Vitaly SMETANNIKOV -#ifndef MODELAPI_RESULTPARAMETERS_H_ -#define MODELAPI_RESULTPARAMETERS_H_ +#ifndef MODELAPI_RESULTPARAMETER_H_ +#define MODELAPI_RESULTPARAMETER_H_ #include "ModelAPI_Result.h" -/**\class ModelAPI_ResultParameters +/**\class ModelAPI_ResultParameter * \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 +class ModelAPI_ResultParameter : public ModelAPI_Result { public: /// Returns the group identifier of this result @@ -31,9 +31,15 @@ class ModelAPI_ResultParameters : public ModelAPI_Result static std::string MY_GROUP = "Parameters"; return MY_GROUP; } + + inline static const std::string& VALUE() + { + static const std::string MY_VALUE_ID("Value"); + return MY_VALUE_ID; + } }; //! Pointer on feature object -typedef std::shared_ptr ResultParametersPtr; +typedef std::shared_ptr ResultParameterPtr; #endif diff --git a/src/XGUI/XGUI_PartDataModel.cpp b/src/XGUI/XGUI_PartDataModel.cpp index 567ad5677..3faa7bd6d 100644 --- a/src/XGUI/XGUI_PartDataModel.cpp +++ b/src/XGUI/XGUI_PartDataModel.cpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include @@ -46,7 +46,7 @@ QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const return tr("Parameters") + QString(" (%1)").arg(rowCount(theIndex)); case ParamObject: { DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultParameters::group(), theIndex.row()); + ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultParameter::group(), theIndex.row()); if (aObject) return aObject->data()->name().c_str(); } @@ -112,7 +112,7 @@ int XGUI_TopDataModel::rowCount(const QModelIndex& theParent) const DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); if (theParent.internalId() == ParamsFolder) - return aRootDoc->size(ModelAPI_ResultParameters::group()); + return aRootDoc->size(ModelAPI_ResultParameter::group()); if (theParent.internalId() == ConstructFolder) return aRootDoc->size(ModelAPI_ResultConstruction::group()); @@ -183,7 +183,7 @@ ObjectPtr XGUI_TopDataModel::object(const QModelIndex& theIndex) const return ObjectPtr(); case ParamObject: { DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); - return aRootDoc->object(ModelAPI_ResultParameters::group(), theIndex.row()); + return aRootDoc->object(ModelAPI_ResultParameter::group(), theIndex.row()); } case ConstructObject: { DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); @@ -204,7 +204,7 @@ QModelIndex XGUI_TopDataModel::findParent(const ObjectPtr& theObject) const QModelIndex XGUI_TopDataModel::findGroup(const std::string& theGroup) const { - if (theGroup == ModelAPI_ResultParameters::group()) + if (theGroup == ModelAPI_ResultParameter::group()) return createIndex(0, 0, (qint32) ParamsFolder); if (theGroup == ModelAPI_ResultConstruction::group()) return createIndex(1, 0, (qint32) ConstructFolder); @@ -228,7 +228,7 @@ QModelIndex XGUI_TopDataModel::objectIndex(const ObjectPtr& theObject) const } } if (aRow != -1) { - if (aGroup == ModelAPI_ResultParameters::group()) + if (aGroup == ModelAPI_ResultParameter::group()) return createIndex(aRow, 0, (qint32) ParamObject); if (aGroup == ModelAPI_ResultConstruction::group()) return createIndex(aRow, 0, (qint32) ConstructObject); @@ -272,7 +272,7 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons case GroupsFolder: return tr("Groups") + QString(" (%1)").arg(rowCount(theIndex)); case ParamObject: { - ObjectPtr aObject = partDocument()->object(ModelAPI_ResultParameters::group(), + ObjectPtr aObject = partDocument()->object(ModelAPI_ResultParameter::group(), theIndex.row()); if (aObject) return std::dynamic_pointer_cast(aObject)->data()->name().c_str(); @@ -369,7 +369,7 @@ int XGUI_PartDataModel::rowCount(const QModelIndex& parent) const return 0; } case ParamsFolder: - return partDocument()->size(ModelAPI_ResultParameters::group()); + return partDocument()->size(ModelAPI_ResultParameter::group()); case ConstructFolder: return partDocument()->size(ModelAPI_ResultConstruction::group()); case BodiesFolder: @@ -476,7 +476,7 @@ ObjectPtr XGUI_PartDataModel::object(const QModelIndex& theIndex) const return ObjectPtr(); case ParamObject: - return partDocument()->object(ModelAPI_ResultParameters::group(), theIndex.row()); + return partDocument()->object(ModelAPI_ResultParameter::group(), theIndex.row()); case ConstructObject: return partDocument()->object(ModelAPI_ResultConstruction::group(), theIndex.row()); case BodiesObject: @@ -501,7 +501,7 @@ QModelIndex XGUI_PartDataModel::findParent(const ObjectPtr& theObject) const QModelIndex XGUI_PartDataModel::findGroup(const std::string& theGroup) const { - if (theGroup == ModelAPI_ResultParameters::group()) + if (theGroup == ModelAPI_ResultParameter::group()) return createIndex(0, 0, (qint32) ParamsFolder); if (theGroup == ModelAPI_ResultConstruction::group()) return createIndex(1, 0, (qint32) ConstructFolder); @@ -538,7 +538,7 @@ QModelIndex XGUI_PartDataModel::objectIndex(const ObjectPtr& theObject) const } if (aRow == -1) return aIndex; - if (aGroup == ModelAPI_ResultParameters::group()) + if (aGroup == ModelAPI_ResultParameter::group()) return createIndex(aRow, 0, (qint32) ParamObject); else if (aGroup == ModelAPI_ResultConstruction::group()) return createIndex(aRow, 0, (qint32) ConstructObject); -- 2.39.2