]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'master' into cgt/devCEA
authorClarisse Genrault <clarisse.genrault@cea.fr>
Mon, 21 Nov 2016 09:49:27 +0000 (10:49 +0100)
committerClarisse Genrault <clarisse.genrault@cea.fr>
Mon, 21 Nov 2016 09:49:27 +0000 (10:49 +0100)
25 files changed:
src/CollectionAPI/CollectionAPI.i
src/CollectionAPI/CollectionAPI_Field.cpp
src/CollectionAPI/CollectionAPI_Field.h
src/CollectionPlugin/CMakeLists.txt
src/CollectionPlugin/CollectionPlugin_Field.cpp
src/CollectionPlugin/CollectionPlugin_Field.h
src/CollectionPlugin/CollectionPlugin_Group.cpp
src/CollectionPlugin/CollectionPlugin_WidgetCreator.cpp
src/CollectionPlugin/CollectionPlugin_WidgetField.cpp
src/CollectionPlugin/CollectionPlugin_WidgetField.h
src/CollectionPlugin/Test/TestField.py [new file with mode: 0644]
src/FeaturesPlugin/FeaturesPlugin_Placement.cpp
src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp
src/FeaturesPlugin/FeaturesPlugin_Translation.cpp
src/Model/Model_SelectionNaming.cpp
src/ModelAPI/ModelAPI.i
src/ModelAPI/ModelAPI_Feature.h
src/ModelHighAPI/CMakeLists.txt
src/ModelHighAPI/ModelHighAPI.i
src/ModelHighAPI/ModelHighAPI_ComponentValue.cpp [deleted file]
src/ModelHighAPI/ModelHighAPI_ComponentValue.h [deleted file]
src/ModelHighAPI/ModelHighAPI_Dumper.cpp
src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp
src/ModelHighAPI/ModelHighAPI_swig.h
src/PythonAPI/model/collection/__init__.py

index 6bdd141e20a64c2f6dc875f801a000a9a02a8679..d7f158eeb1b9feed195f1f5376def05ee0d4eb81 100644 (file)
 #endif // CollectionAPI_swig_H_
 %}
 
+%{
+  #include "ModelHighAPI_swig.h"
+
+  // fix for SWIG v2.0.4
+  #define SWIGPY_SLICE_ARG(obj) ((PySliceObject*)(obj))
+%}
+
 %include "doxyhelp.i"
 
 // import other modules
 
 // standard definitions
 %include "typemaps.i"
+%include "std_list.i"
+%include "std_string.i"
 %include "std_shared_ptr.i"
 
+%template(StringList) std::list<std::string>;
+%template(IntegerList) std::list<int>;
+%template(DoubleList) std::list<double>;
+%template(BooleanList) std::list<bool>;
+%template(StringListList) std::list<std::list<std::string> >;
+%template(IntegerListList) std::list<std::list<int> >;
+%template(DoubleListList) std::list<std::list<double> >;
+%template(BooleanListList) std::list<std::list<bool> >;
+
 // shared pointers
 %shared_ptr(CollectionAPI_Group)
 %shared_ptr(CollectionAPI_Field)
index b0441e4859231c540113c2bc819f4f5064669e42..98110e8614372fb272e78498ad9f7d00b2f000c8 100644 (file)
@@ -10,7 +10,6 @@
 #include <ModelHighAPI_Integer.h>
 #include <ModelHighAPI_Selection.h>
 #include <ModelHighAPI_Tools.h>
-#include <ModelHighAPI_ComponentValue.h>
 #include <ModelAPI_AttributeTables.h>
 #include <ModelAPI_AttributeStringArray.h>
 
@@ -35,13 +34,6 @@ void CollectionAPI_Field::setSelection(const std::list<ModelHighAPI_Selection>&
   execute();
 }
 
