Salome HOME
Merge branch 'Dev_0.6.1' of newgeom:newgeom into Dev_0.6.1
authornds <natalia.donis@opencascade.com>
Mon, 29 Dec 2014 13:55:31 +0000 (16:55 +0300)
committernds <natalia.donis@opencascade.com>
Mon, 29 Dec 2014 13:55:31 +0000 (16:55 +0300)
src/GeomAPI/GeomAPI_AISObject.cpp
src/Model/Model_AttributeSelection.cpp
src/Model/Model_AttributeSelection.h
src/Model/Model_AttributeSelectionList.cpp
src/Model/Model_AttributeSelectionList.h
src/ModelAPI/ModelAPI_AttributeSelection.h
src/ModelAPI/ModelAPI_AttributeSelectionList.h
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.h
src/XGUI/XGUI_pictures.qrc
src/XGUI/pictures/copy.png [new file with mode: 0644]

index a2b39e45217fcb1ae3427531db1eb20ffab599a0..6be05290b1d06ac86d6ad5cc2c7f8c252ea6cc94 100644 (file)
@@ -274,6 +274,7 @@ void GeomAPI_AISObject::setWidth(const double& theWidth)
   if (anAIS.IsNull())
     return;
   anAIS->SetWidth(theWidth);
+  anAIS->Redisplay();
 }
 
 void GeomAPI_AISObject::setColor(int theR, int theG, int theB)
index 3df579de17660cedec7a07f43350f50602274cfe..fa96b0ce6f60d4a01b4dfe2112ecbf951075833c 100644 (file)
@@ -63,7 +63,7 @@ Standard_GUID kSIMPLE_REF_ID("635eacb2-a1d6-4dec-8348-471fae17cb29");
 // TDataStd_IntPackedMap - indexes of edges in composite element (for construction)
 // TDataStd_Integer - type of the selected shape (for construction)
 // TDF_Reference - from ReferenceAttribute, the context
-
+#define DDDD 1
 void Model_AttributeSelection::setValue(const ResultPtr& theContext,
   const std::shared_ptr<GeomAPI_Shape>& theSubShape)
 {
@@ -94,7 +94,11 @@ void Model_AttributeSelection::setValue(const ResultPtr& theContext,
   std::string aSelName = namingName();
   if(!aSelName.empty())
          TDataStd_Name::Set(selectionLabel(), aSelName.c_str()); //set name
-
+#ifdef DDDD
+  //####
+  //selectSubShape("FACE",  "Extrusion_1/LateralFace_3");
+  //selectSubShape("FACE",  "Extrusion_1/TopFace");
+#endif
   myIsInitialized = true;
   owner()->data()->sendAttributeUpdated(this);
 }
@@ -696,3 +700,136 @@ std::string Model_AttributeSelection::namingName()
   }
   return aName;
 }
