]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
#20441 Visualization of faces found
authorJérôme <jerome.lucas@cesgenslab.fr>
Tue, 8 Dec 2020 17:05:14 +0000 (18:05 +0100)
committerJérôme <jerome.lucas@cesgenslab.fr>
Tue, 8 Dec 2020 17:05:14 +0000 (18:05 +0100)
13 files changed:
src/FeaturesAPI/FeaturesAPI_SharedFaces.cpp
src/FeaturesAPI/FeaturesAPI_SharedFaces.h
src/FeaturesPlugin/CMakeLists.txt
src/FeaturesPlugin/FeaturesPlugin_CommonSharedFaces.cpp [new file with mode: 0644]
src/FeaturesPlugin/FeaturesPlugin_CommonSharedFaces.h [new file with mode: 0644]
src/FeaturesPlugin/FeaturesPlugin_GroupSharedFaces.cpp [new file with mode: 0644]
src/FeaturesPlugin/FeaturesPlugin_GroupSharedFaces.h [new file with mode: 0644]
src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp
src/FeaturesPlugin/FeaturesPlugin_SharedFaces.cpp
src/FeaturesPlugin/FeaturesPlugin_SharedFaces.h
src/FeaturesPlugin/plugin-Features.xml
src/FeaturesPlugin/shared_Faces_macro_widget.xml [new file with mode: 0644]
src/FeaturesPlugin/shared_Faces_widget.xml [new file with mode: 0644]

index a0ebb84dc0f25e2cfcd661a3141aabdebf63bc6b..92b09330e08bfcfe383197268deb84d30d92f854 100644 (file)
@@ -19,8 +19,7 @@
 
 #include "FeaturesAPI_SharedFaces.h"
 
-#include <FeaturesPlugin_SharedFaces.h>
-#include <ModelAPI_AttributeDoubleArray.h>
+#include <FeaturesPlugin_GroupSharedFaces.h>
 #include <ModelHighAPI_Services.h>
 #include <ModelHighAPI_Tools.h>
 
@@ -37,20 +36,17 @@ FeaturesAPI_SharedFaces::
 }
 
 //=================================================================================================
-FeaturesAPI_SharedFaces::FeaturesAPI_SharedFaces(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+FeaturesAPI_SharedFaces::FeaturesAPI_SharedFaces(
+                         const std::shared_ptr<ModelAPI_Feature>& theFeature,
                          const ModelHighAPI_Selection& theobject,
-                         const double theTransparency,
+                         const ModelHighAPI_Integer& theTransparency,
                          const std::string & theNameGroup)
 :ModelHighAPI_Interface(theFeature)
 {
   if (initialize()) {
     fillAttribute(theobject, myobjectselected);
     fillAttribute(theTransparency, mytransparency);
-    if (theNameGroup != "") {
-      fillAttribute(true,
-                feature()->boolean(FeaturesPlugin_SharedFaces::CREATE_GROUP_ID()));
-      fillAttribute(theNameGroup, mygroupname);
-    }
+    fillAttribute(theNameGroup, mygroupname);
     execute();
   }
 }
@@ -67,25 +63,22 @@ void FeaturesAPI_SharedFaces::dump(ModelHighAPI_Dumper& theDumper) const
   const std::string& aDocName = theDumper.name(aBase->document());
 
   AttributeSelectionPtr anAttrObject;
-    anAttrObject = aBase->selection(FeaturesPlugin_SharedFaces::OBJECT_ID());
+    anAttrObject = aBase->selection(FeaturesPlugin_GroupSharedFaces::OBJECT_ID());
 
   theDumper << aBase << " = model.getSharedFaces(" << aDocName << ", " << anAttrObject;
-  theDumper << ", " << aBase->integer(FeaturesPlugin_SharedFaces::TRANSPARENCY_ID());
-
-  if (aBase->boolean(FeaturesPlugin_SharedFaces::CREATE_GROUP_ID())->value())
-    theDumper << ", " << aBase->string(FeaturesPlugin_SharedFaces::GROUP_NAME_ID());
-
+  theDumper << ", " << aBase->integer(FeaturesPlugin_GroupSharedFaces::TRANSPARENCY_ID());
+  theDumper << ", " << aBase->string(FeaturesPlugin_GroupSharedFaces::GROUP_NAME_ID());
   theDumper << ")" << std::endl;
 }
 
 //=================================================================================================
 SharedFacesPtr getSharedFaces(const std::shared_ptr<ModelAPI_Document>& thePart,
                               const ModelHighAPI_Selection& theobject,
-                              const double theTransparency,
+                              const ModelHighAPI_Integer& theTransparency,
                               const std::string & theNameGroup)
 {
 
-  FeaturePtr aFeature = thePart->addFeature(FeaturesPlugin_SharedFaces::ID());
+  FeaturePtr aFeature = thePart->addFeature(FeaturesPlugin_GroupSharedFaces::ID());
 
   SharedFacesPtr aSharedFaces;
 
index e97f8e35f39198c5e07a77049599e09be65a4198..001a1cbc3a5f879948f7c4981a392ddb640485c1 100644 (file)
@@ -22,8 +22,9 @@
 
 #include "FeaturesAPI.h"
 
-#include "FeaturesPlugin_SharedFaces.h"
+#include "FeaturesPlugin_GroupSharedFaces.h"
 
+#include <ModelHighAPI_Integer.h>
 #include <ModelHighAPI_Interface.h>
 #include <ModelHighAPI_Macro.h>
 
@@ -45,21 +46,21 @@ public:
   FEATURESAPI_EXPORT
   explicit FeaturesAPI_SharedFaces(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                                    const ModelHighAPI_Selection& theobject,
-                                   const double theTransparency,
-                                  const std::string & theNameGroup);
+                                   const ModelHighAPI_Integer& theTransparency,
+                                   const std::string & theNameGroup);
 
   /// Destructor.
   FEATURESAPI_EXPORT
   virtual ~FeaturesAPI_SharedFaces();
 
