Salome HOME
22625: [CEA 1195] Several attractors per face
authoreap <eap@opencascade.com>
Tue, 5 Aug 2014 11:29:02 +0000 (15:29 +0400)
committereap <eap@opencascade.com>
Tue, 5 Aug 2014 11:29:02 +0000 (15:29 +0400)
   1) Use "minimal of all sizes" approach to size maps superposing
   2) Fix removal of attractors

idl/BLSURFPlugin_Algorithm.idl
src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx
src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx
src/BLSURFPlugin/BLSURFPlugin_Hypothesis.hxx
src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.cxx
src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.hxx
src/GUI/BLSURFPluginGUI_HypothesisCreator.cxx
src/GUI/BLSURFPluginGUI_HypothesisCreator.h

index 7cc9833ab0c0ea78eeb627c73b86982f61bbd153..830cf4fc84a538dceef50031dbc620c0c085942f 100644 (file)
@@ -361,7 +361,8 @@ module BLSURFPlugin
      * Set/unset an attractor given as geom object on another geom object
      */
     void         SetAttractorGeom(in GEOM::GEOM_Object GeomObj, in GEOM::GEOM_Object AttractorShape, in double StartSize, in double EndSize, in double ActionRadius, in double ConstantRadius);
-    void         UnsetAttractorGeom(in GEOM::GEOM_Object GeomObj);
+    void         UnsetAttractorGeom(in GEOM::GEOM_Object GeomObj, in GEOM::GEOM_Object AttractorShape);
+    void         UnsetAttractorEntry(in string entry, in string attractor);
 
     /*!
      * Set an attractor given by entry on a geom object given by entry
index 559cb797980247ffc1dd7cc6222487d92db25702..4989987e82e905802212c3f29d5ae95a578725b1 100644 (file)
@@ -3305,15 +3305,15 @@ status_t size_on_surface(integer face_id, real *uv, real *size, void *user_data)
     // MESSAGE("List of attractor is not empty")
     // MESSAGE("Attractor empty : "<< FaceIndex2ClassAttractor[face_id]->Empty())
     real result = 0;
-    //result = 1e100;
+    result = 1e100;
     std::vector< BLSURFPlugin_Attractor* > & attVec = f2attVec->second;
     for ( size_t i = 0; i < attVec.size(); ++i )
     {
-      result += attVec[i]->GetSize(uv[0],uv[1]);
-      //result = Min( result, attVec[i]->GetSize(uv[0],uv[1]));
+      //result += attVec[i]->GetSize(uv[0],uv[1]);
+      result = Min( result, attVec[i]->GetSize(uv[0],uv[1]));
     }
-    *size = result / attVec.size(); // mean of sizes defined by all attractors
-    //*size = result;
+    //*size = result / attVec.size(); // mean of sizes defined by all attractors
+    *size = result;
   }
   else {
     // MESSAGE("List of attractor is empty !!!")
index 45600425748366978e922705ff0343831aacbf1d..2b555570644e653de6148d89f90a8ca041362743 100644 (file)
@@ -681,7 +681,8 @@ BLSURFPlugin_Hypothesis::TAttractorMap BLSURFPlugin_Hypothesis::GetClassAttracto
 //=======================================================================
 //function : ClearEntry
 //=======================================================================
-void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry)
+void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry,
+                                         const char * attEntry/*=0*/)
 {
  TSizeMap::iterator it  = _sizeMap.find( entry );
  
@@ -699,8 +700,10 @@ void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry)
      TAttractorMap::iterator it_clAt = _classAttractors.find( entry );
      if ( it_clAt != _classAttractors.end() ) {
        do {
-         _classAttractors.erase(it_clAt);
-         it_clAt = _classAttractors.find( entry );
+         if ( !attEntry || it_clAt->second->GetAttractorEntry() == attEntry )
+           _classAttractors.erase( it_clAt++ );
+         else
+           ++it_clAt;
        }
        while ( it_clAt != _classAttractors.end() );
        MESSAGE("_classAttractors.size() = "<<_classAttractors.size())
index 6b2660b51520a94a9969a64789b7f3ec33a2d9f5..0e10ac73e5a7954e79751f5b1c3e44ec9bd1af8f 100644 (file)
@@ -128,7 +128,7 @@ public:
   void SetVerbosity(int theVal);
   int GetVerbosity() const { return _verb; }
   
-  void ClearEntry(const std::string& entry);
+  void ClearEntry(const std::string& entry, const char * attEntry = 0);
   void ClearSizeMaps();
 
   void SetPreCADMergeEdges(bool theVal);
index 088b838355d7389a630cf924a2bf9ba8cd13e8d8..f59e470a4192094dabebd06799642acfb65e6194 100644 (file)
@@ -994,8 +994,8 @@ void BLSURFPlugin_Hypothesis_i::SetClassAttractorEntry(const char* entry, const
   }
   MESSAGE("ENGINE : SETATTRACTOR END ENTRY : " << entry);
   //if ( valueChanged )
-  SMESH::TPythonDump() << _this() << ".SetAttractorGeom("
-                       << entry << ", " << att_entry << ", "<<StartSize<<", "<<EndSize<<", "<<ActionRadius<<", "<<ConstantRadius<<" )";
+  SMESH::TPythonDump() << _this() << ".SetAttractorGeom( '"
+                       << entry << "', '" << att_entry << "', "<<StartSize<<", "<<EndSize<<", "<<ActionRadius<<", "<<ConstantRadius<<" )";
 }
 
 //=============================================================================