+
+TopAbs_ShapeEnum translateType (const std::string& theType)
+{
+  TCollection_AsciiString aStr(theType.c_str());
+  aStr.UpperCase();
+  if(aStr.IsEqual("COMP"))
+       return TopAbs_COMPOUND;
+  else if(aStr.IsEqual("COMS"))
+       return TopAbs_COMPSOLID;
+  else if(aStr.IsEqual("SOLD"))
+       return TopAbs_SOLID;
+  else if(aStr.IsEqual("SHEL"))
+       return TopAbs_SHELL;
+  else if(aStr.IsEqual("FACE"))
+       return TopAbs_FACE;
+  else if(aStr.IsEqual("WIRE"))
+       return TopAbs_WIRE;
+  else if(aStr.IsEqual("EDGE"))
+       return TopAbs_EDGE;
+  else if(aStr.IsEqual("VERT"))
+       return TopAbs_VERTEX;  
+
+  return TopAbs_SHAPE;
+}
+
+const TopoDS_Shape getShapeFromCompound(const std::string& theSubShapeName, const TopoDS_Shape& theCompound)
+{
+  TopoDS_Shape aSelection;
+  std::string::size_type n = theSubShapeName.rfind('/');                       
+  if (n == std::string::npos) n = 0;
+       std::string aSubString = theSubShapeName.substr(n + 1);
+       n = aSubString.rfind('_');
+       if (n == std::string::npos) return aSelection;
+       aSubString = aSubString.substr(n+1);
+       int indx = atoi(aSubString.c_str());
+       TopoDS_Iterator it(theCompound);                        
+       for (int i = 1;it.More();it.Next(), i++) {
+         if(i == indx) {                         
+           aSelection = it.Value();                      
+           break;
+         }
+         else continue;                                                
+       }
+  return aSelection;   
+}
+
+const TopoDS_Shape findFaceByName(const std::string& theSubShapeName, std::shared_ptr<Model_Document> theDoc)
+{
+  TopoDS_Shape aFace;
+  std::string::size_type n, nb = theSubShapeName.rfind('/');                   
+  if (nb == std::string::npos) nb = 0;
+  std::string aSubString = theSubShapeName.substr(nb + 1);
+  n = aSubString.rfind('_');
+  if (n != std::string::npos) {
+         std::string aSubStr2 = aSubString.substr(0, n);
+       aSubString  = theSubShapeName.substr(0, nb + 1);
+       aSubString = aSubString + aSubStr2;     
+  } else
+       aSubString = theSubShapeName;
+                               
+  const TDF_Label& aLabel = theDoc->findNamingName(aSubString);
+  if(aLabel.IsNull()) return aFace;
+  Handle(TNaming_NamedShape) aNS;
+  if(aLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS)) {
+       const TopoDS_Shape& aShape = aNS->Get();
+       if(!aShape.IsNull()) {
+         if(aShape.ShapeType() == TopAbs_COMPOUND) 
+           aFace = getShapeFromCompound(theSubShapeName, aShape);
+         else 
+               aFace = aShape;   
+       }
+  }
+  return aFace;
+}
+
+int ParseEdgeName(const std::string& theSubShapeName)
+{
+  int n = theSubShapeName.find('|');
+  if (n == std::string::npos) return 0;
+  std::string aName = theSubShapeName.substr(0, n); //name of face
+  std::string aSubString = theSubShapeName.substr(n + 1);
+  //...
+}
+// type ::= COMP | COMS | SOLD | SHEL | FACE | WIRE | EDGE | VERT
+void Model_AttributeSelection::selectSubShape(const std::string& theType, const std::string& theSubShapeName)
+{
+  if(theSubShapeName.empty() || theType.empty()) return;
+  TopAbs_ShapeEnum aType = translateType(theType);
+  ResultPtr aCont = context();
+  if(!aCont.get() || aCont->shape()->isNull()) return;
+  TopoDS_Shape aContext  = aCont->shape()->impl<TopoDS_Shape>();
+  TopAbs_ShapeEnum aContType = aContext.ShapeType();
+  if(aType <= aContType) return; // not applicable
+
+  std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(aCont->document());
+  TopoDS_Shape aSelection;
+  switch (aType) 
+  {
+  case TopAbs_COMPOUND:
+    break;
+  case TopAbs_COMPSOLID:
+    break;
+  case TopAbs_SOLID:
+    break;
+  case TopAbs_SHELL:
+    break;
+  case TopAbs_FACE:
+    {
+         const TopoDS_Shape aSelection = findFaceByName(theSubShapeName, aDoc);
+         if(!aSelection.IsNull()) {// Select it
+               std::shared_ptr<GeomAPI_Shape> aShapeToBeSelected(new GeomAPI_Shape());
+        aShapeToBeSelected->setImpl(new TopoDS_Shape(aSelection));
+               setValue(aCont, aShapeToBeSelected);
+         }
+       }
+    break;
+  case TopAbs_WIRE:
+       break;
+  case TopAbs_EDGE:
+       {
+      TopTools_ListOfShape aList;
+         std::list<std::string> aListofNames;
+         //ParseEdgeName();
+
+       }
+    break;
+  case TopAbs_VERTEX:
+       break;
+  default: //TopAbs_SHAPE
+       return;
+  }
+
+}
index 74c77344d5daea843647d8d2c63ad4cf0d1f0d7c..4ca2ef3db2230fcd79ebd748144f3f6bce4ddf9e 100644 (file)
@@ -42,6 +42,9 @@ public:
   /// Returns a textual string of the selection
   MODEL_EXPORT virtual std::string namingName();
 
