]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
DEBUG
authorspo <sergey.pokhodenko@opencascade.com>
Tue, 21 Jun 2016 07:01:00 +0000 (10:01 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Tue, 21 Jun 2016 07:01:00 +0000 (10:01 +0300)
src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp
src/ExchangePlugin/ExchangePlugin_ImportFeature.h
src/ExchangePlugin/ExchangePlugin_Tools.cpp
src/ExchangePlugin/plugin-Exchange.xml
src/ParametersPlugin/ParametersPlugin_msg_ru.ts

index 73a35fd225aecf3cf6f1ca8e8d828ccc23a47d02..e212bf40de8229086faf74b59d0fdcac0bc90697 100644 (file)
@@ -2,16 +2,12 @@
 
 // File:    ExchangePlugin_ImportFeature.cpp
 // Created: Aug 28, 2014
-// Author:  Sergey BELASH
+// Authors:  Sergey BELASH, Sergey POKHODENKO
 
 #include <ExchangePlugin_ImportFeature.h>
 
 #include <algorithm>
 #include <string>
-#ifdef _DEBUG
-#include <iostream>
-#include <ostream>
-#endif
 
 #include <Config_Common.h>
 #include <Config_PropManager.h>
@@ -57,9 +53,10 @@ ExchangePlugin_ImportFeature::~ExchangePlugin_ImportFeature()
 void ExchangePlugin_ImportFeature::initAttributes()
 {
   data()->addAttribute(ExchangePlugin_ImportFeature::FILE_PATH_ID(), ModelAPI_AttributeString::typeId());
-  data()->addAttribute(ExchangePlugin_ImportFeature::GROUP_LIST_ID(), ModelAPI_AttributeRefList::typeId());
+  data()->addAttribute(ExchangePlugin_ImportFeature::FEATURES_ID(), ModelAPI_AttributeRefList::typeId());
 
-  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ExchangePlugin_ImportFeature::GROUP_LIST_ID());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(
+      getKind(), ExchangePlugin_ImportFeature::FEATURES_ID());
 }
 
 /*
@@ -138,23 +135,23 @@ void ExchangePlugin_ImportFeature::importXAO(const std::string& theFileName)
   XAO::Geometry* aXaoGeometry = aXao.getGeometry();
 
   // use the geometry name or the file name for the feature
-  std::string aBodyName = aXaoGeometry->getName().empty()
-      ? GeomAlgoAPI_Tools::File_Tools::name(theFileName)
-      : aXaoGeometry->getName();
+  std::string aBodyName = aXaoGeometry->getName();
+  if (aBodyName.empty())
+    aBodyName = GeomAlgoAPI_Tools::File_Tools::name(theFileName);
   data()->setName(aBodyName);
 
   ResultBodyPtr aResultBody = createResultBody(aGeomShape);
   setResult(aResultBody);
 
   // Process groups
-  AttributeRefListPtr aRefListOfGroups = reflist(ExchangePlugin_ImportFeature::GROUP_LIST_ID());
+  std::shared_ptr<ModelAPI_AttributeRefList> aRefListOfGroups =
+      std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(data()->attribute(FEATURES_ID()));
 
   // Remove previous groups stored in RefList
   std::list<ObjectPtr> anGroupList = aRefListOfGroups->list();
   std::list<ObjectPtr>::iterator anGroupIt = anGroupList.begin();
   for (; anGroupIt != anGroupList.end(); ++anGroupIt) {
-    std::shared_ptr<ModelAPI_Feature> aFeature =
-        std::dynamic_pointer_cast<ModelAPI_Feature>(*anGroupIt);
+    std::shared_ptr<ModelAPI_Feature> aFeature = ModelAPI_Feature::feature(*anGroupIt);
     if (aFeature)
       document()->removeFeature(aFeature);
   }
@@ -163,7 +160,7 @@ void ExchangePlugin_ImportFeature::importXAO(const std::string& theFileName)
   for (int aGroupIndex = 0; aGroupIndex < aXao.countGroups(); ++aGroupIndex) {
     XAO::Group* aXaoGroup = aXao.getGroup(aGroupIndex);
 
-    std::shared_ptr<ModelAPI_Feature> aGroupFeature = document()->addFeature("Group", false);
+    std::shared_ptr<ModelAPI_Feature> aGroupFeature = addFeature("Group");
 
     // group name
     if (!aXaoGroup->getName().empty())
@@ -188,13 +185,13 @@ void ExchangePlugin_ImportFeature::importXAO(const std::string& theFileName)
 
       aSelectionList->value(anElementIndex)->setId(aReferenceID);
     }
-
-    aRefListOfGroups->append(aGroupFeature);
-
-    // hide the group in the history
-    document()->setCurrentFeature(aGroupFeature, false);
-    // groups features is internal part of the import
-    aGroupFeature->setInHistory(aGroupFeature, false);
+//
+//    aRefListOfGroups->append(aGroupFeature);
+//
+//    // hide the group in the history
+//    document()->setCurrentFeature(aGroupFeature, false);
+//    // groups features is internal part of the import
+//    aGroupFeature->setInHistory(aGroupFeature, false);
   }
 
   } catch (XAO::XAO_Exception& e) {
@@ -204,6 +201,79 @@ void ExchangePlugin_ImportFeature::importXAO(const std::string& theFileName)
   }
 }
 
+//============================================================================
+std::shared_ptr<ModelAPI_Feature> ExchangePlugin_ImportFeature::addFeature(
+    std::string theID)
+{
+  std::shared_ptr<ModelAPI_Feature> aNew = document()->addFeature(theID, false);
+  if (aNew)
+    data()->reflist(FEATURES_ID())->append(aNew);
+  // set as current also after it becomes sub to set correctly enabled for other subs
+  document()->setCurrentFeature(aNew, false);
+  return aNew;
+}
+
+void ExchangePlugin_ImportFeature::removeFeature(
+    std::shared_ptr<ModelAPI_Feature> theFeature)
+{
+  if (!data()->isValid())
+    return;
+  AttributeRefListPtr aList = reflist(FEATURES_ID());
+  // if the object is last, remove it from the list (needed to skip empty transaction on edit of sketch feature)
+  if (aList->object(aList->size(true) - 1, true) == theFeature) {
+    aList->remove(theFeature);
+  } else {
+    // to keep the persistent sub-elements indexing, do not remove elements from list,
+    // but substitute by nulls
+    aList->substitute(theFeature, ObjectPtr());
+  }
+}
+
+int ExchangePlugin_ImportFeature::numberOfSubs(bool forTree) const
+{
+  if (forTree)
+    return 0;
+  return data()->reflist(FEATURES_ID())->size(false);
+}
+
+std::shared_ptr<ModelAPI_Feature> ExchangePlugin_ImportFeature::subFeature(
+    const int theIndex, bool forTree)
+{
+  if (forTree)
+    return FeaturePtr();
+
+  ObjectPtr anObj = data()->reflist(FEATURES_ID())->object(theIndex, false);
+  FeaturePtr aRes = std::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
+  return aRes;
+}
+
+int ExchangePlugin_ImportFeature::subFeatureId(const int theIndex) const
+{
+  std::shared_ptr<ModelAPI_AttributeRefList> aRefList = std::dynamic_pointer_cast<
+      ModelAPI_AttributeRefList>(data()->attribute(FEATURES_ID()));
+  std::list<ObjectPtr> aFeatures = aRefList->list();
+  std::list<ObjectPtr>::const_iterator anIt = aFeatures.begin();
+  int aResultIndex = 1; // number of the counted (created) features, started from 1
+  int aFeatureIndex = -1; // number of the not-empty features in the list
+  for (; anIt != aFeatures.end(); anIt++) {
+    if (anIt->get())
+      aFeatureIndex++;
+    if (aFeatureIndex == theIndex)
+      break;
+    aResultIndex++;
+  }
+  return aResultIndex;
+}
+
+bool ExchangePlugin_ImportFeature::isSub(ObjectPtr theObject) const
+{
+  // check is this feature of result
+  FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
+  if (aFeature)
+    return data()->reflist(FEATURES_ID())->isInList(aFeature);
+  return false;
+}
+
 //============================================================================
 void ExchangePlugin_ImportFeature::loadNamingDS(
     std::shared_ptr<GeomAPI_Shape> theGeomShape,
index 566a7b9e569836fd1e6ec4f13466bd27e7cdf750..d882bc759e5e3fd0e2fc5cdedf0b0e69b4f80a15 100644 (file)
@@ -2,13 +2,14 @@
 
 // File:    ExchangePlugin_ImportFeature.h
 // Created: Aug 28, 2014
-// Author:  Sergey BELASH
+// Authors:  Sergey BELASH, Sergey POKHODENKO
 
 #ifndef EXCHANGEPLUGIN_IMPORTFEATURE_H_
 #define EXCHANGEPLUGIN_IMPORTFEATURE_H_
 
-#include <ExchangePlugin.h>
-#include <ModelAPI_Feature.h>
+#include "ExchangePlugin.h"
+
+#include <ModelAPI_CompositeFeature.h>
 #include <ModelAPI_Result.h>
 
 #include <map>
@@ -20,7 +21,7 @@
  *
  * The list of supported formats is defined in the configuration file.
  */
