Salome HOME
Fix compilation error (conflict of OK name between OCCT Plate_Plate.hxx and GEOM...
[modules/geom.git] / src / EntityGUI / EntityGUI_FeatureDetectorDlg.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 9ac38a3..2a684aa
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -26,7 +26,8 @@
 
 // SALOME includes
 #include "EntityGUI_FeatureDetectorDlg.h"
-#include <ShapeRec_FeatureDetector.hxx>
+#include "ShapeRec_FeatureDetector.hxx"
+#include "GEOM_Constants.h"
 
 #include <OCCViewer_ViewWindow.h>
 #include <OCCViewer_ViewManager.h>
 #include <LightApp_Application.h>
 #include <LightApp_SelectionMgr.h>
 
-#include <SALOME_ListIteratorOfListIO.hxx>
+#include <SALOME_ListIO.hxx>
 
 #include <SalomeApp_Study.h>
 
+#include <Basics_OCCTVersion.hxx>
+
 #include <utilities.h>
 #include <Precision.hxx>
 
 #include <BRepBuilderAPI_MakePolygon.hxx>
 #include <BRepBuilderAPI_Transform.hxx>
 
-#include <AIS_TexturedShape.hxx>
+#include <AIS_Shape.hxx>
+
 #include <TCollection_AsciiString.hxx>
-#include <StdSelect_DisplayMode.hxx>
+//#include <StdSelect_DisplayMode.hxx>
 
 #include <Graphic3d_MaterialAspect.hxx>
 
 #include <utility>
 
 // boost includes
+#include <boost/version.hpp>
+#if BOOST_VERSION < 106700
 #include <boost/utility.hpp>
+#else
+#include <boost/next_prior.hpp>
+#endif
 
 // Constructors
-enum{
+enum {
   CONTOURS,
   CORNERS,
   LINES
 };
 
-enum {
-  RADIO_BUTTONS,
-  MSG,
-  PUSH_BUTTON,
-};
-
 enum {
   KERNEL_SIZE,
   FIND_CONTOURS_METHOD,
@@ -286,7 +289,7 @@ EntityGUI_FeatureDetectorDlg::EntityGUI_FeatureDetectorDlg( GeometryGUI* theGeom
   // about what will be considered INSIDE the zone we want to find the frontier of
   // This makes the algorithm more robust against a bit inhomogeneous parts in the zone
   // that we want to delimitate.
-  // The drawback is if we want to delimitate a zone wich color is very similar to the zone
+  // The drawback is if we want to delimitate a zone which color is very similar to the zone
   // we consider as the OUTSIDE, the result will be bad.
   // The current use cases are more of the first form : 
   //  - Strongly contrasted INSIDE and OUTSIDE zones
@@ -404,9 +407,8 @@ void EntityGUI_FeatureDetectorDlg::SelectionIntoArgument()
 {
   
   // TODO supprimer les lignes qui ne servent à rien le cas échéant
-  SUIT_ViewWindow*       theViewWindow  = getDesktop()->activeWindow();
-  std::map< std::string , std::vector<Handle(AIS_InteractiveObject)> >::iterator AISit;
-  SOCC_Viewer* soccViewer = (SOCC_Viewer*)(theViewWindow->getViewManager()->getViewModel());
+  //SUIT_ViewWindow*       theViewWindow  = getDesktop()->activeWindow();
+  //SOCC_Viewer* soccViewer = (SOCC_Viewer*)(theViewWindow->getViewManager()->getViewModel());
 
   if (!myEditCurrentArgument->isEnabled())
     return;
@@ -439,27 +441,23 @@ void EntityGUI_FeatureDetectorDlg::SelectionIntoArgument()
     
     if ( myEditCurrentArgument == mySelectionGroup->LineEdit1 ) {
       myFace = aSelectedObject;
-      AISit = soccViewer->entry2aisobjects.find(myFaceEntry.toStdString());
-      if (AISit == soccViewer->entry2aisobjects.end())
+
+      SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
+      if ( !study ) return;
+      LightApp_Application* app = ::qobject_cast<LightApp_Application*>( study->application() );
+      if ( !app ) return;
+      SUIT_ViewManager* vm = app->activeViewManager();
+      if ( !vm ) return;
+      PropMap propMap = study->getObjectProperties( vm->getGlobalId(), myFaceEntry );
+      QString theImgFileName = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
+      if ( theImgFileName.isEmpty() )
         return;
-      
-      Handle(AIS_InteractiveObject) myAIS = (*AISit).second[0];
-      Handle(GEOM_AISShape) myAISShape;
-      if( myAIS->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) {
-        myAISShape = Handle(GEOM_AISShape)::DownCast( myAIS );
-      }
-      else
-        return ;
-      
-      std::string theImgFileName = myAISShape->TextureFile();      
-      if ( theImgFileName == "" )
-        return ;
 
       // Setting the image caracteristics
-      myDetector->SetPath( theImgFileName );
+      myDetector->SetPath( theImgFileName.toStdString() );
       height            =  myDetector->GetImgHeight();
       width             =  myDetector->GetImgWidth();
-      pictureLeft       = -0.5 * width;              // X coordinate of the top left  corner of the background image in the view
+      pictureLeft       = -0.5 * width;              // X coordinate of the top left corner of the background image in the view
       pictureTop        =  0.5 * height;             // Y coordinate of both top corners
       
     } 
@@ -507,7 +505,7 @@ bool EntityGUI_FeatureDetectorDlg::ClickOnApply()
 //=================================================================================
 void EntityGUI_FeatureDetectorDlg::ConstructorsClicked(int id)
 {
-  MESSAGE("Constructor id ="<<id)
+  MESSAGE("Constructor id ="<<id);
   myConstructorId = id;
   switch (id)
   {
@@ -620,9 +618,10 @@ ShapeRec_Parameters* EntityGUI_FeatureDetectorDlg::parametersChanged()
     aCornersParameters->qualityLevel = (dynamic_cast<QDoubleSpinBox*>(myWidgets[QUALITY_LEVEL]))->value();
     aCornersParameters->minDistance  = (dynamic_cast<QDoubleSpinBox*>(myWidgets[MIN_DISTANCE]))->value();
     switch ( (dynamic_cast<QComboBox*>(myWidgets[TYPE_CRITERIA]))->currentIndex() ) {
-    case 0: aCornersParameters->typeCriteria = CV_TERMCRIT_ITER;
-    case 1: aCornersParameters->typeCriteria = CV_TERMCRIT_EPS;
-    case 2: aCornersParameters->typeCriteria = CV_TERMCRIT_ITER | CV_TERMCRIT_EPS;
+    case 0: aCornersParameters->typeCriteria = CV_TERMCRIT_ITER; break;
+    case 1: aCornersParameters->typeCriteria = CV_TERMCRIT_EPS; break;
+    case 2: aCornersParameters->typeCriteria = CV_TERMCRIT_ITER | CV_TERMCRIT_EPS; break;
+    default: break;
     }
     aCornersParameters->maxIter = (dynamic_cast<QSpinBox*>(myWidgets[MAX_ITER]))->value();
     aCornersParameters->epsilon = (dynamic_cast<QDoubleSpinBox*>(myWidgets[EPSILON]))->value();
@@ -672,7 +671,7 @@ ShapeRec_Parameters* EntityGUI_FeatureDetectorDlg::parametersChanged()
 void EntityGUI_FeatureDetectorDlg::setStartPnt(const gp_Pnt& theStartPnt)
 {
   myStartPnt = theStartPnt;
-  MESSAGE("myStartPnt = ("<<theStartPnt.X()<<", "<<theStartPnt.Y()<<")")
+  MESSAGE("myStartPnt = ("<<theStartPnt.X()<<", "<<theStartPnt.Y()<<")");
 }
 
 //=================================================================================
@@ -682,7 +681,7 @@ void EntityGUI_FeatureDetectorDlg::setStartPnt(const gp_Pnt& theStartPnt)
 void EntityGUI_FeatureDetectorDlg::setEndPnt(const gp_Pnt& theEndPnt)
 {
   myEndPnt = theEndPnt;
-  MESSAGE("myEndPnt = ("<<theEndPnt.X()<<", "<<theEndPnt.Y()<<")")
+  MESSAGE("myEndPnt = ("<<theEndPnt.X()<<", "<<theEndPnt.Y()<<")");
   if (setSelectionRect() && myDetector->GetImgHeight() > 0)
     showImageSample();
 }
@@ -729,7 +728,7 @@ void EntityGUI_FeatureDetectorDlg::showImageSample()
 //=================================================================================
 GEOM::GEOM_IOperations_ptr EntityGUI_FeatureDetectorDlg::createOperation()
 {
-  return myGeomGUI->GetGeomGen()->GetIShapesOperations( getStudyId() );
+  return myGeomGUI->GetGeomGen()->GetIShapesOperations();
 }
 
 //=================================================================================
@@ -740,7 +739,7 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects )
 {
   bool res = false;
   
-  GEOM::GEOM_IBasicOperations_var  aBasicOperations  = myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
+  GEOM::GEOM_IBasicOperations_var  aBasicOperations  = myGeomGUI->GetGeomGen()->GetIBasicOperations();
   GEOM::GEOM_IShapesOperations_var aShapesOperations = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
 
   ShapeRec_Parameters* parameters = parametersChanged();
@@ -801,7 +800,7 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects )
     }
     else if (myConstructorId == CONTOURS)
     {    
-      GEOM::GEOM_ICurvesOperations_var aCurveOperations = myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
+      GEOM::GEOM_ICurvesOperations_var aCurveOperations = myGeomGUI->GetGeomGen()->GetICurvesOperations();
 
       myDetector->ComputeContours( useROI, parameters );
       std::vector< std::vector<cv::Point> >   contours  = myDetector->GetContours();
@@ -815,10 +814,10 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects )
     
       bool insert;
     
-      MESSAGE("hierarchy.size() =" << hierarchy.size()) 
+      MESSAGE("hierarchy.size() =" << hierarchy.size());
       if ( hierarchy.size() < 1 ) {
-       getOperation()->SetErrorCode( "Impossible detected contours" );
-       return false;
+        getOperation()->SetErrorCode( "Impossible detected contours" );
+        return false;
       }
 
       for( ; idx >= 0; idx = hierarchy[idx][0])
@@ -859,11 +858,11 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects )
                 double u_v_det = (it->x - it_previous->x) * (it_next->y - it->y) - 
                                  (it->y - it_previous->y) * (it_next->x - it->x);
                                           
-                double norme_u = sqrt ( (it->x - it_previous->x)*(it->x - it_previous->x) +
-                                        (it->y - it_previous->y)*(it->y - it_previous->y) );
+                double norme_u = sqrt ( double(it->x - it_previous->x) * double(it->x - it_previous->x) +
+                                        double(it->y - it_previous->y) * double(it->y - it_previous->y) );
                 
-                double norme_v = sqrt ( (it->x - it_next->x)*(it->x - it_next->x) +
-                                        (it->y - it_next->y)*(it->y - it_next->y) );
+                double norme_v = sqrt ( double(it->x - it_next->x) * double(it->x - it_next->x) +
+                                        double(it->y - it_next->y) * double(it->y - it_next->y) );
                                                                                                 
                 double u_v_sinus = u_v_det / (norme_u * norme_v);
                 
@@ -954,3 +953,14 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects )
   
   return res;
 }
+
+//=================================================================================
+// function : getSourceObjects
+// purpose  : virtual method to get source objects
+//=================================================================================
+QList<GEOM::GeomObjPtr> EntityGUI_FeatureDetectorDlg::getSourceObjects()
+{
+  QList<GEOM::GeomObjPtr> res;
+  res << myFace;
+  return res;
+}