+  /// Selects (i.e. creates Naming data structure) of sub-shape specifed by textual name
+  MODEL_EXPORT virtual void selectSubShape(const std::string& theType, const std::string& theSubShapeName);
+
 protected:
   /// Objects are created for features automatically
   MODEL_EXPORT Model_AttributeSelection(TDF_Label& theLabel);
@@ -50,6 +53,7 @@ protected:
   /// Performs the selection for the body result (TNaming selection)
   virtual void selectBody(
     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape);
+
   /// Performs the selection for the construction result (selection by index)
   virtual void selectConstruction(
     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape);
index 14a684a96657ff7f13443ac8dc4ef9bff83ccc9a..0643a520bb91a23e620d37c64fefe8413ba3da90 100644 (file)
@@ -11,6 +11,7 @@
 #include "Model_Data.h"
 
 #include <TDF_ChildIterator.hxx>
+#include <TopAbs_ShapeEnum.hxx>
 
 using namespace std;
 
@@ -30,6 +31,35 @@ void Model_AttributeSelectionList::append(
   owner()->data()->sendAttributeUpdated(this);
 }
 
+void Model_AttributeSelectionList::append(std::string theNamingName)
+{
+  int aNewTag = mySize->Get() + 1;
+  TDF_Label aNewLab = mySize->Label().FindChild(aNewTag);
+
+  std::shared_ptr<Model_AttributeSelection> aNewAttr = 
+    std::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aNewLab));
+  if (owner()) {
+    aNewAttr->setObject(owner());
+  }
+  mySize->Set(aNewTag);
+  TopAbs_ShapeEnum aType = (TopAbs_ShapeEnum)selectionType();
+  string aTypeName;
+  switch(aType) {
+  case TopAbs_VERTEX: aTypeName = "VERT"; break;
+  case TopAbs_EDGE: aTypeName = "EDGE"; break;
+  case TopAbs_WIRE: aTypeName = "WIRE"; break;
+  case TopAbs_FACE: aTypeName = "FACE"; break;
+  case TopAbs_SHELL: aTypeName = "SHEL"; break;
+  case TopAbs_SOLID: aTypeName = "SOLD"; break;
+  case TopAbs_COMPOUND: aTypeName = "COMP"; break;
+  case TopAbs_COMPSOLID: aTypeName = "COMS"; break;
+  default: 
+    return; // invalid case => empty new attribute
+  };
+  aNewAttr->selectSubShape(aTypeName, theNamingName);
+  owner()->data()->sendAttributeUpdated(this);
+}
+
 int Model_AttributeSelectionList::size()
 {
   return mySize->Get();
index dcfc8b85dae803f39ec4c4022b844b31871a4d06..fdae79ee6a9c7b73b3d1ebf4bb978d15b246b794 100644 (file)
@@ -29,6 +29,10 @@ public:
   MODEL_EXPORT virtual void append(
     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape);
 
+  /// Adds the new reference to the end of the list by the naming name of the selected shape
+  /// The type of shape is taken from the current selection type
+  MODEL_EXPORT virtual void append(std::string theNamingName);
+
   /// Returns the number ofselection attributes in the list
   MODEL_EXPORT virtual int size();
 
index b562410252ee7c2f54b56e52bb9e34c6de5048bf..3778ecdd4d30acc48d75b552e9ebb62df3c67378 100644 (file)
@@ -48,8 +48,9 @@ class ModelAPI_AttributeSelection : public ModelAPI_Attribute
   virtual std::string namingName() = 0;
 
 
-  /// Selects sub-shape by Name
-  //virtual selectSubShape(const std::string& theSubShapeName, const std::string& theContextShapeName)
+  /// Selects sub-shape by the textual Name
+  virtual void selectSubShape(const std::string& theType, const std::string& theSubShapeName) = 0;
+
   /// To virtually destroy the fields of successors
   virtual ~ModelAPI_AttributeSelection()
   {
index fec280f37ece835150537c58ec98a6e44d01ffd7..dbcdb0bc9561f6327881f863137b4300744bb272 100644 (file)
@@ -23,6 +23,10 @@ class ModelAPI_AttributeSelectionList : public ModelAPI_Attribute
   virtual void append(const ResultPtr& theContext,
                       const GeomShapePtr& theSubShape) = 0;
 
+  /// Adds the new reference to the end of the list by the naming name of the selected shape
+  /// The type of shape is taken from the current selection type
+  virtual void append(std::string theNamingName) = 0;
+
   /// Returns the number ofselection attributes in the list
   virtual int size() = 0;
 
index 4204870979762d92365ea481ea3a52fefba947d7..114a76748d716bd951d53f499582f9875ac3bd2e 100644 (file)
@@ -25,6 +25,9 @@
 #include <QString>
 #include <QComboBox>
 #include <QEvent>
+#include <QAction>
+#include <QApplication>
+#include <QClipboard>
 
 #include <memory>
 #include <string>
@@ -64,6 +67,14 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen
   //TODO_END
   connect(myTypeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onSelectionTypeChanged()));
 
+  myCopyAction = new QAction(QIcon(":pictures/copy.png"), tr("Copy"), this);
+  myCopyAction->setShortcut(QKeySequence::Copy);
+  myCopyAction->setEnabled(false);
+  connect(myCopyAction, SIGNAL(triggered(bool)), SLOT(onCopyItem()));
+  myListControl->addAction(myCopyAction);
+  myListControl->setContextMenuPolicy(Qt::ActionsContextMenu);
+  connect(myListControl, SIGNAL(itemSelectionChanged()), SLOT(onListSelection()));
+
   activateSelection(true);
 }
 