-class ExchangePlugin_ImportFeature : public ModelAPI_Feature
+class ExchangePlugin_ImportFeature : public ModelAPI_CompositeFeature
 {
  public:
   /// Feature kind
@@ -35,11 +36,11 @@ class ExchangePlugin_ImportFeature : public ModelAPI_Feature
     static const std::string MY_FILE_PATH_ID("file_path");
     return MY_FILE_PATH_ID;
   }
-  /// attribute name of group list
-  inline static const std::string& GROUP_LIST_ID()
+  /// All features (list of references)
+  inline static const std::string& FEATURES_ID()
   {
-    static const std::string MY_GROUP_LIST_ID("group_list");
-    return MY_GROUP_LIST_ID;
+    static const std::string MY_FEATURES_ID("Features");
+    return MY_FEATURES_ID;
   }
   /// Default constructor
   EXCHANGEPLUGIN_EXPORT ExchangePlugin_ImportFeature();
@@ -61,6 +62,24 @@ class ExchangePlugin_ImportFeature : public ModelAPI_Feature
   /// Reimplemented from ModelAPI_Feature::isPreviewNeeded(). Returns false.
   EXCHANGEPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return false; }
 
+  /// Reimplemented from ModelAPI_CompositeFeature::addFeature()
+  virtual std::shared_ptr<ModelAPI_Feature> addFeature(std::string theID);
+
+  /// Reimplemented from ModelAPI_CompositeFeature::numberOfSubs()
+  virtual int numberOfSubs(bool forTree = false) const;
+
+  /// Reimplemented from ModelAPI_CompositeFeature::subFeature()
+  virtual std::shared_ptr<ModelAPI_Feature> subFeature(const int theIndex, bool forTree = false);
+
+  /// Reimplemented from ModelAPI_CompositeFeature::subFeatureId()
+  virtual int subFeatureId(const int theIndex) const;
+
+  /// Reimplemented from ModelAPI_CompositeFeature::isSub()
+  virtual bool isSub(ObjectPtr theObject) const;
+
+  /// Reimplemented from ModelAPI_CompositeFeature::removeFeature()
+  virtual void removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature);
+
  protected:
   /// Performs the import of the file
   EXCHANGEPLUGIN_EXPORT void importFile(const std::string& theFileName);
