Salome HOME
0021209: Bug GetInPlace with faces. Integrate self-intersections checker.
[modules/geom.git] / src / EntityGUI / EntityGUI_SketcherDlg.cxx
index 5e9b3b1775e63fc47692d9f3f33ffd9c306219a5..e3ec23f224823ad4dc1eac56f1284259edb9cdc7 100644 (file)
@@ -28,6 +28,9 @@
 #include "EntityGUI_Widgets.h"
 #include <SalomeApp_DoubleSpinBox.h>
 
+#include <OCCViewer_ViewPort3d.h>
+#include <OCCViewer_ViewWindow.h>
+
 #include <GEOMBase.h>
 #include <GeometryGUI.h>
 #include <GEOMImpl_Types.hxx>
@@ -77,6 +80,7 @@ EntityGUI_SketcherDlg::EntityGUI_SketcherDlg( GeometryGUI* GUI, QWidget* parent,
     myGeometryGUI( GUI ),
     myLineWidth( lineWidth )
 {
+  SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
   setModal( modal );
   setAttribute( Qt::WA_DeleteOnClose );
 
@@ -87,19 +91,23 @@ EntityGUI_SketcherDlg::EntityGUI_SketcherDlg( GeometryGUI* GUI, QWidget* parent,
   topLayout->setMargin( 9 ); topLayout->setSpacing( 6 );
 
   MainWidget->buttonCancel->setText( tr( "GEOM_BUT_CANCEL" ) );
-  MainWidget->buttonEnd->setText( tr( "GEOM_BUT_END_SKETCH" ) );
+  MainWidget->buttonEnd->setText( tr( "GEOM_BUT_CLOSE" ) );
   MainWidget->buttonClose->setText( tr( "GEOM_BUT_CLOSE_SKETCH" ) );
   MainWidget->buttonHelp->setText( tr( "GEOM_BUT_HELP" ) );
 
-  QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
-  QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_UNDO" ) ) );
-  QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_REDO" ) ) );
+  QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT"      ) ) );
+  QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_UNDO"    ) ) );
+  QPixmap image2( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_REDO"    ) ) );
+  QPixmap image3( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_LINE_2P" ) ) );
+  QPixmap image4( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_ARC"     ) ) );
 
   setWindowTitle( tr( "GEOM_SKETCHER_TITLE" ) );
 
   MainWidget->GroupConstructors->setTitle( tr( "GEOM_SKETCHER_EL" ) );
-  MainWidget->RadioButton1->setText( tr( "GEOM_SKETCHER_SEGMENT" ) );
-  MainWidget->RadioButton2->setText( tr( "GEOM_SKETCHER_ARC" ) );
+  MainWidget->RadioButton1->setText( "" );
+  MainWidget->RadioButton1->setIcon( image3 );
+  MainWidget->RadioButton2->setText( "" );
+  MainWidget->RadioButton2->setIcon( image4 );
   MainWidget->GroupDest->setTitle( tr( "GEOM_SKETCHER_DEST" ) );
   MainWidget->GroupDest1->setTitle( tr( "GEOM_SKETCHER_TYPE" ) );
   MainWidget->RB_Dest1->setText( tr( "GEOM_SKETCHER_POINT" ) );
@@ -149,7 +157,7 @@ EntityGUI_SketcherDlg::EntityGUI_SketcherDlg( GeometryGUI* GUI, QWidget* parent,
 
   GroupD2 = new EntityGUI_Dir2( MainWidget->DestCnt );
 
-  GroupD2->GroupDir2->setTitle( tr( "GEOM_SKETCHER_DIR" ) );
+  GroupD2->GroupDir2->setTitle( tr( "GEOM_SKETCHER_DIST" ) );
   GroupD2->RB_Dir21->setText( tr( "GEOM_SKETCHER_LENGTH" ) );
   GroupD2->RB_Dir22->setText( tr( "GEOM_SKETCHER_X" ) );
   GroupD2->RB_Dir23->setText( tr( "GEOM_SKETCHER_Y" ) );
@@ -344,7 +352,6 @@ EntityGUI_SketcherDlg::~EntityGUI_SketcherDlg()
 //=================================================================================
 bool EntityGUI_SketcherDlg::eventFilter (QObject* object, QEvent* event)
 {
-  MESSAGE("EntityGUI_SketcherDlg::eventFilter")
   if (event->type() == QEvent::KeyPress) {
     QKeyEvent* ke = (QKeyEvent*)event;
     if ( ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter ) {
@@ -454,6 +461,8 @@ void EntityGUI_SketcherDlg::InitClick()
   Group2Spin->hide();
   Group3Spin->hide();
   Group4Spin->hide();
+  globalSelection(); // close local selection to clear it
+  localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
 }
 
 
@@ -969,7 +978,7 @@ void EntityGUI_SketcherDlg::ClickOnEnd()
       myCommand.append( ":WW" );
   }
   else {
-    // PAL16008 (Sketcher Validation should be equal to Apply&Close)
+    /*// PAL16008 (Sketcher Validation should be equal to Apply&Close)
     if ( ( Group1Spin->buttonApply->isEnabled() && Group1Spin->isVisible() ) ||
          ( Group2Spin->buttonApply->isEnabled() && Group2Spin->isVisible() ) ||
          ( Group3Spin->buttonApply->isEnabled() && Group3Spin->isVisible() ) ||
@@ -978,7 +987,7 @@ void EntityGUI_SketcherDlg::ClickOnEnd()
          ( Group2Sel->buttonApply->isEnabled()  && Group2Sel->isVisible()  ) ||
          ( Group1Sel1Spin->buttonApply->isEnabled() && Group1Sel1Spin->isVisible() ) )  {     
       ClickOnApply();
-    }
+    }*/
     myIsAllAdded = true;
   }
 
@@ -1038,7 +1047,7 @@ bool EntityGUI_SketcherDlg::ClickOnApply()
     (Group4Spin->SpinBox_DX)->setFocus();
     (Group4Spin->SpinBox_DX)->selectAll();
   }
-
+  
   return true;
 }
 
@@ -1519,19 +1528,37 @@ void EntityGUI_SketcherDlg::OnPointSelected(Qt::KeyboardModifiers modifiers, con
 {
   MESSAGE("EntityGUI_SketcherDlg::OnPointSelected")
   
+  SUIT_ViewWindow*       theViewWindow  = getDesktop()->activeWindow();
+  OCCViewer_ViewPort3d*  vp             = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
+  QString                theImgFileName = vp->backgroundImageFilename();
+  
   double x, y;
   x = y = 0;
   
-  autoApply = ( getPnt2ConstructorId() == 1 && false );  // If no additional argument needed after selection
-                                                         // -> apply automatically --> disabled for now
+  BRepBuilderAPI_MakeVertex mkVertex (thePnt);
+  TopoDS_Shape aShape = mkVertex.Shape();
+  
+  // Taking into account LocalCS
+  gp_Ax3 aWPlane = GetActiveLocalCS();
+  gp_Trsf aTrans;
+
+  aTrans.SetTransformation(aWPlane);
+  BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False);
+  aShape = aTransformation.Shape();
+  
+  gp_Pnt aTrsfPnt; 
+  GEOMBase::VertexToPoint( aShape, aTrsfPnt );
+  
+  autoApply = ( (getPnt2ConstructorId() == 1) && (!theImgFileName.isEmpty()) );  // If no additional argument needed after selection and there is a backgroundimage
+                                                                                 // -> apply automatically 
   
   if ( getPnt1ConstructorId() == 0 ){                    // Relative selection mode
-    x = thePnt.X() - myLastX1;
-    y = thePnt.Y() - myLastY1;
+    x = aTrsfPnt.X() - myLastX1;
+    y = aTrsfPnt.Y() - myLastY1;
   }
   else {
-    x = thePnt.X();
-    y = thePnt.Y();
+    x = aTrsfPnt.X();
+    y = aTrsfPnt.Y();
   }
   switch (getPnt2ConstructorId()){
     case 1:
@@ -2296,20 +2323,29 @@ void EntityGUI_SketcherDlg::displayPntPreview(const double x,
                                               bool update
                                              )
 {
+  // Get globalCS and working plane
+  gp_Ax3 globalCS = myLCSList.first(); //gp_Ax3(aOrigin, aDirZ, aDirX);
+  gp_Ax3 aWPlane  = GetActiveLocalCS();
+  
+  // Build point in localCS
   gp_Pnt aPnt = gp_Pnt(x,y,0.0);
+  
+  // Get transfomation from local to global CS
+  gp_Trsf aTrans;
+  aTrans.SetTransformation(aWPlane, globalCS);
+  
   BRepBuilderAPI_MakeVertex mkVertex (aPnt);
-  TopoDS_Shape aVertex = mkVertex.Shape();
+  TopoDS_Shape aLocalVertex = mkVertex.Shape();
   
-  // Disable activation of selection
-  getDisplayer()->SetToActivate( false );
+  // Perform transformation
+  BRepBuilderAPI_Transform aTransformation (aLocalVertex, aTrans, Standard_False);
+  TopoDS_Shape aGlobalVertex = aTransformation.Shape();
   
-  // Build prs
-  SALOME_Prs* aPrs = getDisplayer()->BuildPrs( aVertex );
+  // Build prs with vertex in globalCS
+  SALOME_Prs* aPrs = getDisplayer()->BuildPrs( aGlobalVertex );
   if ( aPrs != 0 && !aPrs->IsNull() )
     GEOMBase_Helper::displayPreview( aPrs, append, update );
   
-  // Enable back activation of selection
-  getDisplayer()->SetToActivate( true );
 }
 
 //================================================================