@@ -1274,32 +1274,44 @@ void BLSURFPlugin_Hypothesis_i::SetAttractorGeom(GEOM::GEOM_Object_ptr theFace,
   SetClassAttractorEntry( theFaceEntry.c_str(), theAttEntry.c_str(), StartSize, EndSize, ActionRadius, ConstantRadius);
 }
 
-void BLSURFPlugin_Hypothesis_i::UnsetAttractorGeom(GEOM::GEOM_Object_ptr theFace)
+void BLSURFPlugin_Hypothesis_i::UnsetAttractorGeom(GEOM::GEOM_Object_ptr theFace,
+                                                   GEOM::GEOM_Object_ptr theAttractor)
 {
   ASSERT(myBaseImpl);
-  string theFaceEntry;
-  theFaceEntry = theFace->GetStudyEntry();
+  CORBA::String_var theFaceEntry = theFace->GetStudyEntry();
+  CORBA::String_var theAttrEntry = theAttractor->GetStudyEntry();
   
-  GEOM::GEOM_Gen_ptr geomGen = SMESH_Gen_i::GetGeomEngine();
-  SMESH_Gen_i *smeshGen = SMESH_Gen_i::GetSMESHGen();
-  string aName;
+  // GEOM::GEOM_Gen_ptr geomGen = SMESH_Gen_i::GetGeomEngine();
+  // SMESH_Gen_i *smeshGen = SMESH_Gen_i::GetSMESHGen();
+  // string aName;
   
-  if (theFaceEntry.empty()) {
-    aName = "Face_";
-    aName += theFace->GetEntry();
-    SALOMEDS::SObject_wrap theSFace = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theFace, aName.c_str());
-    if (!theSFace->_is_nil())
-      theFaceEntry = theSFace->GetID();
-  }
-  if (theFaceEntry.empty())
+  // if (theFaceEntry.empty()) {
+  //   aName = "Face_";
+  //   aName += theFace->GetEntry();
+  //   SALOMEDS::SObject_wrap theSFace = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theFace, aName.c_str());
+  //   if (!theSFace->_is_nil())
+  //     theFaceEntry = theSFace->GetID();
+  // }
+  if ( !theFaceEntry.in() || !theFaceEntry[0] ||
+       !theAttrEntry.in() || !theAttrEntry[0] )
     THROW_SALOME_CORBA_EXCEPTION( "Geom object is not published in study" ,SALOME::BAD_PARAM );
   
   MESSAGE("IDL : GetName : " << theFace->GetName());
   MESSAGE("IDL : UNSETATTRACTOR ( "<< theFaceEntry << ")");