index 51f22b82bb7792b56cfc6bf3a0bdbfe7d849d86f..5a65fc1dabe8cd3b01adebced56f97ab49d88d7e 100644 (file)
@@ -34,6 +34,8 @@ std::string ExchangePlugin_Tools::selectionType2xaoDimension(const std::string&
 
 std::string ExchangePlugin_Tools::xaoDimension2selectionType(const std::string& theDimension)
 {
+//  return theDimension;
+
   if (theDimension == "vertex")
     return "Vertices";
   else if (theDimension == "edge")
index 47d6d85a03175c428f7cf2494a13b37adc276afa..84a73e07e1ce372d13cbbe46d05906ec5c76a17f 100644 (file)
@@ -7,7 +7,7 @@
         id="Import"
         title="Import"
         tooltip="Import a file"
-        icon=":icons/Exchange/import.png"
+        icon="icons/Exchange/import.png"
         document="Part">
         <file_selector id="file_path" title="Import file" path="">
           <validator id="ExchangePlugin_ImportFormat" parameters="BREP|BRP:BREP,STEP|STP:STEP,IGES|IGS:IGES,XAO:XAO" />
@@ -17,7 +17,7 @@
         id="Export"
         title="Export"
         tooltip="Export to file"
-        icon=":icons/Exchange/export.png">
+        icon="icons/Exchange/export.png">
         <source path="export_widget.xml" />
       </feature>
     </group>
index 35b636acd58950dff0b24214b52b7ca66eed10da..b764a4a7037098b68e32a92e20d9256f306a7fb8 100644 (file)
 <context>
     <name>QObject</name>
     <message>
-        <location filename="ParametersPlugin_EvalListener.cpp" line="387"/>
+        <location filename="ParametersPlugin_EvalListener.cpp" line="392"/>
         <source>Warning</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="ParametersPlugin_EvalListener.cpp" line="388"/>
+        <location filename="ParametersPlugin_EvalListener.cpp" line="393"/>
         <source>Selected objects can be used in Part documents which are not loaded: %1. Whould you like to continue?</source>
         <translation type="unfinished"></translation>
     </message>