-//=================================================================================================
-void CollectionAPI_Field::setComponentsNum(const ModelHighAPI_Integer& theNum)
-{
-  fillAttribute(theNum, mycomponentsNum);
-  execute();
-}
-
 //=================================================================================================
 void CollectionAPI_Field::setComponentsNames(const std::list<std::string>& theNames)
 {
@@ -53,6 +45,7 @@ void CollectionAPI_Field::setComponentsNames(const std::list<std::string>& theNa
 void CollectionAPI_Field::setValuesType(const std::string& theType)
 {
   fillAttribute(int(valueTypeByStr(theType)), myvaluesType);
+  myvalues->setType(valueTypeByStr(theType));
   execute();
 }
 
@@ -60,6 +53,7 @@ void CollectionAPI_Field::setValuesType(const std::string& theType)
 void CollectionAPI_Field::setStepsNum(const ModelHighAPI_Integer& theSteps)
 {
   fillAttribute(theSteps, mystepsNum);
+  mystamps->setSize(theSteps.intValue());
   execute();
 }
 
@@ -71,37 +65,45 @@ void CollectionAPI_Field::setStamps(const std::list<ModelHighAPI_Integer>& theSt
 }
 
 //=================================================================================================
-void CollectionAPI_Field::addStep(const ModelHighAPI_Integer& theStepNum,
-  const ModelHighAPI_Integer& theStamp,
-  const std::list<std::list<ModelHighAPI_ComponentValue> >& theComponents)
-{
-  // set the table size to be sure the values are up to date
-  myvalues->setSize(myselection->size() + 1 /* with defaults */,
-    mycomponentsNum->value(), mystepsNum->value());
-
-  // set values one by one
-  int aRowIndex = 0;
-  std::list<std::list<ModelHighAPI_ComponentValue> >::const_iterator 
-    aRowsIter = theComponents.begin();
-  for(; aRowsIter != theComponents.end(); aRowsIter++, aRowIndex++) {
-    int aColIndex = 0;
-    std::list<ModelHighAPI_ComponentValue>::const_iterator aColIter = aRowsIter->begin();
-    for(; aColIter != aRowsIter->end(); aColIter++, aColIndex++) {
-      aColIter->fill(myvalues, theStepNum.intValue(), aColIndex, aRowIndex);
-    }
-  }
-  execute();
+#define addStepImplementation(type, fieldType, type2, fieldType2, type3, fieldType3) \
+void CollectionAPI_Field::addStep(const ModelHighAPI_Integer& theStepNum, \
+  const ModelHighAPI_Integer& theStamp, \
+  const std::list<std::list<type> >& theComponents) \
+{ \
+  myvalues->setSize(myselection->size() + 1, \
+    mycomponentsNames->size(), mystepsNum->value()); \
+  mystamps->setValue(theStepNum.intValue(), theStamp.intValue()); \
+  int aRowIndex = 0; \
+  std::list<std::list<type> >::const_iterator \
+    aRowsIter = theComponents.begin(); \
+  for(; aRowsIter != theComponents.end(); aRowsIter++, aRowIndex++) { \
+    int aColIndex = 0; \
+    std::list<type>::const_iterator aColIter = aRowsIter->begin(); \
+    for(; aColIter != aRowsIter->end(); aColIter++, aColIndex++) { \
+      ModelAPI_AttributeTables::Value aVal; \
+      aVal.fieldType = *aColIter; \
+      aVal.fieldType2 = type2(*aColIter); \
+      aVal.fieldType3 = type3(*aColIter); \
+      myvalues->setValue(aVal, aRowIndex, aColIndex, theStepNum.intValue()); \
+    } \
+  } \
+  execute(); \
 }
 
+addStepImplementation(double, myDouble, int, myInt, bool, myBool);
+addStepImplementation(int, myInt, double, myDouble, bool, myBool);
+addStepImplementation(bool, myBool, int, myInt, double, myDouble);
+addStepImplementation(std::string, myStr, std::string, myStr, std::string, myStr);
+
 //=================================================================================================
 void CollectionAPI_Field::dump(ModelHighAPI_Dumper& theDumper) const
 {
   FeaturePtr aBase = feature();
   const std::string& aDocName = theDumper.name(aBase->document());
 
-  theDumper<<aBase<<" = model.addField("<<aDocName<<", "<<mystepsNum<<", "
-    <<strByValueType(ModelAPI_AttributeTables::ValueType(myvaluesType->value()))<<", "
-    <<mycomponentsNum->value()<<", ";
+  theDumper<<aBase<<" = model.addField("<<aDocName<<", "<<mystepsNum->value()<<", \""
+    <<strByValueType(ModelAPI_AttributeTables::ValueType(myvaluesType->value()))<<"\", "
+    <<mycomponentsNames->size()<<", ";
   theDumper<<mycomponentsNames<<", ";
   theDumper<<myselection<<")"<<std::endl;
   // set values step by step
@@ -114,7 +116,7 @@ void CollectionAPI_Field::dump(ModelHighAPI_Dumper& theDumper) const
       for(int aCol = 0; aCol < myvalues->columns(); aCol++) {
         if (aCol != 0)
           theDumper<<", ";
-        switch(myvalues->type()) {
+        switch(myvaluesType->value()) {
         case ModelAPI_AttributeTables::BOOLEAN:
           theDumper<<myvalues->value(aRow, aCol, aStep).myBool;
           break;
@@ -125,20 +127,20 @@ void CollectionAPI_Field::dump(ModelHighAPI_Dumper& theDumper) const
           theDumper<<myvalues->value(aRow, aCol, aStep).myDouble;
           break;
         case ModelAPI_AttributeTables::STRING:
-          theDumper<<myvalues->value(aRow, aCol, aStep).myStr;
+          theDumper<<'"'<<myvalues->value(aRow, aCol, aStep).myStr<<'"';
           break;
         }
       }
       theDumper<<"]";
     }
-    theDumper<<")"<<std::endl;
+    theDumper<<"])"<<std::endl;
   }
 }
 
 //=================================================================================================
 FieldPtr addField(const std::shared_ptr<ModelAPI_Document>& thePart,
                   const ModelHighAPI_Integer& theStepsNum,
-                  std::string& theComponentType,
+                  const std::string& theComponentType,
                   const int theComponentsNum,
                   const std::list<std::string>& theComponentNames,
                   const std::list<ModelHighAPI_Selection>& theSelectionList)
@@ -147,7 +149,6 @@ FieldPtr addField(const std::shared_ptr<ModelAPI_Document>& thePart,
   std::shared_ptr<CollectionAPI_Field> aField(new CollectionAPI_Field(aFeature));
   aField->setStepsNum(theStepsNum);
   aField->setValuesType(theComponentType);
-  aField->setComponentsNum(theComponentsNum);
   aField->setComponentsNames(theComponentNames);
   aField->setSelection(theSelectionList);
 
index 8f0b5ecab28541d3843d5ff2e6ef62d26afdfbd2..d7eef3ee58e4596a1cc5a0517f1c26dd931fae7a 100644 (file)
@@ -33,11 +33,9 @@ public:
   COLLECTIONAPI_EXPORT
   virtual ~CollectionAPI_Field();
 
-  INTERFACE_7(CollectionPlugin_Field::ID(),
+  INTERFACE_6(CollectionPlugin_Field::ID(),
     selection, CollectionPlugin_Field::SELECTED_ID(),
     ModelAPI_AttributeSelectionList, /** Field selection list*/,
-    componentsNum, CollectionPlugin_Field::COMPONENTS_NB_ID(),
-    ModelAPI_AttributeInteger, /** Number of components integer */,
     componentsNames, CollectionPlugin_Field::COMPONENTS_NAMES_ID(),
     ModelAPI_AttributeStringArray, /** Names of components list of strings */,
     valuesType, CollectionPlugin_Field::VALUES_TYPE_ID(),
@@ -52,9 +50,6 @@ public:
   /// Set selected objects.
   COLLECTIONAPI_EXPORT
   void setSelection(const std::list<ModelHighAPI_Selection>& theFieldList);
-  /// Set number of components
-  COLLECTIONAPI_EXPORT
-  void setComponentsNum(const ModelHighAPI_Integer& theNum);
   /// Set names of components
   COLLECTIONAPI_EXPORT
   void setComponentsNames(const std::list<std::string>& theNames);
@@ -67,10 +62,22 @@ public:
   /// Set stamps identifiers
   COLLECTIONAPI_EXPORT
   void setStamps(const std::list<ModelHighAPI_Integer>& theStamps);
-  /// Sets the values of specific step
+  /// Sets the double values of specific step
+  COLLECTIONAPI_EXPORT
+  void addStep(const ModelHighAPI_Integer& theStepNum, const ModelHighAPI_Integer& theStamp,
+    const std::list<std::list<double> >& theComponents);
+  /// Sets the integer values of specific step
+  COLLECTIONAPI_EXPORT
+  void addStep(const ModelHighAPI_Integer& theStepNum, const ModelHighAPI_Integer& theStamp,
+    const std::list<std::list<int> >& theComponents);
+  /// Sets the string values of specific step
+  COLLECTIONAPI_EXPORT
+  void addStep(const ModelHighAPI_Integer& theStepNum, const ModelHighAPI_Integer& theStamp,
+    const std::list<std::list<std::string> >& theComponents);
+  /// Sets the boolean values of specific step
   COLLECTIONAPI_EXPORT
   void addStep(const ModelHighAPI_Integer& theStepNum, const ModelHighAPI_Integer& theStamp,
-    const std::list<std::list<ModelHighAPI_ComponentValue> >& theComponents);
+    const std::list<std::list<bool> >& theComponents);
 
   /// Dump wrapped feature
   COLLECTIONAPI_EXPORT
@@ -85,7 +92,7 @@ typedef std::shared_ptr<CollectionAPI_Field> FieldPtr;
 COLLECTIONAPI_EXPORT
 FieldPtr addField(const std::shared_ptr<ModelAPI_Document>& thePart,
                   const ModelHighAPI_Integer& theStepsNum,
-                  std::string& theComponentType,
+                  const std::string& theComponentType,
                   const int theComponentsNum,
                   const std::list<std::string>& theComponentNames,
                   const std::list<ModelHighAPI_Selection>& theSelectionList);
index 69df0403470b4d94093f2c06f51673885b683a52..c1b22136e81a2ee841c4aa599481ed01095a0f5c 100644 (file)
@@ -40,6 +40,8 @@ INCLUDE_DIRECTORIES(
   ../GeomValidators
   ../Events
   ../ModuleBase
+  ../Config
+  ${CAS_INCLUDE_DIRS}
 )
 
 SET(PROJECT_LIBRARIES
@@ -51,7 +53,7 @@ SET(PROJECT_LIBRARIES
     ModuleBase
 )
 
-ADD_DEFINITIONS(-DCOLLECTIONPLUGIN_EXPORTS)
+ADD_DEFINITIONS(-DCOLLECTIONPLUGIN_EXPORTS ${CAS_DEFINITIONS})
 ADD_LIBRARY(CollectionPlugin MODULE ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${XML_RESOURCES} ${TEXT_RESOURCES})
 TARGET_LINK_LIBRARIES(CollectionPlugin ${PROJECT_LIBRARIES})
 
@@ -62,4 +64,5 @@ INSTALL(FILES ${TEXT_RESOURCES} DESTINATION ${SHAPER_INSTALL_XML_RESOURCES})
 
 ADD_UNIT_TESTS(
                TestGroup.py
+               TestField.py
 )
index bc2daf57eb425add624205a406b8f8ccd28e7ed7..c9228c405b40b1c915ae187997e72da0165c048b 100644 (file)
@@ -22,7 +22,6 @@ CollectionPlugin_Field::CollectionPlugin_Field()
 void CollectionPlugin_Field::initAttributes()
 {
   data()->addAttribute(SELECTED_ID(), ModelAPI_AttributeSelectionList::typeId());
-  data()->addAttribute(COMPONENTS_NB_ID(), ModelAPI_AttributeInteger::typeId());
   data()->addAttribute(COMPONENTS_NAMES_ID(), ModelAPI_AttributeStringArray::typeId());
   data()->addAttribute(VALUES_TYPE_ID(), ModelAPI_AttributeInteger::typeId());
   data()->addAttribute(STEPS_NB_ID(), ModelAPI_AttributeInteger::typeId());
index 162720f9186b56e02b643132e02c2f6d1efce0ae..2025c5b51508aad3fbd193710bbe2e236120c8d7 100644 (file)
@@ -29,7 +29,7 @@
 class CollectionPlugin_Field : public ModelAPI_Feature
 {
  public:
-  /// Extrusion kind
+  /// Feature kind
   inline static const std::string& ID()
   {
     static const std::string MY_FIELD_ID("Field");
@@ -41,12 +41,6 @@ class CollectionPlugin_Field : public ModelAPI_Feature
     static const std::string MY_SELECTED_ID("selected");
     return MY_SELECTED_ID;
   }
-  /// attribute name of components number
-  inline static const std::string& COMPONENTS_NB_ID()
-  {
-    static const std::string MY_COMPONENTS_NB_ID("components_nb");
-    return MY_COMPONENTS_NB_ID;
-  }
   /// attribute name of componenets titles array
   inline static const std::string& COMPONENTS_NAMES_ID()
   {
index c62b7d0d96b0fd8455949773f6838de22d2391b7..ede838a3e4829039c78ffb4c84355df3d422df97 100644 (file)
@@ -19,8 +19,8 @@ CollectionPlugin_Group::CollectionPlugin_Group()
 
 void CollectionPlugin_Group::initAttributes()
 {
-  //data()->addAttribute(CollectionPlugin_Group::NAME_ID(), ModelAPI_AttributeString::typeId());
-  data()->addAttribute(CollectionPlugin_Group::LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
+  data()->addAttribute(CollectionPlugin_Group::LIST_ID(), 
+                       ModelAPI_AttributeSelectionList::typeId());
 }
 
 void CollectionPlugin_Group::execute()
index a07562235ca13c6133ac928ca3477f35787eb33b..a369cf36e4132313dbdf253d894d4c72b917f639 100644 (file)
@@ -24,14 +24,14 @@ ModuleBase_ModelWidget* CollectionPlugin_WidgetCreator::createWidgetByType(
                                                      const std::string& theType,
                                                      QWidget* theParent,
                                                      Config_WidgetAPI* theWidgetApi,
-                                                     ModuleBase_IWorkshop* /*theWorkshop*/)
+                                                     ModuleBase_IWorkshop* theWorkshop)
 {
   ModuleBase_ModelWidget* aWidget = 0;
   if (myPanelTypes.find(theType) == myPanelTypes.end())
     return aWidget;
 
   if (theType == "field-panel") {     
-    aWidget = new CollectionPlugin_WidgetField(theParent, theWidgetApi);
+    aWidget = new CollectionPlugin_WidgetField(theParent, theWorkshop, theWidgetApi);
   }
 
   return aWidget;
index d0500355ed05d30e5d20ad3dd500f935f787f1ff..a2867f4ee817a3ef1cd56d48688ac1e5be1b1a85 100644 (file)
@@ -6,6 +6,10 @@
 
 #include "CollectionPlugin_WidgetField.h"
 
+#include <ModuleBase_Tools.h>
+#include <ModuleBase_IWorkshop.h>
+#include <ModuleBase_ISelection.h>
+
 #include <QLayout>
 #include <QWidget>
 #include <QFormLayout>
 #include <QTableWidget>
 #include <QPushButton>
 #include <QHeaderView>
+#include <QStackedWidget>
+#include <QValidator>
+#include <QStyledItemDelegate>
+#include <QLineEdit>
+
+
+class DataTableItemDelegate : public QStyledItemDelegate
+{
+public:
+  enum DataType {
+    DoubleType,
+    IntegerType,
+    BooleanType,
+    StringType };
+
+  DataTableItemDelegate(DataType theType) : QStyledItemDelegate() { myType = theType; }
+
+  virtual QWidget* createEditor(QWidget* theParent, 
+                                const QStyleOptionViewItem & theOption, 
+                                const QModelIndex& theIndex) const;
+
+  virtual void setModelData(QWidget* theEditor, QAbstractItemModel* theModel, 
+                            const QModelIndex& theIndex) const;
+
+  DataType dataType() const { return myType; }
+
+  void setDataType(DataType theType) { myType = theType; }
+
+private:
+  DataType myType;
+};
+
+QWidget* DataTableItemDelegate::createEditor(QWidget* theParent, 
+                                             const QStyleOptionViewItem & theOption, 
+                                             const QModelIndex& theIndex ) const
+{
+  if ((theIndex.column() != 0) && (theIndex.row() != 0)) {
+    QLineEdit* aLineEdt = 0;
+    switch (myType) {
+    case DoubleType:
+      aLineEdt = dynamic_cast<QLineEdit*>(QStyledItemDelegate::createEditor(theParent, 
+                                                                            theOption, 
+                                                                            theIndex));
+      if (aLineEdt) {
+        aLineEdt->setValidator(new QDoubleValidator(aLineEdt));
+        return aLineEdt;
+      }
+    case IntegerType:
+      aLineEdt = dynamic_cast<QLineEdit*>(QStyledItemDelegate::createEditor(theParent, 
+                                                                            theOption, 
+                                                                            theIndex));
+      if (aLineEdt) {
+        aLineEdt->setValidator(new QIntValidator(aLineEdt));
+        return aLineEdt;
+      }
+    case BooleanType: 
+      {
+        QComboBox* aBox = new QComboBox(theParent);
+        aBox->addItem("True");
+        aBox->addItem("False");
+        return aBox;
+      }
+    }
+  }
+  return QStyledItemDelegate::createEditor(theParent, theOption, theIndex);
+}
+
+
+void DataTableItemDelegate::setModelData(QWidget* theEditor, QAbstractItemModel* theModel, 
+                                         const QModelIndex& theIndex) const
+{
+  QComboBox* aBox = dynamic_cast<QComboBox*>(theEditor);
+  if (aBox) {
+    theModel->setData(theIndex, aBox->currentText());
+  } else 
+    QStyledItemDelegate::setModelData(theEditor, theModel, theIndex);
+}
+
+
 
 CollectionPlugin_WidgetField::
-  CollectionPlugin_WidgetField(QWidget* theParent, const Config_WidgetAPI* theData):
-ModuleBase_ModelWidget(theParent, theData)
+  CollectionPlugin_WidgetField(QWidget* theParent, 
+                               ModuleBase_IWorkshop* theWorkshop, 
+                               const Config_WidgetAPI* theData):
+ModuleBase_WidgetSelector(theParent, theWorkshop, theData)
 {
   QVBoxLayout* aMainLayout = new QVBoxLayout(this);
 
@@ -83,36 +168,10 @@ ModuleBase_ModelWidget(theParent, theData)
   aSliderLayout->addWidget(myMaxLbl);
 
   // Stamp value
-  aStepLayout->addWidget(new QLabel(tr("Stamp"), aStepFrame), 2, 0);
-  myStampSpn = new QSpinBox(aStepFrame);
-  aStepLayout->addWidget(myStampSpn, 2, 1);
-
-  // Data table
-  myDataTbl = new QTableWidget(2, 2, aStepFrame);
-  myDataTbl->verticalHeader()->hide();
-  myDataTbl->horizontalHeader()->hide();
-  myDataTbl->setRowHeight(0, 25);
-  myDataTbl->setRowHeight(1, 25);
-
-  QTableWidgetItem* aItem = new QTableWidgetItem("Shape");
-  aItem->setBackgroundColor(Qt::lightGray);
-  aItem->setFlags(Qt::NoItemFlags | Qt::ItemIsEnabled);
-  myDataTbl->setItem(0, 0, aItem);
-
-  aItem = new QTableWidgetItem("Comp 1");
-  aItem->setBackgroundColor(Qt::lightGray);
-  myDataTbl->setItem(0, 1, aItem);
-
-  aItem = new QTableWidgetItem("Default value");
-  aItem->setBackgroundColor(Qt::lightGray);
-  aItem->setFlags(Qt::NoItemFlags | Qt::ItemIsEnabled);
-  myDataTbl->setItem(1, 0, aItem);
-
-  aItem = new QTableWidgetItem("0");
-  aItem->setBackgroundColor(Qt::lightGray);
-  myDataTbl->setItem(1, 1, aItem);
-  
-  aStepLayout->addWidget(myDataTbl, 3, 0, 1, 2);
+  myCompNamesList << "Comp 1";
+  myStepWgt = new QStackedWidget(aStepFrame);
+  aStepLayout->addWidget(myStepWgt, 2, 0, 1, 2);
+  appendStepControls();
 
   // Buttons below
   QWidget* aBtnWgt = new QWidget(this);
@@ -125,20 +184,83 @@ ModuleBase_ModelWidget(theParent, theData)
 
   aBtnLayout->addStretch(1);
 
-  QPushButton* aRemoveBtn = new QPushButton(tr("Remove step"), aBtnWgt);
-  aBtnLayout->addWidget(aRemoveBtn);
+  myRemoveBtn = new QPushButton(tr("Remove step"), aBtnWgt);
+  aBtnLayout->addWidget(myRemoveBtn);
+  myRemoveBtn->setEnabled(false);
 
   connect(myNbComponentsSpn, SIGNAL(valueChanged(int)), SLOT(onNbCompChanged(int)));
   connect(aAddBtn, SIGNAL(clicked(bool)), SLOT(onAddStep()));
-  connect(aRemoveBtn, SIGNAL(clicked(bool)), SLOT(onRemoveStep()));
+  connect(myRemoveBtn, SIGNAL(clicked(bool)), SLOT(onRemoveStep()));
   connect(myStepSlider, SIGNAL(valueChanged(int)), SLOT(onStepMove(int)));
+  connect(myFieldTypeCombo, SIGNAL(currentIndexChanged(int)), SLOT(onFieldTypeChanged(int)));
+}
+
+void CollectionPlugin_WidgetField::appendStepControls()
+{
+  QWidget* aWidget = new QWidget(myStepWgt);
+  QGridLayout* aStepLayout = new QGridLayout(aWidget);
+  aStepLayout->setContentsMargins(0, 0, 0, 0);
+
+  aStepLayout->addWidget(new QLabel(tr("Stamp"), aWidget), 0, 0);
+
+  QSpinBox* aStampSpn = new QSpinBox(aWidget);
+  aStepLayout->addWidget(aStampSpn, 0, 1);
+
+  myStampSpnList.append(aStampSpn);
+
+  // Data table
+  QTableWidget* aDataTbl = new QTableWidget(2, myCompNamesList.count() + 1, aWidget);
+  aDataTbl->setItemDelegate(
+    new DataTableItemDelegate((DataTableItemDelegate::DataType) myFieldTypeCombo->currentIndex()));
+  aDataTbl->verticalHeader()->hide();
+  aDataTbl->horizontalHeader()->hide();
+  aDataTbl->setRowHeight(0, 25);
+  aDataTbl->setRowHeight(1, 25);
+
+  QTableWidgetItem* aItem = new QTableWidgetItem("Shape");
+  aItem->setBackgroundColor(Qt::lightGray);
+  aItem->setFlags(Qt::NoItemFlags | Qt::ItemIsEnabled);
+  aDataTbl->setItem(0, 0, aItem);
+
+  aItem = new QTableWidgetItem("Default value");
+  aItem->setBackgroundColor(Qt::lightGray);
+  aItem->setFlags(Qt::NoItemFlags | Qt::ItemIsEnabled);
+  aDataTbl->setItem(1, 0, aItem);
+
+  for (int i = 0; i < myCompNamesList.count(); i++) {
+    aItem = new QTableWidgetItem(myCompNamesList[i]);
+    aItem->setBackgroundColor(Qt::lightGray);
+    aDataTbl->setItem(0, i + 1, aItem);
+
+    aItem = new QTableWidgetItem("0");
+    aItem->setBackgroundColor(Qt::lightGray);
+    aDataTbl->setItem(1, i + 1, aItem);
+  }
+  aStepLayout->addWidget(aDataTbl, 1, 0, 1, 2);
+
+  QAbstractItemDelegate* aDel = aDataTbl->itemDelegate();
+  myDataTblList.append(aDataTbl);
+
+  myStepWgt->addWidget(aWidget);
+}
+
+void CollectionPlugin_WidgetField::removeStepControls()
+{
+  int aCurWgtId = myStepWgt->currentIndex();
+  myStepWgt->removeWidget(myStepWgt->currentWidget());
+
+  myStampSpnList.removeAt(aCurWgtId);
+  myDataTblList.removeAt(aCurWgtId);
 }
 
+
 QList<QWidget*> CollectionPlugin_WidgetField::getControls() const
 {
   QList<QWidget*> aControls;
   // this control will accept focus and will be highlighted in the Property Panel
-  //aControls.push_back(myComboBox);
+  //aControls.push_back(myShapeTypeCombo);
+  //aControls.push_back(myFieldTypeCombo);
+  //aControls.push_back(myNbComponentsSpn);
   return aControls;
 }
 
@@ -167,21 +289,31 @@ bool CollectionPlugin_WidgetField::restoreValueCustom()
 
 void CollectionPlugin_WidgetField::onNbCompChanged(int theVal)
 {
-  int aOldCol = myDataTbl->columnCount() - 1;
-  int aNbRows = myDataTbl->rowCount();
-  myDataTbl->setColumnCount(theVal + 1);
+  int aOldCol = myCompNamesList.count();
+  int aNbRows = myDataTblList.first()->rowCount();
   int aDif = theVal - aOldCol;
   QTableWidgetItem* aItem = 0;
-  for (int i = 0; i < aDif; i++) {
-    for (int j = 0; j < aNbRows; j++) {
-      aItem = new QTableWidgetItem();
-      if (j == 0)
-        aItem->setText(QString("Comp %1").arg(i + aOldCol + 1));
-      else
-        aItem->setText("0");
-      if (j < 3)
-        aItem->setBackgroundColor(Qt::lightGray);
-      myDataTbl->setItem(j, i + aOldCol + 1, aItem);
+
+  while (myCompNamesList.count() != theVal) {
+    if (aDif > 0)
+      myCompNamesList.append(QString("Comp %1").arg(myCompNamesList.count() + 1));
+    else
+      myCompNamesList.removeLast();
+  }
+
+  foreach(QTableWidget* aDataTbl, myDataTblList) {
+    aDataTbl->setColumnCount(theVal + 1);
+    for (int i = 0; i < myCompNamesList.count(); i++) {
+      for (int j = 0; j < aNbRows; j++) {
+        aItem = new QTableWidgetItem();
+        if (j == 0)
+          aItem->setText(myCompNamesList.at(i));
+        else
+          aItem->setText("0");
+        if (j < 3)
+          aItem->setBackgroundColor(Qt::lightGray);
+        aDataTbl->setItem(j, i + aOldCol + 1, aItem);
+      }
     }
   }
 }
@@ -192,28 +324,33 @@ void CollectionPlugin_WidgetField::onAddStep()
   aMax++;
   myStepSlider->setMaximum(aMax);
   myMaxLbl->setText(QString::number(aMax));
-  clearData();
+  appendStepControls();
   myStepSlider->setValue(aMax);
+  myRemoveBtn->setEnabled(aMax > 1);
 }
 
 void CollectionPlugin_WidgetField::onRemoveStep()
 {
   int aMax = myStepSlider->maximum();
   aMax--;
-  myStepSlider->setMaximum(aMax);
   myMaxLbl->setText(QString::number(aMax));
+  removeStepControls();
+  myStepSlider->setMaximum(aMax);
+  myRemoveBtn->setEnabled(aMax > 1);
 }
 
 void CollectionPlugin_WidgetField::clearData()
 {
-  int aNbRows = myDataTbl->rowCount();
-  int aNbCol = myDataTbl->columnCount();
-
-  QString aDefValue;
-  for (int i = 1; i < aNbCol; i++) {
-    aDefValue = myDataTbl->item(1, i)->text();
-    for (int j = 2; j < aNbRows; j++) {
-      myDataTbl->item(j, i)->setText(aDefValue);
+  int aNbRows = myDataTblList.first()->rowCount();
+  int aNbCol = myDataTblList.first()->columnCount();
+
+  foreach(QTableWidget* aDataTbl, myDataTblList) {
+    QString aDefValue;
+    for (int i = 1; i < aNbCol; i++) {
+      aDefValue = aDataTbl->item(1, i)->text();
+      for (int j = 2; j < aNbRows; j++) {
+        aDataTbl->item(j, i)->setText(aDefValue);
+      }
     }
   }
 }
@@ -221,4 +358,59 @@ void CollectionPlugin_WidgetField::clearData()
 void CollectionPlugin_WidgetField::onStepMove(int theStep)
 {
   myCurStepLbl->setText(QString::number(theStep));
+  myStepWgt->setCurrentIndex(theStep - 1);
+}
+
+QIntList CollectionPlugin_WidgetField::shapeTypes() const
+{
+  QIntList aRes;
+  switch (myShapeTypeCombo->currentIndex()) {
+  case 0: //"Vertices"
+    aRes.append(ModuleBase_Tools::shapeType("vertex"));
+    break;
+  case 1: // "Edges"
+    aRes.append(ModuleBase_Tools::shapeType("edge"));
+    break;
+  case 2: // "Faces"
+    aRes.append(ModuleBase_Tools::shapeType("face"));
+    break;
+  case 3: // "Solids"
+    aRes.append(ModuleBase_Tools::shapeType("solid"));
+    break;
+  case 4: // "Results"
+    aRes.append(ModuleBase_Tools::shapeType("object"));
+    break;
+  case 5: // "Parts"
+    // TODO: Selection mode for Parts
+    break;
+  }
+  return aRes;
+}
+
+bool CollectionPlugin_WidgetField::
+  isValidSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs)
+{
+  return true;
+}
+
+void CollectionPlugin_WidgetField::onSelectionChanged()
+{
+  QList<ModuleBase_ViewerPrsPtr> aSelected = 
+    myWorkshop->selection()->getSelected(ModuleBase_ISelection::AllControls);
+
+  clearData();
+
+  foreach(ModuleBase_ViewerPrsPtr aPrs, aSelected) {
+
+  }
+}
+
+void CollectionPlugin_WidgetField::onFieldTypeChanged(int theIdx)
+{
+  DataTableItemDelegate* aDelegate = 0;
+  foreach(QTableWidget* aTable, myDataTblList) {
+    aDelegate = dynamic_cast<DataTableItemDelegate*>(aTable->itemDelegate());
+    if (aDelegate)
+      aDelegate->setDataType((DataTableItemDelegate::DataType)theIdx);
+  }
 }
index 0098157392171a3fecdfa9a0109700790754888a..3e3277b53a28c38219f3ccf9a999c467be4563f0 100644 (file)
 
 #include "CollectionPlugin.h"
 
-#include <ModuleBase_ModelWidget.h>
+#include <ModuleBase_WidgetSelector.h>
+#include <ModuleBase_ViewerPrs.h>
+
+#include <QList>
+#include <QStringList>
+
 
 class QWidget;
 class QComboBox;
@@ -19,16 +24,20 @@ class QSpinBox;
 class QLabel;
 class QSlider;
 class QTableWidget;
+class QStackedWidget;
+class QPushButton;
 
 /*!
  * \ingroup GUI
  * Represent a content of the property panel to show/modify parameters of a Field feature.
  */
-class CollectionPlugin_WidgetField : public ModuleBase_ModelWidget
+class CollectionPlugin_WidgetField : public ModuleBase_WidgetSelector
 {
  Q_OBJECT
 public:
-  CollectionPlugin_WidgetField(QWidget* theParent, const Config_WidgetAPI* theData);
+  CollectionPlugin_WidgetField(QWidget* theParent, 
+                               ModuleBase_IWorkshop* theWorkshop, 
+                               const Config_WidgetAPI* theData);
 
   virtual ~CollectionPlugin_WidgetField() {}
 
@@ -36,6 +45,12 @@ public:
   /// \return a control list
   virtual QList<QWidget*> getControls() const;
 
+  /// Checks the widget validity. By default, it returns true.
+  /// \param thePrs a selected presentation in the view
+  /// \return a boolean value
+  virtual bool isValidSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
+
+
 protected:
   /// Saves the internal parameters to the given feature
   /// \return True in success
@@ -44,6 +59,15 @@ protected:
   /// Restore value from attribute data to the widget's control
   virtual bool restoreValueCustom();
 
+  /// Retunrs a list of possible shape types
+  /// \return a list of shapes
+  virtual QIntList shapeTypes() const;
+
+
+protected slots:
+  /// Slot which is called on selection event
+  virtual void onSelectionChanged();
+
 private slots:
   void onNbCompChanged(int theVal);
 
@@ -53,9 +77,14 @@ private slots:
 
   void onStepMove(int theStep);
 
+  void onFieldTypeChanged(int theIdx);
+
 private:
   void clearData();
 
+  void appendStepControls();
+  void removeStepControls();
+
   /// Types of shapes selection
   QComboBox* myShapeTypeCombo;
 
@@ -72,11 +101,19 @@ private:
   QSlider* myStepSlider;
 
   /// Stamp value
-  QSpinBox* myStampSpn;
+  QList<QSpinBox*> myStampSpnList;
 
-  QTableWidget* myDataTbl;
+  QList<QTableWidget*> myDataTblList;
 
   QLabel* myMaxLbl;
+
+  QStackedWidget* myStepWgt;
+
+  QStringList myCompNamesList;
+
+  QList<ModuleBase_ViewerPrsPtr> mySelection;
+
+  QPushButton* myRemoveBtn;
 };
 
 #endif
\ No newline at end of file
diff --git a/src/CollectionPlugin/Test/TestField.py b/src/CollectionPlugin/Test/TestField.py
new file mode 100644 (file)
index 0000000..5bf10bd
--- /dev/null
@@ -0,0 +1,186 @@
+"""
+      TestBoolean.py
+      Unit test of FeaturesPlugin_Group class
+
+      class FeaturesPlugin_Group
+        static const std::string MY_GROUP_ID("Group");
+        static const std::string MY_GROUP_LIST_ID("group_list");
+
+        data()->addAttribute(FeaturesPlugin_Group::LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
+"""
+#=========================================================================
+# Initialization of the test
+#=========================================================================
+from ModelAPI import *
+from GeomDataAPI import *
+from GeomAlgoAPI import *
+from GeomAPI import *
+
+__updated__ = "2014-12-16"
+
+aSession = ModelAPI_Session.get()
+# Create a part for extrusions & boolean
+aSession.startOperation()
+aPartFeature = aSession.moduleDocument().addFeature("Part")
+aSession.finishOperation()
+aPart = aSession.activeDocument()
+#=========================================================================
+# Create a sketch with triangle and extrude it
+#=========================================================================
+aSession.startOperation()
+aTriangleSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
+origin = geomDataAPI_Point(aTriangleSketchFeature.attribute("Origin"))
+origin.setValue(0, 0, 0)
+dirx = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirX"))
+dirx.setValue(1, 0, 0)
+norm = geomDataAPI_Dir(aTriangleSketchFeature.attribute("Norm"))
+norm.setValue(0, 0, 1)
+aSketchLineA = aTriangleSketchFeature.addFeature("SketchLine")
+aSketchLineB = aTriangleSketchFeature.addFeature("SketchLine")
+aSketchLineC = aTriangleSketchFeature.addFeature("SketchLine")
+aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
+aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
+aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
+aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
+aLineCStartPoint = geomDataAPI_Point2D(aSketchLineC.attribute("StartPoint"))
+aLineCEndPoint = geomDataAPI_Point2D(aSketchLineC.attribute("EndPoint"))
+aLineAStartPoint.setValue(-100., 0.)
+aLineAEndPoint.setValue(100., 0.)
+aLineBStartPoint.setValue(100., 0.)
+aLineBEndPoint.setValue(0., 173.2)
+aLineCStartPoint.setValue(0., 173.2)
+aLineCEndPoint.setValue(-100., 0.)
+aSession.finishOperation()
+# Build sketch faces
+aSession.startOperation()
+aSketchResult = aTriangleSketchFeature.firstResult()
+aSketchEdges = modelAPI_ResultConstruction(aSketchResult).shape()
+origin = geomDataAPI_Point(aTriangleSketchFeature.attribute("Origin")).pnt()
+dirX = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirX")).dir()
+norm = geomDataAPI_Dir(aTriangleSketchFeature.attribute("Norm")).dir()
+aSketchFaces = ShapeList()
+GeomAlgoAPI_SketchBuilder.createFaces(origin, dirX, norm, aSketchEdges, aSketchFaces)
+# Create extrusion on them
+anExtrusionFt = aPart.addFeature("Extrusion")
+anExtrusionFt.selectionList("base").append(aSketchResult, aSketchFaces[0])
+anExtrusionFt.string("CreationMethod").setValue("BySizes")
+anExtrusionFt.real("to_size").setValue(50)
+anExtrusionFt.real("from_size").setValue(50)
+anExtrusionFt.real("to_offset").setValue(0) #TODO: remove
+anExtrusionFt.real("from_offset").setValue(0) #TODO: remove
+anExtrusionFt.execute()
+aSession.finishOperation()
+anExtrusionBody = modelAPI_ResultBody(anExtrusionFt.firstResult())
+#=========================================================================
+# Create doubles field on vertices
+#=========================================================================
+aSession.startOperation()
+aField = aSession.activeDocument().addFeature("Field")
+aSelectionListAttr = aField.selectionList("selected")
+aSelectionListAttr.setSelectionType("vertex")
+aSelectionListAttr.append("Extrusion_1_1/Generated_Face_3&Extrusion_1_1/Generated_Face_1&Extrusion_1_1/To_Face_1_1")
+aSelectionListAttr.append("Extrusion_1_1/Generated_Face_2&Extrusion_1_1/Generated_Face_1&Extrusion_1_1/To_Face_1_1")
+aSelectionListAttr.append("Extrusion_1_1/Generated_Face_3&Extrusion_1_1/Generated_Face_2&Extrusion_1_1/From_Face_1_1")
+aComponentNames = aField.stringArray("components_names")
+aComponentNames.setSize(2) # two components
+aComponentNames.setValue(0, "temperatue")
+aComponentNames.setValue(1, "porosity")
+aField.integer("type").setValue(2) # double
+aField.integer("steps_nb").setValue(1) # one step
+aStamps = aField.intArray("stamps")
+aStamps.setSize(1)
+aStamps.setValue(0, 10)
+aTables = aField.tables("values")
+aTables.setType(2)
+aTables.setSize(1 + 3, 2, 1) # default row + number of selected, number of compoents, number of steps (tables)
+aTables.setValue(20, 0, 0, 0) # value, index of selection, index of component, index of step
+aTables.setValue(35, 1, 0, 0)
+aTables.setValue(27, 2, 0, 0)
+aTables.setValue(28, 3, 0, 0)
+aTables.setValue(0.5, 0, 1, 0)
+aTables.setValue(0.55, 1, 1, 0)
+aTables.setValue(0.39, 2, 1, 0)
+aTables.setValue(0.40, 3, 1, 0)
+aSession.finishOperation()
+#=========================================================================
+# Create strings field on faces
+#=========================================================================
+aSession.startOperation()
+aField = aSession.activeDocument().addFeature("Field")
+aSelectionListAttr = aField.selectionList("selected")
+aSelectionListAttr.setSelectionType("face")
+aSelectionListAttr.append("Extrusion_1_1/Generated_Face_3")
+aComponentNames = aField.stringArray("components_names")
+aComponentNames.setSize(1) # one component
+aComponentNames.setValue(0, "description")
+aField.integer("type").setValue(3) # string
+aField.integer("steps_nb").setValue(2) # two steps
+aStamps = aField.intArray("stamps")
+aStamps.setSize(2)
+aStamps.setValue(0, 1)
+aStamps.setValue(1, 3)
+aTables = aField.tables("values")
+aTables.setType(3)
+aTables.setSize(1 + 1, 1, 2) # default row + number of selected, number of compoents, number of steps (tables)
+aTables.setValue("-default-", 0, 0, 0) # value, index of selection, index of component, index of step
+aTables.setValue("-default-", 0, 0, 1)
+aTables.setValue("Face one", 1, 0, 0)
+aTables.setValue("Face two", 1, 0, 1)
+aSession.finishOperation()
+
+aFieldResult = aField.firstResult()
+assert(aFieldResult)
+#=========================================================================
+# Create integer field on faces
+#=========================================================================
+aSession.startOperation()
+aField = aSession.activeDocument().addFeature("Field")
+aSelectionListAttr = aField.selectionList("selected")
+aSelectionListAttr.setSelectionType("face")
+aSelectionListAttr.append("Extrusion_1_1/Generated_Face_3")
+aComponentNames = aField.stringArray("components_names")
+aComponentNames.setSize(1) # one component
+aComponentNames.setValue(0, "description")
+aField.integer("type").setValue(1) # integer
+aField.integer("steps_nb").setValue(1) # one step
+aStamps = aField.intArray("stamps")
+aStamps.setSize(1)
+aStamps.setValue(0, 0)
+aTables = aField.tables("values")
+aTables.setType(1)
+aTables.setSize(1 + 1, 1, 1) # default row + number of selected, number of compoents, number of steps (tables)
+aTables.setValue(0, 0, 0, 0) # value, index of selection, index of component, index of step
+aTables.setValue(2, 1, 0, 0)
+aSession.finishOperation()
+
+aFieldResult = aField.firstResult()
+assert(aFieldResult)
+
+#=========================================================================
+# Create Boolean field on faces
+#=========================================================================
+aSession.startOperation()
+aField = aSession.activeDocument().addFeature("Field")
+aSelectionListAttr = aField.selectionList("selected")
+aSelectionListAttr.setSelectionType("face")
+aSelectionListAttr.append("Extrusion_1_1/Generated_Face_3")
+aComponentNames = aField.stringArray("components_names")
+aComponentNames.setSize(1) # one component
+aComponentNames.setValue(0, "description")
+aField.integer("type").setValue(0) # boolean
+aField.integer("steps_nb").setValue(1) # one step
+aStamps = aField.intArray("stamps")
+aStamps.setSize(1)
+aStamps.setValue(0, 0)
+aTables = aField.tables("values")
+aTables.setType(0)
+aTables.setSize(1 + 1, 1, 1) # default row + number of selected, number of compoents, number of steps (tables)
+aTables.setValue(True, 0, 0, 0) # value, index of selection, index of component, index of step
+aTables.setValue(False, 1, 0, 0)
+aSession.finishOperation()
+
+aFieldResult = aField.firstResult()
+assert(aFieldResult)
+
+import model
+assert(model.checkPythonDump())
index c3351408566f81b7fd5b9c4d79acbf1db8854656..0ffb26ed7a9f3777f2a2ec7266c6e36c498cd83e 100644 (file)
@@ -197,5 +197,7 @@ void FeaturesPlugin_Placement::loadNamingDS(GeomAlgoAPI_Transform& theTransformA
   std::string aPlacedName = "Placed";
   std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = theTransformAlgo.mapOfSubShapes();
 
-  FeaturesPlugin_Tools::storeModifiedShapes(theTransformAlgo, theResultBody, theBaseShape, aPlacedTag, aPlacedName, *aSubShapes.get());
+  FeaturesPlugin_Tools::storeModifiedShapes(theTransformAlgo, theResultBody, 
+                                            theBaseShape, aPlacedTag, aPlacedName, 
+                                            *aSubShapes.get());
 }
index ac2c10ca0e03316d29b9af2259e80bcaeb973899..614264603a7f9eb0defbe0a3b4c3f839d090213d 100755 (executable)
@@ -132,5 +132,7 @@ void FeaturesPlugin_Rotation::loadNamingDS(GeomAlgoAPI_Rotation& theRotaionAlgo,
   std::string aRotatedName = "Rotated";
   std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = theRotaionAlgo.mapOfSubShapes();
 
-  FeaturesPlugin_Tools::storeModifiedShapes(theRotaionAlgo, theResultBody, theBaseShape, aRotatedTag, aRotatedName, *aSubShapes.get());
+  FeaturesPlugin_Tools::storeModifiedShapes(theRotaionAlgo, theResultBody, 
+                                            theBaseShape, aRotatedTag, aRotatedName, 
+                                            *aSubShapes.get());
 }
index 2b5a34ed97b25ec76cf1002d13067e2714b173a2..b176b485dfa76d3a183824279862c30e3ce0b0d1 100644 (file)
@@ -247,5 +247,7 @@ void FeaturesPlugin_Translation::loadNamingDS(GeomAlgoAPI_Translation& theTransl
   std::string aTranslatedName = "Translated";
   std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = theTranslationAlgo.mapOfSubShapes();
 
-  FeaturesPlugin_Tools::storeModifiedShapes(theTranslationAlgo, theResultBody, theBaseShape, aTranslatedTag, aTranslatedName, *aSubShapes.get());
+  FeaturesPlugin_Tools::storeModifiedShapes(theTranslationAlgo, theResultBody, 
+                                            theBaseShape, aTranslatedTag, aTranslatedName,
+                                            *aSubShapes.get());
 }
index bc88078c686a08dcc2ef7fce8ed6d588859b2755..47b530460a584018355ca25f5ef3d370cde66884 100644 (file)
@@ -74,7 +74,8 @@ std::string Model_SelectionNaming::getShapeName(
           static const std::string aPostFix("_");
           TNaming_Iterator anItL(aNS);
           for(int i = 1; anItL.More(); anItL.Next(), i++) {
-            if(anItL.NewShape().IsSame(theShape)) { // in #1766 IsEqual produced no index of the face
+            // in #1766 IsEqual produced no index of the face
+            if(anItL.NewShape().IsSame(theShape)) { 
               aName += aPostFix;
               aName += TCollection_AsciiString (i).ToCString();
               break;
index b0cab6686e48afc0c7a4afb5c0d97422313c3d76..6fd73dedba08d1c0fc98e94f641159c4fd032477 100644 (file)
 %shared_ptr(ModelAPI_ResultParameter)
 %shared_ptr(ModelAPI_ResultCompSolid)
 
+%typecheck(SWIG_TYPECHECK_POINTER) const ModelAPI_AttributeTables::Value {
+  $1 = (PyFloat_Check($input) || PyInt_Check($input) || PyLong_Check($input) || PyString_Check($input) || PyBool_Check($input)) ? 1 : 0;
+}
+
+// Tables Value reading as int, double, boolean or string
+%typemap(in) const ModelAPI_AttributeTables::Value {
+  if (PyInt_Check($input)) {
+    $1.myInt = int(PyInt_AsLong($input));
+    $1.myDouble = double(PyInt_AsLong($input));
+    $1.myBool = PyInt_AsLong($input) != 0;
+  } else if (PyFloat_Check($input)) {
+    $1.myInt = int(PyFloat_AsDouble($input));
+    $1.myDouble = PyFloat_AsDouble($input);
+  } else if (PyBool_Check($input)) {
+    $1.myBool = $input == Py_True;
+  } else if (PyString_Check($input)) {
+    $1.myStr = PyString_AsString($input);
+  } else if ((SWIG_ConvertPtr($input, (void **)&$1, $1_descriptor, SWIG_POINTER_EXCEPTION)) == 0) {
+  } else {
+    PyErr_SetString(PyExc_ValueError, "Tables value must be int, double, string or bool.");
+    return NULL;
+  }
+}
+
 // all supported interfaces
 %include "ModelAPI_Entity.h"
 %include "ModelAPI_Document.h"
index 66eb18225d371b0cd2ba02b94a0b50581c36a0dc..b993ea254eb5b22430670cdef19eca1ea8a52fa8 100644 (file)
@@ -175,6 +175,11 @@ class ModelAPI_Feature : public ModelAPI_Object
   {
     return data()->integer(theID);
   }
+  /// Returns the integer array attribute by the identifier
+  inline std::shared_ptr<ModelAPI_AttributeIntArray> intArray(const std::string& theID)
+  {
+    return data()->intArray(theID);
+  }
   /// Returns the reference attribute by the identifier
   inline std::shared_ptr<ModelAPI_AttributeRefAttr> refattr(const std::string& theID)
   {
@@ -205,6 +210,16 @@ class ModelAPI_Feature : public ModelAPI_Object
   {
     return data()->string(theID);
   }
+  /// Returns the string array attribute by the identifier
+  inline std::shared_ptr<ModelAPI_AttributeStringArray> stringArray(const std::string& theID)
+  {
+    return data()->stringArray(theID);
+  }
+  /// Returns the tables attribute by the identifier
+  inline std::shared_ptr<ModelAPI_AttributeTables> tables(const std::string& theID)
+  {
+    return data()->tables(theID);
+  }
   /// Returns the attribute by the identifier
   inline std::shared_ptr<ModelAPI_Attribute> attribute(const std::string& theID)
   {
index 76e151451c1d22e415e101f62a41091a9dbf20c0..9607e5fa2fbc8616f882ad1a45ccb455c935f78a 100644 (file)
@@ -12,7 +12,6 @@ SET(PROJECT_HEADERS
   ModelHighAPI_RefAttr.h
   ModelHighAPI_Reference.h
   ModelHighAPI_Selection.h
-  ModelHighAPI_ComponentValue.h
   ModelHighAPI_Services.h
   ModelHighAPI_Tools.h
   ModelHighAPI_FeatureStore.h
@@ -26,7 +25,6 @@ SET(PROJECT_SOURCES
   ModelHighAPI_RefAttr.cpp
   ModelHighAPI_Reference.cpp
   ModelHighAPI_Selection.cpp
-  ModelHighAPI_ComponentValue.cpp
   ModelHighAPI_Services.cpp
   ModelHighAPI_Tools.cpp
   ModelHighAPI_FeatureStore.cpp
index 0d2daf0f31f1f8c7da8fa880d4a3345889e3c071..e7b448bc39d2453618b32173645607a3ce7551b1 100644 (file)
 %template(RefAttrList) std::list<ModelHighAPI_RefAttr>;
 %template(RefList) std::list<ModelHighAPI_Reference>;
 
+
 // fix compilarion error: ‘res*’ was not declared in this scope
 %typemap(freearg) const std::list<ModelHighAPI_RefAttr> & {}
 %typemap(freearg) const std::list<std::shared_ptr<ModelAPI_Object> > & {}
 %include "ModelHighAPI_RefAttr.h"
 %include "ModelHighAPI_Reference.h"
 %include "ModelHighAPI_Selection.h"
-%include "ModelHighAPI_ComponentValue.h"
 %include "ModelHighAPI_Services.h"
 %include "ModelHighAPI_Macro.h"
 %include "ModelHighAPI_Tools.h"
diff --git a/src/ModelHighAPI/ModelHighAPI_ComponentValue.cpp b/src/ModelHighAPI/ModelHighAPI_ComponentValue.cpp
deleted file mode 100644 (file)
index 9c20968..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-// Name   : ModelHighAPI_ComponentValue.cpp
-// Purpose:
-//
-// History:
-// 29/03/16 - Sergey POKHODENKO - Creation of the file
-
-//--------------------------------------------------------------------------------------
-#include "ModelHighAPI_ComponentValue.h"
-
-#include <ModelAPI_AttributeInteger.h>
-
-#include <sstream>
-
-//--------------------------------------------------------------------------------------
-ModelHighAPI_ComponentValue::ModelHighAPI_ComponentValue(const bool theValue)
-  : myType(ModelAPI_AttributeTables::BOOLEAN)
-{
-  // initialize everything since in python there may be problem with correct typification
-  myValue.myBool = theValue;
-  myValue.myInt = theValue ? 1 : 0;
-  myValue.myDouble = theValue ? 1. : 0.;
-  myValue.myStr = theValue ? "True" : "False";
-}
-//--------------------------------------------------------------------------------------
-ModelHighAPI_ComponentValue::ModelHighAPI_ComponentValue(const int theValue)
-  : myType(ModelAPI_AttributeTables::INTEGER)
-{
-  // initialize everything since in python there may be problem with correct typification
-  myValue.myBool = theValue == 0 ? false : true;
-  myValue.myInt = theValue;
-  myValue.myDouble = theValue;
-  std::ostringstream s;
-  s << theValue;
-  myValue.myStr = s.str();
-}
-//--------------------------------------------------------------------------------------
-ModelHighAPI_ComponentValue::ModelHighAPI_ComponentValue(const double theValue)
-  : myType(ModelAPI_AttributeTables::DOUBLE)
-{
-  // initialize everything since in python there may be problem with correct typification
-  myValue.myBool = theValue == 0. ? false : true;
-  myValue.myInt = int(theValue);
-  myValue.myDouble = theValue;
-  std::ostringstream s;
-  s << theValue;
-  myValue.myStr = s.str();
-}
-//--------------------------------------------------------------------------------------
-ModelHighAPI_ComponentValue::ModelHighAPI_ComponentValue(const std::string& theValue)
-  : myType(ModelAPI_AttributeTables::STRING)
-{
-  myValue.myBool = (theValue.empty() || theValue == "False" || theValue == "0") ? false : true;
-
-  std::stringstream stream1(theValue);
-  myValue.myInt = 0;
-  stream1 >> myValue.myInt;
-  std::stringstream stream2(theValue);
-  myValue.myDouble = 0.;
-  stream2 >> myValue.myDouble;
-
-  myValue.myStr = theValue;
-}
-
-//--------------------------------------------------------------------------------------
-ModelHighAPI_ComponentValue::~ModelHighAPI_ComponentValue()
-{
-}
-
-//--------------------------------------------------------------------------------------
-void ModelHighAPI_ComponentValue::fill(const std::shared_ptr<ModelAPI_AttributeTables>& theAttr,
-    const int theTable, const int theColumn, const int theRow) const
-{
-  theAttr->setValue(myValue, theRow, theColumn, theTable);
-}
diff --git a/src/ModelHighAPI/ModelHighAPI_ComponentValue.h b/src/ModelHighAPI/ModelHighAPI_ComponentValue.h
deleted file mode 100644 (file)
index d7dd41c..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-// Name   : ModelHighAPI_ComponentValue.h
-// Purpose:
-//
-// History:
-// 16/11/16 - Mikhail Ponikarov - Creation of the file
-
-#ifndef SRC_MODELHIGHAPI_ModelHighAPI_ComponentValue_H_
-#define SRC_MODELHIGHAPI_ModelHighAPI_ComponentValue_H_
-
-//--------------------------------------------------------------------------------------
-#include "ModelHighAPI.h"
-
-#include <ModelAPI_AttributeTables.h>
-
-//--------------------------------------------------------------------------------------
-/**\class ModelHighAPI_ComponentValue
- * \ingroup CPPHighAPI
- * \brief Class for filling ModelAPI_AttributeTable elements
- */
-class ModelHighAPI_ComponentValue
-{
-public:
-  /// Constructor for Boolean
-  MODELHIGHAPI_EXPORT ModelHighAPI_ComponentValue(const bool theValue = false);
-  /// Constructor for int
-  MODELHIGHAPI_EXPORT ModelHighAPI_ComponentValue(const int theValue);
-  /// Constructor for double
-  MODELHIGHAPI_EXPORT ModelHighAPI_ComponentValue(const double theValue);
-  /// Constructor for std::string
-  MODELHIGHAPI_EXPORT ModelHighAPI_ComponentValue(const std::string & theValue);
-  /// Destructor
-  MODELHIGHAPI_EXPORT virtual ~ModelHighAPI_ComponentValue();
-
-  /// Sets value to the table
-  MODELHIGHAPI_EXPORT virtual void fill(const std::shared_ptr<ModelAPI_AttributeTables>& theAttr,
-    const int theTable, const int theColumn, const int theRow) const;
-
-private:
-  ModelAPI_AttributeTables::ValueType myType; ///< type of the value set
-  ModelAPI_AttributeTables::Value myValue; ///< value itself
-};
-
-//--------------------------------------------------------------------------------------
-//--------------------------------------------------------------------------------------
-#endif /* SRC_MODELHIGHAPI_ModelHighAPI_ComponentValue_H_ */
index 1176de251e001ef09757c5da6134a53f99c1ee79..1ea7a1f828e4610628a38eba8d95e4238f50a1f4 100644 (file)
@@ -839,10 +839,10 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
 {
   myDumpBuffer<<"[";
   for(int anIndex = 0; anIndex < theArray->size(); ++anIndex) {
-
-    myDumpBuffer<<"\""<<theArray->value(anIndex)<<"\"";
     if (anIndex != 0)
       myDumpBuffer<<", ";
+
+    myDumpBuffer<<"\""<<theArray->value(anIndex)<<"\"";
   }
 
   myDumpBuffer<<"]";
index 99f992f49712a81d700b23f259128ac981521f13..c42072510617eaa52e828893798bc993e3092c8b 100644 (file)
@@ -21,7 +21,9 @@
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeStringArray.h>
 #include <ModelAPI_AttributeDoubleArray.h>
+#include <ModelAPI_AttributeTables.h>
 #include <ModelAPI_Validator.h>
 
 #include <GeomDataAPI_Dir.h>
@@ -266,6 +268,35 @@ std::string ModelHighAPI_FeatureStore::dumpAttr(const AttributePtr& theAttr) {
       std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(theAttr);
     for(int a = 0; a < anAttr->size(); a++)
       aResult<<anAttr->value(a)<<" ";
+  } else if (aType == ModelAPI_AttributeStringArray::typeId()) {
+    AttributeStringArrayPtr anAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeStringArray>(theAttr);
+    for(int a = 0; a < anAttr->size(); a++)
+      aResult<<"'"<<anAttr->value(a)<<"'"<<" ";
+  } else if (aType == ModelAPI_AttributeTables::typeId()) {
+    AttributeTablesPtr anAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeTables>(theAttr);
+    aResult<<anAttr->tables()<<"x"<<anAttr->rows()<<"x"<<anAttr->columns()<<" ";
+    for(int aTab = 0; aTab < anAttr->tables(); aTab++) {
+      for(int aRow = 0; aRow < anAttr->rows(); aRow++) {
+        for( int aCol = 0; aCol < anAttr->columns(); aCol++) {
+          switch(anAttr->type()) {
+          case ModelAPI_AttributeTables::BOOLEAN:
+            aResult<<anAttr->value(aRow, aCol, aTab).myBool<<" ";
+            break;
+          case ModelAPI_AttributeTables::INTEGER:
+            aResult<<anAttr->value(aRow, aCol, aTab).myInt<<" ";
+            break;
+          case ModelAPI_AttributeTables::DOUBLE:
+            aResult<<anAttr->value(aRow, aCol, aTab).myDouble<<" ";
+            break;
+          case ModelAPI_AttributeTables::STRING:
+            aResult<<"'"<<anAttr->value(aRow, aCol, aTab).myStr.c_str()<<"' ";
+            break;
+          }
+        }
+      }
+    }
   } else if (aType == GeomDataAPI_Point::typeId()) {
     AttributePointPtr anAttr = std::dynamic_pointer_cast<GeomDataAPI_Point>(theAttr);
     double aValues[3] = {anAttr->x(), anAttr->y(), anAttr->z()};
index 250b8f8666c6515a60e07f28f8555235b453513a..c9230d49ef728b4bfd1af5784d03ebd4668d7a58 100644 (file)
@@ -20,7 +20,6 @@
   #include "ModelHighAPI_RefAttr.h"
   #include "ModelHighAPI_Reference.h"
   #include "ModelHighAPI_Selection.h"
-  #include "ModelHighAPI_ComponentValue.h"
   #include "ModelHighAPI_Services.h"
   #include "ModelHighAPI_Tools.h"
 
index 4189aac1066b156d823c37837f5391f724a1ece4..5c3e2548621eeac7c08cab22bf7952bdbd66d7ea 100644 (file)
@@ -1,4 +1,4 @@
 """Package for Collection plugin for the Parametric Geometry API of the Modeler.
 """
 
-from CollectionAPI import addGroup
+from CollectionAPI import addGroup, addField