-    INTERFACE_3(FeaturesPlugin_SharedFaces::ID(),
-              objectselected, FeaturesPlugin_SharedFaces::OBJECT_ID(),
+    INTERFACE_3(FeaturesPlugin_GroupSharedFaces::ID(),
+               objectselected, FeaturesPlugin_GroupSharedFaces::OBJECT_ID(),
                               ModelAPI_AttributeSelection,
                               /** object selected*/,
-              transparency, FeaturesPlugin_SharedFaces::TRANSPARENCY_ID(),
+               transparency, FeaturesPlugin_GroupSharedFaces::TRANSPARENCY_ID(),
                               ModelAPI_AttributeInteger,
                               /** transparency*/,
-              groupname, FeaturesPlugin_SharedFaces::GROUP_NAME_ID(),
+               groupname, FeaturesPlugin_GroupSharedFaces::GROUP_NAME_ID(),
                               ModelAPI_AttributeString,
                               /** group name*/)
 
@@ -79,7 +80,7 @@ typedef std::shared_ptr<FeaturesAPI_SharedFaces> SharedFacesPtr;
 FEATURESAPI_EXPORT
 SharedFacesPtr getSharedFaces(const std::shared_ptr<ModelAPI_Document>& thePart,
                               const ModelHighAPI_Selection& theObject,
-                              const double theTransparency = 0.0,
-                              const std::string & theNameGroup = "");
+                              const ModelHighAPI_Integer& theTransparency,
+                              const std::string & theNameGroup);
 
 #endif // FeaturesAPI_SharedFaces_H_
index 3ab09b9b5af0919828cdccc63a06b9c4bd242482..c94d57e7d6481aaa031474567fa0926219c6914f 100644 (file)
@@ -24,7 +24,6 @@ INCLUDE(UseQtExt)
 # additional include directories
 INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src/GeomDataAPI
                      ${PROJECT_SOURCE_DIR}/src/Locale
-                     ${PROJECT_SOURCE_DIR}/src/PrimitivesPlugin
                      ${QT_INCLUDES})
 
 # additional preprocessor / compiler flags
