From b9f398dbfcfd422eb13b36fa37aecfad5639d5d6 Mon Sep 17 00:00:00 2001 From: Eduardo DAVILA Date: Mon, 17 Jul 2023 17:36:24 +0200 Subject: [PATCH] #3524 TransformWidget2 --- .../src/bbcreaMaracasVisuTransformWidget2.cxx | 287 +++++++++++++++--- bbtk/src/bbcreaMaracasVisuTransformWidget2.h | 12 +- 2 files changed, 247 insertions(+), 52 deletions(-) diff --git a/bbtk/src/bbcreaMaracasVisuTransformWidget2.cxx b/bbtk/src/bbcreaMaracasVisuTransformWidget2.cxx index 11f3206..f00e527 100644 --- a/bbtk/src/bbcreaMaracasVisuTransformWidget2.cxx +++ b/bbtk/src/bbcreaMaracasVisuTransformWidget2.cxx @@ -12,24 +12,48 @@ class TransformWidgetPanel : public wxPanel { public: TransformWidgetPanel(TransformWidget2* box, wxWindow *parent); - ~TransformWidgetPanel(); - void OnSliderTrackX(wxScrollEvent& event); - void OnSliderTrackY(wxScrollEvent& event); - void OnSliderTrackZ(wxScrollEvent& event); - void OnSliderReleaseX(wxScrollEvent& event); - void OnSliderReleaseY(wxScrollEvent& event); - void OnSliderReleaseZ(wxScrollEvent& event); - void Release( wxSlider * slider ); - void Track( wxSlider * slider ,int idVector); - + ~TransformWidgetPanel (); + void OnSetPoint (wxCommandEvent& event); + void Release (wxSlider *slider); + void Track (double angle ,int idVector); + void SetPossiblePoint (std::vector possiblePoint); + void _OnSetPoint(); + + // Type : Module A + void OnSliderTrackX (wxScrollEvent& event); + void OnSliderTrackY (wxScrollEvent& event); + void OnSliderTrackZ (wxScrollEvent& event); + void OnSliderReleaseX (wxScrollEvent& event); + void OnSliderReleaseY (wxScrollEvent& event); + void OnSliderReleaseZ (wxScrollEvent& event); + + // Type : Module B + void OnRadioButtonX(wxEvent& event); + void OnRadioButtonY(wxEvent& event); + void OnRadioButtonZ(wxEvent& event); + void OnRadioButtonN(wxEvent& event); + void OnReset(wxCommandEvent& event); + void OnMoveDown(wxCommandEvent& event); + void OnMoveUp(wxCommandEvent& event); + void OnSliderGeneralTrack(wxScrollEvent& event); + void OnSliderGeneralRelease(wxScrollEvent& event); + private: - TransformWidget2 *mBox; - wxSlider *mSliderRotationX; - wxSlider *mSliderRotationY; - wxSlider *mSliderRotationZ; - vtkTransform *t; - vtkTransform *tt; + vtkTransform *t; + vtkTransform *tt; + std::vector mPossiblePoint; + std::vector mActualPoint; + TransformWidget2 *mBox; + + // Type : Module A + wxSlider *mSliderRotationX; + wxSlider *mSliderRotationY; + wxSlider *mSliderRotationZ; + // Type : Module B + char mTool; + wxSlider *mSliderGeneral; }; + //------------------------------------------------------------------------ //------------------------------------------------------------------------ //------------------------------------------------------------------------ @@ -38,30 +62,94 @@ TransformWidgetPanel::TransformWidgetPanel(TransformWidget2* box, wxWindow *pare : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL), mBox(box) { - t = vtkTransform::New(); - tt = NULL; - wxSize sizeSliderWidget(25,25); - mSliderRotationX = new wxSlider( this, -1, 0 , -180, 180 , wxDefaultPosition,sizeSliderWidget, wxSL_HORIZONTAL, wxDefaultValidator); - mSliderRotationY = new wxSlider( this, -1, 0 , -180, 180 , wxDefaultPosition,sizeSliderWidget, wxSL_HORIZONTAL, wxDefaultValidator); - mSliderRotationZ = new wxSlider( this, -1, 0 , -180, 180 , wxDefaultPosition,sizeSliderWidget, wxSL_HORIZONTAL, wxDefaultValidator); -// mSliderRotationX = new wxSlider( this, -1, 0 , -180, 180 , wxDefaultPosition,sizeSliderWidget, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator); -// mSliderRotationY = new wxSlider( this, -1, 0 , -180, 180 , wxDefaultPosition,sizeSliderWidget, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator); -// mSliderRotationZ = new wxSlider( this, -1, 0 , -180, 180 , wxDefaultPosition,sizeSliderWidget, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator); - - Connect( mSliderRotationX->GetId(),wxEVT_SCROLL_THUMBRELEASE,(wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderReleaseX ); - Connect( mSliderRotationX->GetId(),wxEVT_SCROLL_THUMBTRACK ,(wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderTrackX ); - Connect( mSliderRotationX->GetId(),wxEVT_SCROLL_CHANGED ,(wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderTrackX ); - Connect( mSliderRotationY->GetId(),wxEVT_SCROLL_THUMBRELEASE,(wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderReleaseY ); - Connect( mSliderRotationY->GetId(),wxEVT_SCROLL_THUMBTRACK ,(wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderTrackY ); - Connect( mSliderRotationY->GetId(),wxEVT_SCROLL_CHANGED ,(wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderTrackY ); - Connect( mSliderRotationZ->GetId(),wxEVT_SCROLL_THUMBRELEASE,(wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderReleaseZ ); - Connect( mSliderRotationZ->GetId(),wxEVT_SCROLL_THUMBTRACK ,(wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderTrackZ ); - Connect( mSliderRotationZ->GetId(),wxEVT_SCROLL_CHANGED ,(wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderTrackZ ); - wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL); - sizer->Add( mSliderRotationX,1 ); - sizer->Add( mSliderRotationY,1 ); - sizer->Add( mSliderRotationZ,1 ); - SetSizer(sizer); + t = vtkTransform::New(); + tt = vtkTransform::New(); + mActualPoint.push_back(0); + mActualPoint.push_back(0); + mActualPoint.push_back(0); + + mPossiblePoint.push_back(0); + mPossiblePoint.push_back(0); + mPossiblePoint.push_back(0); + + wxSize sizeSliderWidget; + wxSize sizeButton; + + if (mBox->bbGetInputType()==0) + { + sizeSliderWidget.Set(25,25); + sizeButton.Set( 45 , -1 ); + mSliderRotationX = new wxSlider( this, -1, 0 , -180, 180 , wxDefaultPosition,sizeSliderWidget, wxSL_HORIZONTAL, wxDefaultValidator ); + mSliderRotationY = new wxSlider( this, -1, 0 , -180, 180 , wxDefaultPosition,sizeSliderWidget, wxSL_HORIZONTAL, wxDefaultValidator ); + mSliderRotationZ = new wxSlider( this, -1, 0 , -180, 180 , wxDefaultPosition,sizeSliderWidget, wxSL_HORIZONTAL, wxDefaultValidator ); + wxButton *mBtnSetPoint = new wxButton( this, -1, _T("Set Point") , wxDefaultPosition, sizeButton ); + Connect(mBtnSetPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSetPoint ); + Connect( mSliderRotationX->GetId(), wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderReleaseX ); + Connect( mSliderRotationX->GetId(), wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderTrackX ); + Connect( mSliderRotationX->GetId(), wxEVT_SCROLL_CHANGED , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderTrackX ); + Connect( mSliderRotationY->GetId(), wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderReleaseY ); + Connect( mSliderRotationY->GetId(), wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderTrackY ); + Connect( mSliderRotationY->GetId(), wxEVT_SCROLL_CHANGED , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderTrackY ); + Connect( mSliderRotationZ->GetId(), wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderReleaseZ ); + Connect( mSliderRotationZ->GetId(), wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderTrackZ ); + Connect( mSliderRotationZ->GetId(), wxEVT_SCROLL_CHANGED , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderTrackZ ); + wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL); + sizer->Add( mSliderRotationX , 1 ); + sizer->Add( mSliderRotationY , 1 ); + sizer->Add( mSliderRotationZ , 1 ); + sizer->Add( mBtnSetPoint , 1 ); + SetSizer(sizer); + } // if Type == 0 + + if (mBox->bbGetInputType()==1) + { + mTool=0; + sizeSliderWidget.Set(250,-1 ); + sizeButton.Set( 65 , -1 ); + wxRadioButton *rBtnX = new wxRadioButton( this, -1, _T("X") ,wxDefaultPosition, wxDefaultSize, wxRB_GROUP); + wxRadioButton *rBtnY = new wxRadioButton( this, -1, _T("Y") ,wxDefaultPosition, wxDefaultSize, 0); + wxRadioButton *rBtnZ = new wxRadioButton( this, -1, _T("Z") ,wxDefaultPosition, wxDefaultSize, 0); + wxRadioButton *rBtnN = new wxRadioButton( this, -1, _T("N") ,wxDefaultPosition, wxDefaultSize, 0); + mSliderGeneral = new wxSlider( this, -1, 0 , -180, 180 , wxDefaultPosition,sizeSliderWidget, wxSL_HORIZONTAL, wxDefaultValidator ); + wxButton *mBtnMoveDown = new wxButton( this, -1, _T("-") , wxDefaultPosition, sizeButton ); + wxButton *mBtnMoveUp = new wxButton( this, -1, _T("+") , wxDefaultPosition, sizeButton ); + wxButton *mBtnSetPoint = new wxButton( this, -1, _T("Set") , wxDefaultPosition, sizeButton ); + wxButton *mBtnReset = new wxButton( this, -1, _T("Reset") , wxDefaultPosition, sizeButton ); + Connect( rBtnX->GetId() , wxEVT_COMMAND_RADIOBUTTON_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&)) &TransformWidgetPanel::OnRadioButtonX ); + Connect( rBtnY->GetId() , wxEVT_COMMAND_RADIOBUTTON_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&)) &TransformWidgetPanel::OnRadioButtonY ); + Connect( rBtnZ->GetId() , wxEVT_COMMAND_RADIOBUTTON_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&)) &TransformWidgetPanel::OnRadioButtonZ ); + Connect( rBtnN->GetId() , wxEVT_COMMAND_RADIOBUTTON_SELECTED, (wxObjectEventFunction) (void (wxPanel::*)(wxEvent&)) &TransformWidgetPanel::OnRadioButtonN ); + Connect(mBtnSetPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSetPoint ); + Connect(mBtnReset->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnReset ); + Connect(mBtnMoveDown->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnMoveDown ); + Connect(mBtnMoveUp->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnMoveUp ); + Connect( mSliderGeneral->GetId(), wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderGeneralRelease ); + Connect( mSliderGeneral->GetId(), wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderGeneralTrack ); + Connect( mSliderGeneral->GetId(), wxEVT_SCROLL_CHANGED , (wxObjectEventFunction)(void (wxPanel::*)(wxScrollEvent&)) &TransformWidgetPanel::OnSliderGeneralTrack ); + rBtnX->SetValue(true); + + wxBoxSizer *sizerD = new wxBoxSizer(wxHORIZONTAL); + sizerD->Add( mBtnSetPoint , 1 ); + sizerD->Add( mBtnReset , 1 ); + wxBoxSizer *sizerA = new wxBoxSizer(wxHORIZONTAL); + sizerA->Add( rBtnX , 1 ); + sizerA->Add( rBtnY , 1 ); + sizerA->Add( rBtnZ , 1 ); + sizerA->Add( rBtnN , 1 ); + wxBoxSizer *sizerB = new wxBoxSizer(wxHORIZONTAL); + sizerB->Add( mSliderGeneral , 0 ); + wxBoxSizer *sizerC = new wxBoxSizer(wxHORIZONTAL); + sizerC->Add( mBtnMoveDown , 1 ); + sizerC->Add( mBtnMoveUp , 1 ); + wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL); + sizer->Add( sizerD , 0 ); + sizer->Add( sizerA , 0 ); + sizer->Add( sizerB , 0 ); + sizer->Add( sizerC , 0 ); + + SetSizer(sizer); + } // if + } TransformWidgetPanel::~TransformWidgetPanel() @@ -70,7 +158,10 @@ TransformWidgetPanel::~TransformWidgetPanel() void TransformWidgetPanel::Release( wxSlider * slider ) { - slider->SetValue(0); + if (slider!=NULL) + { + slider->SetValue(0); + } // t = t*tt t->PostMultiply(); t->Concatenate ( tt->GetMatrix() ); t->Update(); @@ -94,7 +185,7 @@ void TransformWidgetPanel::OnSliderReleaseZ(wxScrollEvent& event) Release( mSliderRotationZ ); } -void TransformWidgetPanel::Track( wxSlider *slider, int idVector) +void TransformWidgetPanel::Track( double angle, int idVector) { // out = t*tt if (tt!=NULL) @@ -108,7 +199,7 @@ void TransformWidgetPanel::Track( wxSlider *slider, int idVector) tt = vtkTransform::New(); tt->PostMultiply(); - double angle = slider->GetValue()/2; + angle = angle/2; tt->RotateWXYZ( angle , tvx,tvy,tvz); tt->Update(); vtkTransform *result=vtkTransform::New(); result->PostMultiply(); @@ -120,17 +211,112 @@ void TransformWidgetPanel::Track( wxSlider *slider, int idVector) void TransformWidgetPanel::OnSliderTrackX(wxScrollEvent& event) { - Track(mSliderRotationX ,0); + Track(mSliderRotationX->GetValue() ,0); } void TransformWidgetPanel::OnSliderTrackY(wxScrollEvent& event) { - Track(mSliderRotationY ,1); + Track(mSliderRotationY->GetValue() ,1); } void TransformWidgetPanel::OnSliderTrackZ(wxScrollEvent& event) { - Track(mSliderRotationZ ,2); + Track(mSliderRotationZ->GetValue() ,2); +} + +void TransformWidgetPanel::SetPossiblePoint(std::vector possiblePoint) +{ + mPossiblePoint = possiblePoint; +} + +void TransformWidgetPanel::_OnSetPoint() +{ + mActualPoint = mPossiblePoint; + mBox->bbSetOutputActualPoint( mActualPoint ); + mBox->bbSignalOutputModification(std::string("ActualPoint")); +} + +void TransformWidgetPanel::OnSetPoint(wxCommandEvent& event) +{ + _OnSetPoint(); +} + +//------------------------------------------------------------------------ + +void TransformWidgetPanel::OnRadioButtonX(wxEvent& event) +{ + mTool = 0; +} + +void TransformWidgetPanel::OnRadioButtonY(wxEvent& event) +{ + mTool = 1; +} + +void TransformWidgetPanel::OnRadioButtonZ(wxEvent& event) +{ + mTool = 2; +} + +void TransformWidgetPanel::OnRadioButtonN(wxEvent& event) +{ + mTool = 3; +} + +void TransformWidgetPanel::OnReset(wxCommandEvent& event) +{ + if ((mTool>=0) && (mTool<=2)) + { + tt->GetMatrix()->Identity(); tt->Update(); + t->GetMatrix()->Identity(); t->Update(); + if (mTool==0) + { + Release( NULL ); + } // if + + if (mTool==1) + { + t->RotateWXYZ( 90 , 1,0,0); tt->Update(); + Release( NULL ); + } // if + + if (mTool==2) + { + t->RotateWXYZ( 90 , 0,1,0); tt->Update(); + Release( NULL ); + } // if + } // if mTool >=0 <=2 +} + +void TransformWidgetPanel::OnMoveDown(wxCommandEvent& event) +{ + if ((mTool>=0) && (mTool<=2)) + { + Track( -2 , mTool ); + Release( NULL ); + } +} + +void TransformWidgetPanel::OnMoveUp(wxCommandEvent& event) +{ + if ((mTool>=0) && (mTool<=2)) + { + Track( 2 , mTool ); + Release( NULL ); + } +} + +void TransformWidgetPanel::OnSliderGeneralRelease(wxScrollEvent& event) +{ + Release( mSliderGeneral ); +} + +void TransformWidgetPanel::OnSliderGeneralTrack(wxScrollEvent& event) +{ + if ((mTool>=0) && (mTool<=2)) + { + Track( mSliderGeneral->GetValue() , mTool ); + } } @@ -145,7 +331,13 @@ BBTK_BLACK_BOX_IMPLEMENTATION(TransformWidget2,bbtk::WxBlackBox); //===== void TransformWidget2::Process() { - + TransformWidgetPanel *w = (TransformWidgetPanel*) bbGetOutputWidget( ); + w->SetPossiblePoint( bbGetInputPossiblePoint() ); + if (firsttime==true) + { + firsttime=false; + w->_OnSetPoint(); + }// if } //===== @@ -162,6 +354,7 @@ void TransformWidget2::CreateWidget(wxWindow* parent) //===== void TransformWidget2::bbUserSetDefaultValues() { + firsttime=true; bbSetInputType(0); } diff --git a/bbtk/src/bbcreaMaracasVisuTransformWidget2.h b/bbtk/src/bbcreaMaracasVisuTransformWidget2.h index 4dcbede..e603bc3 100644 --- a/bbtk/src/bbcreaMaracasVisuTransformWidget2.h +++ b/bbtk/src/bbcreaMaracasVisuTransformWidget2.h @@ -22,12 +22,14 @@ class bbcreaMaracasVisu_EXPORT TransformWidget2 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== BBTK_DECLARE_INPUT(Type,int); - BBTK_DECLARE_INPUT(Point,std::vector< double >); + BBTK_DECLARE_INPUT(PossiblePoint,std::vector< double >); BBTK_DECLARE_OUTPUT(Out,vtkLinearTransform *); + BBTK_DECLARE_OUTPUT(ActualPoint,std::vector< double >); BBTK_PROCESS(Process); void Process(); BBTK_CREATE_WIDGET(CreateWidget); void CreateWidget(wxWindow*); + bool firsttime; //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== @@ -38,15 +40,15 @@ BBTK_BEGIN_DESCRIBE_BLACK_BOX(TransformWidget2,bbtk::WxBlackBox); BBTK_AUTHOR("InfoDev"); BBTK_DESCRIPTION("No Description."); BBTK_CATEGORY("__CategoryBlackBox__"); - BBTK_INPUT(TransformWidget2,Type,"(default 0)",int,""); - BBTK_INPUT(TransformWidget2,Point,"Potential Point [x y z]",std::vector,""); + BBTK_INPUT(TransformWidget2,Type,"(default 0) 0:mode A with 3 sliders 1:mode B with radio buttons,",int,""); + BBTK_INPUT(TransformWidget2,PossiblePoint,"Potential Point [x y z]",std::vector,""); BBTK_OUTPUT(TransformWidget2,Out,"vtkTransform result",vtkLinearTransform *,""); + BBTK_OUTPUT(TransformWidget2,ActualPoint,"Origin [x,y,z]",std::vector,""); BBTK_END_DESCRIBE_BLACK_BOX(TransformWidget2); //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== -} -// EO namespace bbcreaMaracasVisu +} // EO namespace bbcreaMaracasVisu #endif // __bbcreaMaracasVisuTransformWidget2_h_INCLUDED__ #endif // _USE_WXWIDGETS_ -- 2.47.1