@@ -261,3 +272,27 @@ void ModuleBase_WidgetMultiSelector::updateSelectionList(AttributeSelectionListP
     myListControl->addItem(aAttr->namingName().c_str());
   }
 }
+
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::onCopyItem()
+{
+  QList<QListWidgetItem*> aItems = myListControl->selectedItems();
+  QString aRes;
+  foreach(QListWidgetItem* aItem, aItems) {
+    if (!aRes.isEmpty())
+      aRes += "\n";
+    aRes += aItem->text();
+  }
+  if (!aRes.isEmpty()) {
+    QClipboard *clipboard = QApplication::clipboard();
+    clipboard->setText(aRes);
+  }
+}
+
+//********************************************************************
+void ModuleBase_WidgetMultiSelector::onListSelection()
+{
+  QList<QListWidgetItem*> aItems = myListControl->selectedItems();
+  myCopyAction->setEnabled(!aItems.isEmpty());
+}
+
index 47f08a5e683efd1f4696894f6df17029ab6e171e..111b27f0d8a5e487e043b1e1e50c2d3de09033e0 100644 (file)
@@ -29,6 +29,7 @@ class QWidget;
 class QListWidget;
 class QComboBox;
 class ModuleBase_IWorkshop;
+class QAction;
 
 class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_ModelWidget
 {
@@ -61,6 +62,10 @@ class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_Model
   void onSelectionTypeChanged();
   void onSelectionChanged();
 
+protected slots:
+  void onCopyItem();
+  void onListSelection();
+
  protected:
   void filterShapes(const NCollection_List<TopoDS_Shape>& theShapesToFilter,
                     NCollection_List<TopoDS_Shape>& theResult);
@@ -83,6 +88,8 @@ class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_Model
 
   typedef QPair<ResultPtr, GeomShapePtr> GeomSelection;
   QList<GeomSelection> mySelection;
+
+  QAction* myCopyAction;
 };
 
 #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */
index b7c79dd9bb6456e486649959355613b1dbc57bb7..3176442f64049a911497746232d405bbe7f120aa 100644 (file)
@@ -8,6 +8,7 @@
      <file>pictures/undo.png</file>
      <file>pictures/rebuild.png</file>
      <file>pictures/preferences.png</file>
+     <file>pictures/copy.png</file>
      
      <file>pictures/params_folder.png</file>
      <file>pictures/constr_folder.png</file>
diff --git a/src/XGUI/pictures/copy.png b/src/XGUI/pictures/copy.png
new file mode 100644 (file)
index 0000000..12968bf
Binary files /dev/null and b/src/XGUI/pictures/copy.png differ