@@ -71,6 +70,8 @@ SET(PROJECT_HEADERS
     FeaturesPlugin_Fillet1D.h
     FeaturesPlugin_Measurement.h
     FeaturesPlugin_SharedFaces.h
+    FeaturesPlugin_CommonSharedFaces.h
+    FeaturesPlugin_GroupSharedFaces.h
     FeaturesPlugin_FusionFaces.h
     FeaturesPlugin_RemoveResults.h
     FeaturesPlugin_Chamfer.h
@@ -120,6 +121,8 @@ SET(PROJECT_SOURCES
     FeaturesPlugin_Fillet1D.cpp
     FeaturesPlugin_Measurement.cpp
     FeaturesPlugin_SharedFaces.cpp
+    FeaturesPlugin_CommonSharedFaces.cpp
+    FeaturesPlugin_GroupSharedFaces.cpp
     FeaturesPlugin_FusionFaces.cpp
     FeaturesPlugin_RemoveResults.cpp
     FeaturesPlugin_Chamfer.cpp
@@ -158,7 +161,8 @@ SET(XML_RESOURCES
   fillet_widget.xml
   fillet1d_widget.xml
   measurement_widget.xml
-  sharedFaces_widget.xml
+  shared_Faces_widget.xml
+  shared_Faces_macro_widget.xml
   fusion_faces_widget.xml
   chamfer_widget.xml
   copy_widget.xml
diff --git a/src/FeaturesPlugin/FeaturesPlugin_CommonSharedFaces.cpp b/src/FeaturesPlugin/FeaturesPlugin_CommonSharedFaces.cpp
new file mode 100644 (file)
index 0000000..0cd9bc0
--- /dev/null
@@ -0,0 +1,122 @@
+// Copyright (C) 2018-2020  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "FeaturesPlugin_CommonSharedFaces.h"
+
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_Attribute.h>
+
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
+#include <Locale_Convert.h>
+
+#include <GeomAlgoAPI_CompoundBuilder.h>
+
+#include <Config_PropManager.h>
+
+#include <GeomAlgoAPI_ShapeTools.h>
+#include <GeomAlgoAPI_SharedFaces.h>
+#include <GeomAPI_ShapeIterator.h>
+#include <ModelAPI_Tools.h>
+#include <iomanip>
+#include <sstream>
+
+
+//=================================================================================================
+void FeaturesPlugin_CommonSharedFaces::updateFaces()
+{
+  AttributeSelectionPtr ancompSolidAttr =
+              std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(attributObject());
+
+  AttributeSelectionListPtr aFacesListAttr =
+                  std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>
+                                                      (attributListFaces());
+
+  if (aFacesListAttr->isInitialized())
+        aFacesListAttr->clear();
+
+  GeomShapePtr aShape = ancompSolidAttr->value();
+  if (aShape.get() && ancompSolidAttr->context().get()) {
+
+    aShape = ancompSolidAttr->context()->shape();
+    if (aShape) {
+      std::string anError;
+      ListOfShape aFaces;
+      ListOfShape theShapes;
+
+      theShapes.push_back(aShape);
+      if (!GetSharedFaces(theShapes,
+                          aFaces,
+                          false,
+                          anError))
+        setError("Error in GetSharedFaces calculation :" +  anError);
+
+      aFacesListAttr->setSelectionType("face");
+
+      ListOfShape::const_iterator anIt = aFaces.cbegin();
+      for(; anIt != aFaces.cend(); ++anIt) {
+
+        GeomShapePtr aFacePtr = *anIt;
+
+        if (!aFacePtr.get()) {
+          setError("GetSharedFaces : An invalid face found " +  anError);
+        }
+        aFacesListAttr->append( ancompSolidAttr->context(), aFacePtr);
+      }
+      std::stringstream alabel;
+      alabel << "Number of shared faces : " << aFacesListAttr->size();
+      AttributeStringPtr aNumberFacesAttr =
+                  std::dynamic_pointer_cast<ModelAPI_AttributeString>
+                                                      (attributNumberFaces());
+      aNumberFacesAttr->setValue( alabel.str() );
+
+    }
+  }
+}
+
+//=================================================================================================
+void FeaturesPlugin_CommonSharedFaces::setFacesGroup(const std::wstring& theName )
+{
+  std::vector<int> aColor;
+  ResultGroupPtr aGroup = document()->createGroup(data());
+  // clean the result of the operation
+  aGroup->data()->setName(theName);
+  aGroup->store(GeomShapePtr());
+
+  // shapes containing in group
+  ListOfShape aFaces;
+  AttributeSelectionListPtr aFacesListAttr =
+                    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>
+                                                        (attributListFaces());
+
+  for (int anI =0; anI< aFacesListAttr->size(); anI++) {
+    AttributeSelectionPtr aAtt = aFacesListAttr->value(anI);
+    aFaces.push_back( aAtt->value() );
+  }
+  GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aFaces);
+
+  aGroup->store(aCompound);
+  aColor = {255,0,0};
+  setResult(aGroup);
+  ModelAPI_Tools::setColor( lastResult(),aColor);
+}
+
diff --git a/src/FeaturesPlugin/FeaturesPlugin_CommonSharedFaces.h b/src/FeaturesPlugin/FeaturesPlugin_CommonSharedFaces.h
new file mode 100644 (file)
index 0000000..dabe7c7
--- /dev/null
@@ -0,0 +1,63 @@
+// Copyright (C) 2018-2020  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef FeaturesPlugin_CommonSharedFaces_H_
+#define FeaturesPlugin_CommonSharedFaces_H_
+
+#include "FeaturesPlugin.h"
+#include <ModelAPI_Attribute.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_ResultGroup.h>
+
+#include <GeomAPI_IPresentable.h>
+#include <GeomAPI_IScreenParams.h>
+
+
+/// \class FeaturesPlugin_CommonSharedFaces
+/// \ingroup Plugins
+/// \brief Feature to check the shared faces of solid
+
+class FeaturesPlugin_CommonSharedFaces : public ModelAPI_Feature
+{
+public:
+
+  /// Performs the algorithm and stores results it in the data structure.
+  FEATURESPLUGIN_EXPORT virtual void execute(){};
+
+  /// Return Attribut values of result.
+  virtual AttributePtr attributObject() = 0;
+
+  /// Return Attribut values of result.
+  virtual AttributePtr attributListFaces() = 0;
+
+  /// Return Attribut values of result.
+  virtual AttributePtr attributNumberFaces() = 0;
+
+  protected:
+  FeaturesPlugin_CommonSharedFaces() {}
+
+  //Set group of faces
+  void setFacesGroup(const std::wstring& theName );
+
+  // Update the list of faces
+  void updateFaces();
+
+};
+
+#endif
diff --git a/src/FeaturesPlugin/FeaturesPlugin_GroupSharedFaces.cpp b/src/FeaturesPlugin/FeaturesPlugin_GroupSharedFaces.cpp
new file mode 100644 (file)
index 0000000..53b576e
--- /dev/null
@@ -0,0 +1,125 @@
+// Copyright (C) 2018-2020  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "FeaturesPlugin_GroupSharedFaces.h"
+
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeInteger.h>
+#include <ModelAPI_Attribute.h>
+
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
+#include <Locale_Convert.h>
+
+#include <GeomAlgoAPI_CompoundBuilder.h>
+
+#include <Config_PropManager.h>
+#include <ModelAPI_ResultBody.h>
+#include <GeomAlgoAPI_ShapeTools.h>
+#include <GeomAPI_ShapeIterator.h>
+#include <ModelAPI_Tools.h>
+#include <iomanip>
+#include <sstream>
+
+//=================================================================================================
+FeaturesPlugin_GroupSharedFaces::FeaturesPlugin_GroupSharedFaces()
+{
+}
+
+//=================================================================================================
+void FeaturesPlugin_GroupSharedFaces::initAttributes()
+{
+  // attribute for object selected
+  data()->addAttribute(OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
+  AttributeSelectionListPtr aList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(
+    data()->addAttribute(LIST_FACES_ID(), ModelAPI_AttributeSelectionList::typeId()));
+
+  data()->addAttribute(NUMBER_FACES_ID(), ModelAPI_AttributeString::typeId());
+  data()->addAttribute(TRANSPARENCY_ID(), ModelAPI_AttributeInteger::typeId());
+  data()->addAttribute(GROUP_NAME_ID(), ModelAPI_AttributeString::typeId());
+
+}
+
+
+//=================================================================================================
+AttributePtr FeaturesPlugin_GroupSharedFaces::attributObject()
+{
+  return attribute(OBJECT_ID());
+}
+
+//=================================================================================================
+AttributePtr FeaturesPlugin_GroupSharedFaces::attributListFaces()
+{
+  return attribute(LIST_FACES_ID());
+}
+
+//=================================================================================================
+AttributePtr FeaturesPlugin_GroupSharedFaces::attributNumberFaces()
+{
+  return attribute(NUMBER_FACES_ID());
+}
+
+//=================================================================================================
+void FeaturesPlugin_GroupSharedFaces::execute()
+{
+  if ( selectionList(LIST_FACES_ID())->isInitialized()
+    && string(GROUP_NAME_ID())->value() != "") {
+    AttributeStringPtr aNameAtt = string( GROUP_NAME_ID() ) ;
+    std::wstring aNameFace = aNameAtt->isUValue() ?
+                            Locale::Convert::toWString(aNameAtt->valueU()) :
+                            Locale::Convert::toWString(aNameAtt->value());
+
+    if (lastResult().get())
+      eraseResultFromList(lastResult());
+    setFacesGroup(aNameFace);
+
+  } else {
+    if (lastResult().get()) {
+      eraseResultFromList(lastResult());
+    }
+
+  }
+  if (selection(OBJECT_ID())->isInitialized()) {
+    AttributeSelectionPtr ancompSolidAttr = selection(OBJECT_ID());
+    ResultPtr aResult = ancompSolidAttr->context();
+
+    double aTranparency = integer(TRANSPARENCY_ID())->value()/100.0;
+    ModelAPI_Tools::setTransparency(aResult, aTranparency);
+
+    ResultBodyPtr aResultBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
+    std::list<ResultPtr> allRes;
+    ModelAPI_Tools::allSubs(aResultBody, allRes);
+    std::list<ResultPtr>::iterator aRes;
+    for(aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
+      ModelAPI_Tools::setTransparency(*aRes, aTranparency);
+    }
+  }
+}
+
+//=================================================================================================
+void FeaturesPlugin_GroupSharedFaces::attributeChanged(const std::string& theID)
+{
+  if (theID == OBJECT_ID()) {
+    updateFaces();
+  }
+}
\ No newline at end of file
diff --git a/src/FeaturesPlugin/FeaturesPlugin_GroupSharedFaces.h b/src/FeaturesPlugin/FeaturesPlugin_GroupSharedFaces.h
new file mode 100644 (file)
index 0000000..ff7273e
--- /dev/null
@@ -0,0 +1,105 @@
+// Copyright (C) 2018-2020  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef FeaturesPlugin_GroupSharedFaces_H_
+#define FeaturesPlugin_GroupSharedFaces_H_
+
+#include <FeaturesPlugin_CommonSharedFaces.h>
+
+/// \class FeaturesPlugin_GroupSharedFaces
+/// \ingroup Plugins
+/// \brief Feature to check the shared faces of solid
+
+class FeaturesPlugin_GroupSharedFaces : public FeaturesPlugin_CommonSharedFaces
+{
+public:
+   inline static const std::string& ID()
+  {
+    static const std::string MY_ID("Shared_faces");
+    return MY_ID;
+  }
+
+  /// \return the kind of a feature.
+  virtual const std::string& getKind()
+  {
+    return ID();
+  }
+
+  /// Attribute name for object selected.
+  inline static const std::string& OBJECT_ID()
+  {
+    static const std::string MY_OBJECT_ID("main_object");
+    return MY_OBJECT_ID;
+  }
+
+  /// Attribute name for number of faces.
+  inline static const std::string& NUMBER_FACES_ID()
+  {
+    static const std::string MY_NUMBER_FACES_ID("number_shared_faces");
+    return MY_NUMBER_FACES_ID;
+  }
+
+  /// Attribute name for z coodinate.
+  inline static const std::string& LIST_FACES_ID()
+  {
+    static const std::string MY_LIST_FACES_ID("faces");
+    return MY_LIST_FACES_ID;
+  }
+
+    /// Attribute name for transparency.
+  inline static const std::string& TRANSPARENCY_ID()
+  {
+    static const std::string MY_TRANSPARENCY_ID("transparency");
+    return MY_TRANSPARENCY_ID;
+  }
+
+  /// Attribute name for group name.
+  inline static const std::string& GROUP_NAME_ID()
+  {
+    static const std::string MY_GROUP_NAME_ID("group_name");
+    return MY_GROUP_NAME_ID;
+  }
+
+  /// Performs the algorithm and stores results it in the data structure.
+  FEATURESPLUGIN_EXPORT virtual void execute();
+
+  /// Request for initialization of data model of the feature: adding all attributes
+  FEATURESPLUGIN_EXPORT virtual void initAttributes();
+
+  /// Called on change of any argument-attribute of this object
+  /// \param theID identifier of changed attribute
+  FEATURESPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
+
+  /// Use plugin manager for features creation
+  FeaturesPlugin_GroupSharedFaces();
+
+  private:
+
+  /// Return Attribut values of object.
+  virtual AttributePtr attributObject();
+
+  /// Return Attribut values of list of faces.
+  virtual AttributePtr attributListFaces();
+
+  /// Return Attribut values of number of faces.
+  virtual AttributePtr attributNumberFaces();
+
+};
+
+#endif
index 7f6ef48f3ad4c15e3742efd789d81ad08ff487d1..7926794c46c75dd2a953fa6ca7c7b5618fabe2ef 100644 (file)
@@ -34,6 +34,7 @@
 #include <FeaturesPlugin_Intersection.h>
 #include <FeaturesPlugin_Measurement.h>
 #include <FeaturesPlugin_SharedFaces.h>
+#include <FeaturesPlugin_GroupSharedFaces.h>
 #include <FeaturesPlugin_MultiRotation.h>
 #include <FeaturesPlugin_MultiTranslation.h>
 #include <FeaturesPlugin_Partition.h>
@@ -190,6 +191,8 @@ FeaturePtr FeaturesPlugin_Plugin::createFeature(std::string theFeatureID)
     return FeaturePtr(new FeaturesPlugin_Measurement);
   } else if (theFeatureID == FeaturesPlugin_SharedFaces::ID()) {
     return FeaturePtr(new FeaturesPlugin_SharedFaces);
+  } else if (theFeatureID == FeaturesPlugin_GroupSharedFaces::ID()) {
+    return FeaturePtr(new FeaturesPlugin_GroupSharedFaces);
   } else if (theFeatureID == FeaturesPlugin_RemoveResults::ID()) {
     return FeaturePtr(new FeaturesPlugin_RemoveResults);
   } else if (theFeatureID == FeaturesPlugin_Chamfer::ID()) {
index 718b163563969568d237c1d9ae4dff5cda6421bc..e80ecf1a3030a0bf588b12dc5a615315fd947c9e 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "FeaturesPlugin_SharedFaces.h"
 
+#include <FeaturesPlugin_GroupSharedFaces.h>
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeBoolean.h>
@@ -63,28 +64,59 @@ void FeaturesPlugin_SharedFaces::initAttributes()
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), GROUP_NAME_ID());
 }
 
