]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
change the control buttons for sphere widget
authorpkv <pkv@opencascade.com>
Fri, 25 Nov 2005 11:48:54 +0000 (11:48 +0000)
committerpkv <pkv@opencascade.com>
Fri, 25 Nov 2005 11:48:54 +0000 (11:48 +0000)
src/PIPELINE/VISU_SphereWidget.cxx
src/PIPELINE/VISU_SphereWidget.hxx

index c2b46a61c91f99e168d25391d003e47b3e887246..f242513cde68e71a58dbcaacadf18e98acd452c5 100755 (executable)
@@ -294,10 +294,10 @@ void VISU_SphereWidget::SetEnabled(int enabling)
     Interactor->AddObserver(vtkCommand::LeftButtonReleaseEvent, 
                             EventCallbackCommand,
                             Priority);
-    Interactor->AddObserver(vtkCommand::RightButtonPressEvent, 
+    Interactor->AddObserver(vtkCommand::MiddleButtonPressEvent, 
                             EventCallbackCommand,
                             Priority);
-    Interactor->AddObserver(vtkCommand::RightButtonReleaseEvent, 
+    Interactor->AddObserver(vtkCommand::MiddleButtonReleaseEvent, 
                             EventCallbackCommand,
                             Priority);
 
@@ -365,11 +365,11 @@ void VISU_SphereWidget::ProcessEvents(vtkObject* vtkNotUsed(object),
     case vtkCommand::LeftButtonReleaseEvent:
       self->OnLeftButtonUp();
       break;
-    case vtkCommand::RightButtonPressEvent:
-      self->OnRightButtonDown();
+    case vtkCommand::MiddleButtonPressEvent:
+      self->OnMiddleButtonDown();
       break;
-    case vtkCommand::RightButtonReleaseEvent:
-      self->OnRightButtonUp();
+    case vtkCommand::MiddleButtonReleaseEvent:
+      self->OnMiddleButtonUp();
       break;
     case vtkCommand::MouseMoveEvent:
       self->OnMouseMove();
@@ -379,10 +379,10 @@ void VISU_SphereWidget::ProcessEvents(vtkObject* vtkNotUsed(object),
   }
 }
 //====================================================================
-// function:OnRightButtonDown
+// function:OnMiddleButtonDown
 // purpose:
 //====================================================================
-void VISU_SphereWidget::OnRightButtonDown()
+void VISU_SphereWidget::OnMiddleButtonDown()
 {
   int X = Interactor->GetEventPosition()[0];
   int Y = Interactor->GetEventPosition()[1];
@@ -473,10 +473,10 @@ void VISU_SphereWidget::OnMouseMove()
   Interactor->Render();
 }
 //====================================================================
-// function:OnRightButtonUp
+// function:OnMiddleButtonUp
 // purpose:
 //====================================================================
-void VISU_SphereWidget::OnRightButtonUp()
+void VISU_SphereWidget::OnMiddleButtonUp()
 {
   if ( myState == VISU_SphereWidget::Outside ) {
     return;
@@ -589,21 +589,24 @@ void VISU_SphereWidget::Translate(double *p1, double *p2)
 // purpose:
 //====================================================================
 void VISU_SphereWidget::Scale(double *p1, double *p2, 
-                              int , int )
+                              int aX, int aY)
 {
-  float aC[3], aR, d1, d2, sf, aR1;
+  double v[3];
+  v[0] = p2[0] - p1[0];
+  v[1] = p2[1] - p1[1];
+  v[2] = p2[2] - p1[2];
   //
+  float aC[3], aR, sf, aR1;
   aR=mySphereSource->GetRadius();
   mySphereSource->GetCenter(aC);
-  d1=sqrt((p1[0]-aC[0])*(p1[0]-aC[0])+
-          (p1[1]-aC[1])*(p1[1]-aC[1])+
-          (p1[2]-aC[2])*(p1[2]-aC[2]));
-
-  d2=sqrt((p2[0]-aC[0])*(p2[0]-aC[0])+
-          (p2[1]-aC[1])*(p2[1]-aC[1])+
-          (p2[2]-aC[2])*(p2[2]-aC[2]));
-
-  sf=1.+(d2-d1)/aR;
+  sf=vtkMath::Norm(v)/aR;
+  int aCoordLast[2], iDX, iDY, iSign;
+  Interactor->GetLastEventPosition(aCoordLast);
+  //
+  iDX=aX-aCoordLast[0];
+  iDY=aCoordLast[1]-aY; 
+  iSign=(iDX+iDY>0)? 1 : -1;
+  sf=1.+iSign*sf;
   aR1=sf*aR;
   if (aR1<myRmin){
     aR1=myRmin;
@@ -716,3 +719,43 @@ void VISU_SphereWidget::PrintSelf(ostream& os, vtkIndent indent)
 {
   this->Superclass::PrintSelf(os,indent);
 }
+/*
+//====================================================================
+// function:Scale
+// purpose:
+//====================================================================
+void VISU_SphereWidget::Scale(double *p1, double *p2, 
+                              int , int )
+{
+  float aC[3], aR, d1, d2, sf, aR1;
+  //
+  aR=mySphereSource->GetRadius();
+  mySphereSource->GetCenter(aC);
+  d1=sqrt((p1[0]-aC[0])*(p1[0]-aC[0])+
+          (p1[1]-aC[1])*(p1[1]-aC[1])+
+          (p1[2]-aC[2])*(p1[2]-aC[2]));
+
+  d2=sqrt((p2[0]-aC[0])*(p2[0]-aC[0])+
+          (p2[1]-aC[1])*(p2[1]-aC[1])+
+          (p2[2]-aC[2])*(p2[2]-aC[2]));
+
+  sf=1.+(d2-d1)/aR;
+  aR1=sf*aR;
+  if (aR1<myRmin){
+    aR1=myRmin;
+  }
+  mySphereSource->SetRadius(aR1);
+  mySphere->SetCenter(mySphereSource->GetCenter());
+  mySphere->SetRadius(mySphereSource->GetRadius());
+  //
+  int i;
+  float aCH[3];
+  //
+  myHandleSource->GetCenter(aCH);
+  for (i=0; i<3; ++i){  
+    aCH[i]=aC[i]+aR1*(aCH[i]-aC[i])/aR;
+  }
+  myHandleSource->SetCenter(aCH);
+  myHandleActor->SetCenter(aCH);
+}
+*/
index 09515a4134325e1d25a652d7d7a0257d9dabcbcd..7373e4be2b988ccd50c9538c746b901b8bf026d1 100755 (executable)
@@ -79,8 +79,8 @@ protected:
   // ProcessEvents() dispatches to these methods.
   void OnLeftButtonDown();
   void OnLeftButtonUp();
-  void OnRightButtonDown();
-  void OnRightButtonUp();
+  void OnMiddleButtonDown();
+  void OnMiddleButtonUp();
   void OnMouseMove();
 
   void HighlightSphere(int highlight);