-  UnsetEntry( theFaceEntry.c_str());
-  SMESH::TPythonDump() << _this() << ".UnsetAttractorGeom( " << theFaceEntry.c_str() << " )";
+  GetImpl()->ClearEntry( theFaceEntry.in(), theAttrEntry.in() );
+  SMESH::TPythonDump() << _this() << ".UnsetAttractorGeom( "
+                       << theFace << ", " << theAttractor << " )";
 }
 
+void BLSURFPlugin_Hypothesis_i::UnsetAttractorEntry(const char* faceEntry,
+                                                    const char* attractorEntry)
+{
+  GetImpl()->ClearEntry( faceEntry, attractorEntry );
+  SMESH::TPythonDump() << _this() << ".UnsetAttractorEntry( '"
+                       << faceEntry << "', '" << attractorEntry << "' )";
+}
+
+
 /*
  void BLSURFPlugin_Hypothesis_i::SetCustomSizeMap(GEOM::GEOM_Object_ptr GeomObj, const char* sizeMap)
  {}
index cd573b4ed308970d7e67124e262fbce1fcba602c..7832e7fedc43fbbf7d96814c6e099a957a8314fe 100644 (file)
@@ -168,8 +168,10 @@ public:
   
   void SetAttractorGeom(GEOM::GEOM_Object_ptr GeomObj, GEOM::GEOM_Object_ptr Attractor, CORBA::Double StartSize, CORBA::Double EndSize, CORBA::Double ActionRadius, CORBA::Double ConstantRadius );
 
-  void UnsetAttractorGeom(GEOM::GEOM_Object_ptr GeomObj);
+  void UnsetAttractorGeom(GEOM::GEOM_Object_ptr GeomObj,
+                          GEOM::GEOM_Object_ptr theAttractor);
 
+  void UnsetAttractorEntry(const char* entry, const char* attractor);
   void SetClassAttractorEntry(const char* entry, const char* att_entry, CORBA::Double StartSize, CORBA::Double EndSize, CORBA::Double ActionRadius, CORBA::Double ConstantRadius)  throw (SALOME::SALOME_Exception);
 
   BLSURFPlugin::TAttParamsMap* GetAttractorParams();
@@ -294,7 +296,7 @@ public:
     throw (SALOME::SALOME_Exception);
 
   void AddEdgePeriodicity(GEOM::GEOM_Object_ptr theFace1, GEOM::GEOM_Object_ptr theEdge1,
-                         GEOM::GEOM_Object_ptr theFace2, GEOM::GEOM_Object_ptr theEdge2, CORBA::Long edge_orientation = 0)
+                          GEOM::GEOM_Object_ptr theFace2, GEOM::GEOM_Object_ptr theEdge2, CORBA::Long edge_orientation = 0)
       throw (SALOME::SALOME_Exception);
 
   void AddEdgePeriodicityWithoutFaces(GEOM::GEOM_Object_ptr theEdge1, GEOM::GEOM_Object_ptr theEdge2, CORBA::Long edge_orientation = 0)
index ba14abb30a76e4dc0f84adcd8fd5bf1a01d1db35..662fa38e6006fc40c39eb36669fce043b8096c06 100644 (file)
@@ -2342,12 +2342,16 @@ bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesi
           const TAttractorVec& attVec = myATTMap[entry];
           for ( size_t i = 0; i < attVec.size(); ++i )
           {
-            h->SetClassAttractorEntry( entry.toLatin1().constData(),
-                                       attVec[i].attEntry.c_str(),
-                                       attVec[i].startSize,
-                                       h->GetPhySize(),
-                                       attVec[i].infDist,
-                                       attVec[i].constDist );
+            if ( attVec[i].IsToDelete() )
+              h->UnsetAttractorEntry( entry.toLatin1().constData(),
+                                      attVec[i].attEntry.c_str() );
+            else
+              h->SetClassAttractorEntry( entry.toLatin1().constData(),
+                                         attVec[i].attEntry.c_str(),
+                                         attVec[i].startSize,
+                                         h->GetPhySize(),
+                                         attVec[i].infDist,
+                                         attVec[i].constDist );
           }
         }
         else {
@@ -2962,12 +2966,30 @@ void BLSURFPluginGUI_HypothesisCreator::onRemoveMap()
   while ( it.hasPrevious() ) {
       item = it.previous();
       QString entry = item->data(SMP_ENTRY_COLUMN, Qt::EditRole).toString();
+      QString parentEntry;
+      if ( QTreeWidgetItem* parent = item->parent() )
+        parentEntry = parent->data(SMP_ENTRY_COLUMN, Qt::EditRole).toString();
       if (that->mySMPMap.contains(entry))
+      {
         that->mySMPMap[entry] = "__TO_DELETE__";
+        if ( myATTMap.contains( entry ))
+        {
+          TAttractorVec& attVec = myATTMap[entry];
+          for ( size_t i = 0; i < attVec.size(); ++i )
+            attVec[i].SetToDelete();
+        }          
+      }
+      else if ( mySMPMap.contains( parentEntry ) && myATTMap.contains( parentEntry ))
+      {
+        TAttractorVec& attVec = myATTMap[parentEntry];
+        for ( size_t i = 0; i < attVec.size(); ++i )
+        {
+          if ( entry == attVec[i].attEntry.c_str() )
+            attVec[i].SetToDelete();
+        }
+      }
       if (that->mySMPShapeTypeMap.contains(entry))
         that->mySMPShapeTypeMap.remove(entry);
-      if (that->myATTMap.contains(entry))
-        that->myATTMap.remove(entry);
       // if (that->myDistMap.contains(entry))
       //   that->myDistMap.remove(entry);
       // if (that->myAttDistMap.contains(entry))
@@ -3226,11 +3248,28 @@ bool BLSURFPluginGUI_HypothesisCreator::insertAttractor(GEOM::GEOM_Object_var aF
     //     return false;
     //   }
     // }
-    item = new QTreeWidgetItem();
+    int rowToChange = findRowFromEntry(shapeEntry);
+    if ( rowToChange < mySizeMapTable->topLevelItemCount() )
+    {
+      item = mySizeMapTable->topLevelItem( rowToChange );
+    }
+    else {
+      item = new QTreeWidgetItem();
+      mySizeMapTable->addTopLevelItem(item);
+    }
     child = new QTreeWidgetItem();
-    mySizeMapTable->addTopLevelItem(item);
     item->addChild(child);
-    myATTMap[shapeEntry].push_back( attParams );
+    bool exists = false;
+    TAttractorVec & attVec = myATTMap[shapeEntry];
+    for ( size_t i = 0; i < attVec.size(); ++i )
+      if ( attVec[i].attEntry == attEntry )
+      {
+        attVec[i] = attParams;
+        exists = true;
+        break;
+      }
+    if ( !exists )
+      myATTMap[shapeEntry].push_back( attParams );
   }
   mySMPMap.insert(shapeEntry,sizeMap);
   mySMPShapeTypeMap.insert(shapeEntry,shapeType);
@@ -3420,13 +3459,13 @@ CORBA::Object_var BLSURFPluginGUI_HypothesisCreator::entryToObject(QString entry
 }
 
 int BLSURFPluginGUI_HypothesisCreator::findRowFromEntry(QString entry){
-  QString entryForChecking;
   int endRow = mySizeMapTable->topLevelItemCount()-1;
   int row = 0;
-  entryForChecking = mySizeMapTable->topLevelItem( row )->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
-  while (entry != entryForChecking && row <= endRow){
-    row++;
-    entryForChecking = mySizeMapTable->topLevelItem( row )->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
+  for ( ; row <= endRow; ++row )
+  {
+    QString entryForChecking = mySizeMapTable->topLevelItem( row )->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
+    if (entry == entryForChecking )
+      break;
   }
   MESSAGE("BLSURFPluginGUI_HypothesisCreator::findRowFromEntry; row = "<<row<<" , endRow ="<<endRow)
   return row;
index cfeb7c623e96e7ead8e4ad0c05a86b40586ce1d3..bc3c7a0cc6b1fcd757fe53e28fa501dd084e79e9 100644 (file)
@@ -126,6 +126,8 @@ struct TAttractor{
       infDist( theInfDist ),
       constDist( theConstDist )
   {}
+  void SetToDelete() { startSize = -1; }
+  bool IsToDelete() const { return startSize < 0; }
 };
 typedef std::vector< TAttractor > TAttractorVec;