+
+//=================================================================================================
+AttributePtr FeaturesPlugin_SharedFaces::attributObject()
+{
+  return attribute(OBJECT_ID());
+}
+
+//=================================================================================================
+AttributePtr FeaturesPlugin_SharedFaces::attributListFaces()
+{
+  return attribute(LIST_FACES_ID());
+}
+
+//=================================================================================================
+AttributePtr FeaturesPlugin_SharedFaces::attributNumberFaces()
+{
+  return attribute(NUMBER_FACES_ID());
+}
+
 //=================================================================================================
 void FeaturesPlugin_SharedFaces::execute()
 {
-  if (boolean(CREATE_GROUP_ID())->value()
-    && selectionList(LIST_FACES_ID())->isInitialized()
-    && string(GROUP_NAME_ID())->value() != "") {
-    AttributeStringPtr aNameAtt = string( GROUP_NAME_ID() ) ;
-    std::wstring aNameFace = aNameAtt->isUValue() ?
-                            Locale::Convert::toWString(aNameAtt->valueU()) :
-                            Locale::Convert::toWString(aNameAtt->value());
-
-    if (myGroup.get())
-      eraseResults();
-    setFacesGroup(aNameFace);
+  if (boolean(CREATE_GROUP_ID())->value()) {
 
-  } else {
-    if (myGroup.get()) {
-      eraseResults();
-      myGroup.reset();
+    if ( string(GROUP_NAME_ID())->value() != ""
+      && selectionList(LIST_FACES_ID())->isInitialized()) {
+
+      if (lastResult().get()) {
+        eraseResultFromList(lastResult());
+      }
+
+      if (!myCreateGroupFeature.get())
+        createGroup();
+      updateGroup();
     }
 
+  } else {
+    if (selectionList(LIST_FACES_ID())->isInitialized()) {
+
+      if (myCreateGroupFeature.get()) {
+        myCreateGroupFeature->eraseResults();
+        SessionPtr aSession = ModelAPI_Session::get();
+        DocumentPtr aDoc =  aSession->activeDocument();
+        aDoc->removeFeature(myCreateGroupFeature);
+        myCreateGroupFeature.reset();
+      }
+
+      if (lastResult().get())
+        eraseResultFromList(lastResult());
+      setFacesGroup(L"Group_SharedFaces");
+    }
   }
+
   if (selection(OBJECT_ID())->isInitialized()) {
     AttributeSelectionPtr ancompSolidAttr = selection(OBJECT_ID());
     ResultPtr aResult = ancompSolidAttr->context();
@@ -106,76 +138,38 @@ void FeaturesPlugin_SharedFaces::execute()
 void FeaturesPlugin_SharedFaces::attributeChanged(const std::string& theID)
 {
   if (theID == OBJECT_ID()) {
-    AttributeSelectionPtr ancompSolidAttr = selection(OBJECT_ID());
-
-    GeomShapePtr aShape = ancompSolidAttr->value();
-    if (aShape.get() && ancompSolidAttr->context().get()) {
-
-      aShape = ancompSolidAttr->context()->shape();
-      if (aShape) {
-        std::string anError;
-        ListOfShape aFaces;
-        ListOfShape theShapes;
-
-        theShapes.push_back(aShape);
-        if (!GetSharedFaces(theShapes,
-                               aFaces,
-                               false,
-                               anError))
-          setError("Error in GetSharedFaces calculation :" +  anError);
-
-        AttributeSelectionListPtr aFacesListAttr =
-                    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>
-                                                        (attribute(LIST_FACES_ID()));
-
-        if (aFacesListAttr->isInitialized())
-          aFacesListAttr->clear();
 
-        aFacesListAttr->setSelectionType("face");
+    updateFaces();
+    if (myCreateGroupFeature.get())
+      updateGroup();
+  }
+}
 
-        ListOfShape::const_iterator anIt = aFaces.cbegin();
-        for(; anIt != aFaces.cend(); ++anIt) {
 
-          GeomShapePtr aFacePtr = *anIt;
+//=================================================================================================
+void FeaturesPlugin_SharedFaces::createGroup()
+{
+  SessionPtr aSession = ModelAPI_Session::get();
 
-          if (!aFacePtr.get()) {
-            setError("GetSharedFaces : An invalid face found " +  anError);
-          }
-          aFacesListAttr->append( ancompSolidAttr->context(), aFacePtr);
-        }
-        std::stringstream alabel;
-        alabel << "Number of shared faces : " << aFacesListAttr->size();
-        string(NUMBER_FACES_ID() )->setValue( alabel.str() );
+  DocumentPtr aDoc =  aSession->activeDocument();
 
-      }
-    }
+  if (aDoc.get()) {
+    myCreateGroupFeature = aDoc->addFeature(FeaturesPlugin_GroupSharedFaces::ID());
   }
 }
 
 //=================================================================================================
-void FeaturesPlugin_SharedFaces::setFacesGroup(const std::wstring& theName )
+void FeaturesPlugin_SharedFaces::updateGroup()
 {
-  std::vector<int> aColor;
-  myGroup = document()->createGroup(data());
-  // clean the result of the operation
-  myGroup->data()->setName(theName);
-  myGroup->store(GeomShapePtr());
-
-  // shapes containing in group
-  ListOfShape aFaces;
-  AttributeSelectionListPtr aFacesListAttr =
-                    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>
-                                                        (attribute(LIST_FACES_ID()));
-
-  for (int anI =0; anI< aFacesListAttr->size(); anI++) {
-    AttributeSelectionPtr aAtt = aFacesListAttr->value(anI);
-    aFaces.push_back( aAtt->value() );
-  }
-  GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aFaces);
-  myGroup->store(aCompound);
-  aColor = {255,0,0};
-  setResult(myGroup);
-  ModelAPI_Tools::setColor( lastResult(),aColor);
+    myCreateGroupFeature->string(FeaturesPlugin_GroupSharedFaces::GROUP_NAME_ID())
+                          ->setValue( string(GROUP_NAME_ID())->value());
 
-}
+    myCreateGroupFeature->selection(FeaturesPlugin_GroupSharedFaces::OBJECT_ID())
+                          ->setValue( selection(OBJECT_ID())->context() ,
+                                      selection(OBJECT_ID())->value() );
+
+    myCreateGroupFeature->integer(FeaturesPlugin_GroupSharedFaces::TRANSPARENCY_ID())
+                          ->setValue( integer(TRANSPARENCY_ID())->value());
 
+    myCreateGroupFeature->execute();
+}
\ No newline at end of file
index 7c865445e144d2c79e68f5f676f5cd86e076884e..995ef77906fdcf91cb08ee7342086a740fc1da73 100644 (file)
 #ifndef FeaturesPlugin_SharedFaces_H_
 #define FeaturesPlugin_SharedFaces_H_
 
-#include "FeaturesPlugin.h"
-#include <ModelAPI_Feature.h>
-#include <ModelAPI_ResultGroup.h>
-
-#include <GeomAPI_IPresentable.h>
-#include <GeomAPI_IScreenParams.h>
-#include <GeomAlgoAPI_Box.h>
+#include <FeaturesPlugin_CommonSharedFaces.h>
 
 /// \class FeaturesPlugin_SharedFaces
 /// \ingroup Plugins
 /// \brief Feature to check the shared faces of solid
 
-class FeaturesPlugin_SharedFaces : public ModelAPI_Feature
+class FeaturesPlugin_SharedFaces : public FeaturesPlugin_CommonSharedFaces
 {
 public:
    inline static const std::string& ID()
   {
-    static const std::string MY_ID("Shared_faces");
+    static const std::string MY_ID("Shared_faces_macro");
     return MY_ID;
   }
 
@@ -99,15 +93,32 @@ public:
   /// \param theID identifier of changed attribute
   FEATURESPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
 
+  /// Reimplemented from ModelAPI_Feature::isMacro(). Returns true.
+  FEATURESPLUGIN_EXPORT virtual bool isMacro() const { return true; }
+
   /// Use plugin manager for features creation
   FeaturesPlugin_SharedFaces();
 
   private:
 
-  //Set group of faces
-  void setFacesGroup(const std::wstring& theName );
+  /// Return Attribut values of object.
+  virtual AttributePtr attributObject();
+
+  /// Return Attribut values of list of faces.
+  virtual AttributePtr attributListFaces();
+
+  /// Return Attribut values of number of faces.
+  virtual AttributePtr attributNumberFaces();
+
+  /// Create group
+  void createGroup();
+
+  /// Update group
+  void updateGroup();
+
+  /// Feature to create group
+  FeaturePtr myCreateGroupFeature;
 
-  ResultGroupPtr myGroup;
 };
 
 #endif
index 0d01b06594a70c485b50365332a9ddb05e7f46c2..808e7b9b3b998b2c44c12c518166e0e81f1f82de 100644 (file)
       </feature>
     </group>
     <group id="Face">
-      <feature id="Shared_faces" title="Check shared faces" tooltip="Check the shared faces" auto_preview="true"
+      <feature id="Shared_faces_macro" title="Check shared faces" tooltip="Check the shared faces" auto_preview="true"
                icon="icons/Features/shared_shapes.png" helpfile="checkSharedFaceFeature.html"> 
-        <source path="sharedFaces_widget.xml"/>
+        <source path="shared_Faces_macro_widget.xml"/>
+      </feature>
+      <feature id="Shared_faces" title="Check shared faces" tooltip="Check the shared faces" auto_preview="true"
+               icon="icons/Features/shared_shapes.png" helpfile="checkSharedFaceFeature.html" internal="1"> 
+        <source path="shared_Faces_widget.xml"/>
       </feature>
     </group>
   </workbench>
diff --git a/src/FeaturesPlugin/shared_Faces_macro_widget.xml b/src/FeaturesPlugin/shared_Faces_macro_widget.xml
new file mode 100644 (file)
index 0000000..960c960
--- /dev/null
@@ -0,0 +1,34 @@
+<source>
+  <shape_selector id="main_object"
+                  label="Object"
+                  tooltip="Select a object"
+                  shape_types="compsolid compsolid object"
+                  default=""
+                  geometrical_selection="true">
+    <validator id="PartSet_DifferentObjects"/>
+    <validator id="GeomValidators_ShapeType" parameters="compsolid,compound"/>
+  </shape_selector>
+  <groupbox title="Shared faces">
+    <label id="number_shared_faces"/>
+    <multi_selector id="faces"
+                      label="Liste of faces :"
+                      icon=""
+                      shape_types="faces"
+                      Block_selection = "true"
+                      use_choice="false">
+          <validator id="PartSet_DifferentObjects"/>
+          <validator id="GeomValidators_ShapeType" parameters="faces"/>
+    </multi_selector>
+  </groupbox>
+  <integervalue id="transparency"
+                    label="Transparency"
+                    min="0"
+                    max="100"
+                    step="10"
+                    default="50">
+  </integervalue>
+  <optionalbox id="create_group" title="Create group" show_title="true">
+    <stringvalue id="group_name" label="Group Name"/>
+    <label/>
+  </optionalbox>
+</source>
diff --git a/src/FeaturesPlugin/shared_Faces_widget.xml b/src/FeaturesPlugin/shared_Faces_widget.xml
new file mode 100644 (file)
index 0000000..97d8b7d
--- /dev/null
@@ -0,0 +1,31 @@
+<source>
+  <shape_selector id="main_object"
+                  label="Object"
+                  tooltip="Select a object"
+                  shape_types="compsolid compsolid object"
+                  default=""
+                  geometrical_selection="true">
+    <validator id="PartSet_DifferentObjects"/>
+    <validator id="GeomValidators_ShapeType" parameters="compsolid,compound"/>
+  </shape_selector>
+  <groupbox title="Shared faces">
+    <label id="number_shared_faces"/>
+    <multi_selector id="faces"
+                      label="Liste of faces :"
+                      icon=""
+                      shape_types="faces"
+                      Block_selection = "true"
+                      use_choice="false">
+          <validator id="PartSet_DifferentObjects"/>
+          <validator id="GeomValidators_ShapeType" parameters="faces"/>
+    </multi_selector>
+  </groupbox>
+  <integervalue id="transparency"
+                    label="Transparency"
+                    min="0"
+                    max="100"
+                    step="10"
+                    default="50">
+  </integervalue>
+  <stringvalue id="group_name" label="Group Name"/>
+</source>