From 0b3b25440d23eabf549ebdfa0a4a39ea91ea2f23 Mon Sep 17 00:00:00 2001 From: corredor <> Date: Tue, 6 Apr 2010 15:21:55 +0000 Subject: [PATCH] Move box and refresh position ... ports don't refresh automatically their position and a new problem using contours module to make the connections. Good and sunny day --- .../bbsKernelEditorGraphic/GBlackBoxModel.cxx | 37 ++++++++ .../bbsKernelEditorGraphic/GBlackBoxModel.h | 3 + .../bbsKernelEditorGraphic/GObjectModel.cxx | 4 + .../bbsKernelEditorGraphic/GObjectModel.h | 2 + .../bbsKernelEditorGraphic/GPortModel.cxx | 30 ++++-- .../bbsKernelEditorGraphic/GPortModel.h | 5 +- .../bbsKernelEditorGraphic/GlobalConstants.h | 7 +- .../bbsKernelEditorGraphic/Observable.cxx | 4 +- .../bbsKernelEditorGraphic/Observable.h | 5 +- .../bbsKernelEditorGraphic/Observer.cxx | 3 +- .../bbsKernelEditorGraphic/Observer.h | 2 +- .../wxVtkSceneManager.cxx | 93 +++++++++++++++++-- .../wxVtkSceneManager.h | 20 +++- .../GObjectController.cxx | 13 ++- .../GObjectController.h | 8 +- .../GObjectsMVCFactory.cxx | 3 + .../GPortController.cxx | 59 ++++++++++++ .../bbsVtkGUIEditorGraphic/GPortController.h | 3 + .../vtkGBlackBoxView.cxx | 13 ++- .../bbsVtkGUIEditorGraphic/vtkGBlackBoxView.h | 5 +- .../bbsVtkGUIEditorGraphic/vtkGObjectView.cxx | 37 +++++++- .../bbsVtkGUIEditorGraphic/vtkGObjectView.h | 12 ++- .../bbsVtkGUIEditorGraphic/vtkGPortView.cxx | 22 +++-- .../bbsVtkGUIEditorGraphic/vtkGPortView.h | 3 +- 24 files changed, 343 insertions(+), 50 deletions(-) diff --git a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GBlackBoxModel.cxx b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GBlackBoxModel.cxx index 2a2081f..f2866f5 100644 --- a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GBlackBoxModel.cxx +++ b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GBlackBoxModel.cxx @@ -89,6 +89,43 @@ namespace bbtk //========================================================================= + void GBlackBoxModel::move(double xx,double yy,double zz) + { + setInicPoint(xx,yy,zz); + //std::cout<<"GBlackBoxModel::move xx:"<updatePortPosition(i); + } + + //Refresh outputs position + for(i=0;i<_outputs.size();i++) + { + _outputs[i]->updatePortPosition(i); + } + + } + + //========================================================================= + + GPortModel* GBlackBoxModel::getStartInputPort() + { + GPortModel* temp = NULL; + + for(int i=0; i<_inputs.size() && temp == NULL;i++) + { + if(_inputs[i]->getState() == CREATING_CONTOUR) + { + temp = _inputs[i]; + } + } + + return temp; + } + } // EO namespace bbtk // EOF diff --git a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GBlackBoxModel.h b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GBlackBoxModel.h index 5536e00..f1c36cf 100644 --- a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GBlackBoxModel.h +++ b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GBlackBoxModel.h @@ -46,6 +46,7 @@ Version: $Revision$ //Includes same project #include "GlobalConstants.h" #include "GObjectModel.h" +#include "GPortModel.h" //Includes creaMaracasVisu @@ -73,6 +74,8 @@ namespace bbtk void addOutputPort(GPortModel *outputport); int getNumInputPorts(); int getNumOutputPorts(); + virtual void move(double xx,double yy,double zz); + GPortModel* getStartInputPort(); private: diff --git a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GObjectModel.cxx b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GObjectModel.cxx index 4752ec9..f6d8c4d 100644 --- a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GObjectModel.cxx +++ b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GObjectModel.cxx @@ -140,6 +140,10 @@ namespace bbtk //========================================================================= + void GObjectModel::move(double xx,double yy,double zz)//virtual + { + setInicPoint(xx,yy,zz); + } //========================================================================= diff --git a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GObjectModel.h b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GObjectModel.h index 4dfc477..b610386 100644 --- a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GObjectModel.h +++ b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GObjectModel.h @@ -75,6 +75,7 @@ namespace bbtk virtual void setFinalPoint(double& x, double& y, double& z); void setState(int state); int getState(); + virtual void move(double xx,double yy,double zz); virtual bool isPointInside(double x,double y, double z); virtual void updateBlackBox(BlackBoxDescriptor::Pointer descriptor); @@ -82,6 +83,7 @@ namespace bbtk int getGObjectType(); void setGObjectType(int obtype); + private: //Private Attributes diff --git a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GPortModel.cxx b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GPortModel.cxx index 82940f8..abb6945 100644 --- a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GPortModel.cxx +++ b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GPortModel.cxx @@ -53,40 +53,54 @@ namespace bbtk } //========================================================================= - void GPortModel::registerInBox(GBlackBoxModel *blackBox,int portType) + void GPortModel::registerInBox(GBlackBoxModel *blackBox,int portType, int pos) { _parentBox = blackBox; _portType = portType; + updatePortPosition(pos); + + } + + //========================================================================= + + void GPortModel::updatePortPosition(int pos) + { double xInic, yInic,zInic,xFin,yFin,zFin; _parentBox->getInicPoint(xInic,yInic,zInic); _parentBox->getFinalPoint(xFin, yFin,zFin); - - int cant = 0; + double posX=xInic,posY=yInic,posZ=zInic; if(_portType==GOUTPUTPORT) { - cant = _parentBox->getNumOutputPorts(); posY = yInic+PORT_HEIGHT; } else if(_portType==GINPUTPORT) { - cant = _parentBox->getNumInputPorts(); posY = yFin; } - posX = xInic + PORT_WIDTH + cant*2*PORT_WIDTH; + //Usually pos begins in 0 + posX = xInic + PORT_WIDTH + pos*2*PORT_WIDTH; setInicPoint(posX,posY,posZ); posX=posX+PORT_WIDTH; posY=posY-PORT_HEIGHT; - setFinalPoint(posX,posY,posZ); - + setFinalPoint(posX,posY,posZ); + + setChanged(); + notifyObservers(); } //========================================================================= + + int GPortModel::getPortType() + { + return _portType; + } + } // EO namespace bbtk // EOF diff --git a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GPortModel.h b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GPortModel.h index 1d6fa3e..1a32e09 100644 --- a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GPortModel.h +++ b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GPortModel.h @@ -69,7 +69,10 @@ namespace bbtk ~GPortModel(); //Public methods - void registerInBox(GBlackBoxModel *blackBox,int portType); + void registerInBox(GBlackBoxModel *blackBox,int portType, int pos); + void updatePortPosition(int pos); + int getPortType(); + private: //Attributes diff --git a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GlobalConstants.h b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GlobalConstants.h index 112822f..2beacdb 100644 --- a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GlobalConstants.h +++ b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/GlobalConstants.h @@ -51,11 +51,12 @@ namespace bbtk const int GOUTPUTPORT = 5; // Object states - static const int NOTHING_HAPPENS = 101; + const int NOTHING_HAPPENS = 101; const int HIGHLIGHTED=102; const int CLICKED=103; const int DRAG=104; const int SELECTED=105; + const int CREATING_CONTOUR=106; // Object dimensions const double BOX_HEIGHT=0.1; @@ -63,6 +64,10 @@ namespace bbtk const double PORT_HEIGHT=0.04; const double PORT_WIDTH=0.04; + // Commands + const int REPAINT = 201; + const int INIT_CREATION_CONTOUR= 202; + // Colors (object_state_(R|G|B)) const double BOXCONTOUR_NH_R=0.0; const double BOXCONTOUR_NH_G=0.0; diff --git a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/Observable.cxx b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/Observable.cxx index 9b6a4f5..b169cc4 100644 --- a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/Observable.cxx +++ b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/Observable.cxx @@ -59,14 +59,14 @@ namespace bbtk //========================================================================= - void Observable::notifyObservers() + void Observable::notifyObservers(int command) { if(_changed) { int i; for(i=0;i<_observers.size();i++) { - _observers[i]->update(); + _observers[i]->update(command); } _changed=false; } diff --git a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/Observable.h b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/Observable.h index 72e1e80..a55b17d 100644 --- a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/Observable.h +++ b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/Observable.h @@ -47,6 +47,9 @@ Version: $Revision$ #include "Observer.h" +//Includes same project +#include "GlobalConstants.h" + //Includes std #include #include @@ -68,7 +71,7 @@ namespace bbtk bool hasChanged(); - void notifyObservers(); + void notifyObservers(int command=REPAINT); void setChanged(); diff --git a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/Observer.cxx b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/Observer.cxx index 3be8382..d80b07d 100644 --- a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/Observer.cxx +++ b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/Observer.cxx @@ -36,6 +36,7 @@ Version: $Revision$ #include "Observer.h" + namespace bbtk { @@ -51,7 +52,7 @@ namespace bbtk } //========================================================================= - void Observer::update() //virtual + void Observer::update(int command) //virtual { //virtual } diff --git a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/Observer.h b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/Observer.h index ac8ad9e..bd0e345 100644 --- a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/Observer.h +++ b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/Observer.h @@ -59,7 +59,7 @@ namespace bbtk ~Observer(); //Public methods - virtual void update(); + virtual void update(int command); private: diff --git a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx index bbe321e..3c79b61 100644 --- a/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx +++ b/lib/EditorGraphicBBS/bbsKernelEditorGraphic/wxVtkSceneManager.cxx @@ -55,6 +55,9 @@ namespace bbtk ///// ******* TO ERASE ******* //JUST TO TEST // + + + vtkConeSource *cone = vtkConeSource::New(); cone->SetResolution(10); @@ -93,6 +96,8 @@ namespace bbtk _pointVtkActor->SetMapper(_bboxMapper); getRenderer()->AddActor(_pointVtkActor); + + // ******* TO ERASE ******* ///////////////////// @@ -160,27 +165,30 @@ namespace bbtk model->setInicPoint(xx,yy,zz); model->addObserver(view); + model->addObserver(this); //Iterate and create the input ports std::map descriptorInMap = descriptor->GetInputDescriptorMap(); std::map::iterator itInput; + int i=0; for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput) { BlackBoxInputDescriptor *desc = itInput->second; - createGInputPort(desc,model); + createGInputPort(desc,model,i); + i++; } //Iterate and create the output ports std::map descriptorOutMap = descriptor->GetOutputDescriptorMap(); std::map::iterator itOutput; - + i=0; for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput) { BlackBoxOutputDescriptor *desc = itOutput->second; - createGOutputPort(desc,model); - + createGOutputPort(desc,model,i); + i++; } @@ -201,13 +209,13 @@ namespace bbtk registerController((InteractorStyleMaracas*) controller); //Add the object to the objects list (only boxes and connectors) - objects.push_back(model); + _objects.push_back(model); } //========================================================================= - void wxVtkSceneManager::createGOutputPort(BlackBoxOutputDescriptor *desc,GBlackBoxModel *blackBox) + void wxVtkSceneManager::createGOutputPort(BlackBoxOutputDescriptor *desc,GBlackBoxModel *blackBox, int pos) { int type = GPORT; @@ -216,9 +224,12 @@ namespace bbtk vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type); GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type); - model->registerInBox(blackBox,GOUTPUTPORT); + model->registerInBox(blackBox,GOUTPUTPORT, pos); blackBox->addOutputPort(model); + model->addObserver(view); + model->addObserver(this); + //Associates the view with the correspondent renderer and the model. //(NOTE: Refresh is only made by the view) view->setModel(model); @@ -234,7 +245,7 @@ namespace bbtk //========================================================================= - void wxVtkSceneManager::createGInputPort(BlackBoxInputDescriptor *desc,GBlackBoxModel *blackBox) + void wxVtkSceneManager::createGInputPort(BlackBoxInputDescriptor *desc,GBlackBoxModel *blackBox, int pos) { int type = GPORT; @@ -243,9 +254,11 @@ namespace bbtk vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type); GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type); - model->registerInBox(blackBox,GINPUTPORT); + model->registerInBox(blackBox,GINPUTPORT,pos); blackBox->addInputPort(model); + model->addObserver(view); + model->addObserver(this); //Associates the view with the correspondent renderer and the model. //(NOTE: Refresh is only made by the view) @@ -262,6 +275,39 @@ namespace bbtk //========================================================================= + void wxVtkSceneManager::createGConnector(GPortModel* startPort) + { + manualContourControler* manContourControl = new manualContourControler(); + manualViewContour* manViewerContour = new manualViewContour(); + manualContourModel* manContourModel = new manualContourModel(); + + + manViewerContour->SetModel( manContourModel ); + manViewerContour->SetWxVtkBaseView( _baseView ); + manViewerContour->SetRange( 0.5 ); + manViewerContour->SetZ( 900 ); + + manViewerContour->SetColorNormalContour(0, 0, 1); + manViewerContour->SetColorEditContour(0.5, 0.5, 0.5); + manViewerContour->SetColorSelectContour(1, 0.8, 0); + manViewerContour->SetWidthLine(1); + + manContourControl->SetModelView( manContourModel , manViewerContour ); + manContourControl->Configure(); + int i,sizeLstPoints = manContourModel->GetSizeLstPoints(); + for ( i=0; iAddPoint(); + } + + manContourControl->CreateNewManualContour(); + manViewerContour->RefreshContour(); + registerController((InteractorStyleMaracas*) manContourControl); + + } + + //========================================================================= + void wxVtkSceneManager::registerController(InteractorStyleMaracas *param) { vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView(); @@ -287,7 +333,36 @@ namespace bbtk { return true; } + //========================================================================= + + void wxVtkSceneManager::update(int command) + { + + if(command==INIT_CREATION_CONTOUR) + { + std::cout<<"wxVtkSceneManager::update size:"<<_objects.size()<getGObjectType()<getGObjectType() == GBLACKBOX) + { + + GPortModel* startInputPort=((GBlackBoxModel*)_objects[i])->getStartInputPort(); + std::cout<<"wxVtkSceneManager::update "< @@ -54,6 +56,9 @@ Version: $Revision$ #include #include #include +#include +#include +#include //Includes vtk #include @@ -69,7 +74,7 @@ Version: $Revision$ namespace bbtk { - class wxVtkSceneManager : public InteractorStyleMaracas + class wxVtkSceneManager : public InteractorStyleMaracas , public Observer { public: wxVtkSceneManager(wxDropTarget *parent, wxVtk3DBaseView *baseView, int id); @@ -77,23 +82,28 @@ namespace bbtk void configureBaseView(); void createGBlackBox(int x, int y,std::string packageName, std::string boxName); - void createGInputPort(BlackBoxInputDescriptor *desc,GBlackBoxModel *blackBox); - void createGOutputPort(BlackBoxOutputDescriptor *desc,GBlackBoxModel *blackBox); + void createGInputPort(BlackBoxInputDescriptor *desc,GBlackBoxModel *blackBox, int pos); + void createGOutputPort(BlackBoxOutputDescriptor *desc,GBlackBoxModel *blackBox, int pos); + void createGConnector(GPortModel* startPort); + void registerController(InteractorStyleMaracas *param); vtkRenderWindow* getRenderWindow(); vtkRenderer* getRenderer(); + void disconnectDrop(); + virtual bool OnMouseMove(); + virtual void update(int command); private: int _id; wxVtk3DBaseView *_baseView; - std::vector objects; - std::vector selectedObjects; + std::vector _objects; + std::vector _selectedObjects; protected: diff --git a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GObjectController.cxx b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GObjectController.cxx index b053cba..37b5de2 100644 --- a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GObjectController.cxx +++ b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GObjectController.cxx @@ -74,8 +74,8 @@ bool GObjectController::OnMouseMove() //Evaluate new state if(!_model->hasChanged() && state == DRAG) { - //MoveObject(X,Y); - + moveObject(X,Y); + _model->setChanged(); } if(!_model->hasChanged() && state == NOTHING_HAPPENS) @@ -115,6 +115,7 @@ bool GObjectController::OnLeftButtonDown() //Evaluate new state if(!_model->hasChanged() && state==HIGHLIGHTED) { + _view->isFirstDragging(true); _model->setState(DRAG); _model->setChanged(); } @@ -123,6 +124,7 @@ bool GObjectController::OnLeftButtonDown() { if(_view->isPointInside(X,Y)) { + _view->isFirstDragging(true); _model->setState(DRAG); _model->setChanged(); } @@ -199,8 +201,15 @@ bool GObjectController::OnRightButtonDown() } return true; } + //========================================================================= +void GObjectController::moveObject(int X,int Y) +{ + _view->moveObject(X,Y); +} + +//========================================================================= } // EO namespace bbtk diff --git a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GObjectController.h b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GObjectController.h index 45dd9ec..a490e63 100644 --- a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GObjectController.h +++ b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GObjectController.h @@ -73,8 +73,7 @@ namespace bbtk private: //Attributes - GObjectModel* _model; - vtkGObjectView* _view; + //Private Methods @@ -82,7 +81,8 @@ namespace bbtk protected: //Protected Attributes - + GObjectModel* _model; + vtkGObjectView* _view; //Protected Methods virtual bool OnMouseMove(); @@ -91,6 +91,8 @@ namespace bbtk virtual bool OnLeftDClick(); virtual bool OnRightButtonDown(); + virtual void moveObject(int X,int Y); + }; diff --git a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GObjectsMVCFactory.cxx b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GObjectsMVCFactory.cxx index 2cb11be..c9a1bc9 100644 --- a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GObjectsMVCFactory.cxx +++ b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GObjectsMVCFactory.cxx @@ -130,6 +130,9 @@ namespace bbtk { model = new GPortModel(); } + + model->setGObjectType(type); + return model; } diff --git a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GPortController.cxx b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GPortController.cxx index 33794ce..c9c196b 100644 --- a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GPortController.cxx +++ b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GPortController.cxx @@ -52,6 +52,65 @@ namespace bbtk } //========================================================================= + bool GPortController::OnLeftButtonDown() + { + + if ( _vtkInteractorStyleBaseView!=NULL ) + { + int X,Y; + wxVTKRenderWindowInteractor *wxVTKiren; + wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor(); + wxVTKiren->GetEventPosition(X,Y); + + int state = _model->getState(); + + int portType = ((GPortModel*)_model)->getPortType(); + + //Evaluate new state + if(!_model->hasChanged() && state==HIGHLIGHTED && portType==GINPUTPORT ) + { + _model->setState(CREATING_CONTOUR); + _model->setChanged(); + } + + _model->notifyObservers(); + + } + return true; + } + //========================================================================= + bool GPortController::OnLeftButtonUp() + { + if ( _vtkInteractorStyleBaseView!=NULL ) + { + int X,Y; + wxVTKRenderWindowInteractor *wxVTKiren; + wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor(); + wxVTKiren->GetEventPosition(X,Y); + + int state = _model->getState(); + + //Evaluate new state + if(!_model->hasChanged() && state==CREATING_CONTOUR) + { + if(_view->isPointInside(X,Y)) + { + _model->setChanged(); + _model->notifyObservers(INIT_CREATION_CONTOUR); + } + else + { + _model->setState(NOTHING_HAPPENS); + _model->setChanged(); + _model->notifyObservers(); + } + } + + + + } + return true; + } //========================================================================= diff --git a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GPortController.h b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GPortController.h index 66c3e2a..fdc8a24 100644 --- a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GPortController.h +++ b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/GPortController.h @@ -46,6 +46,7 @@ Version: $Revision$ //Includes same project #include "GlobalConstants.h" #include "GObjectController.h" +#include "GPortModel.h" //Includes creaMaracasVisu @@ -67,6 +68,8 @@ namespace bbtk //Public methods + virtual bool OnLeftButtonDown(); + virtual bool OnLeftButtonUp(); private: diff --git a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBlackBoxView.cxx b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBlackBoxView.cxx index 1626940..5c36d4b 100644 --- a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBlackBoxView.cxx +++ b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBlackBoxView.cxx @@ -51,7 +51,7 @@ namespace bbtk } //========================================================================= - void vtkGBlackBoxView::update() + void vtkGBlackBoxView::update(int command) { if(_model->getState()==NOTHING_HAPPENS) { @@ -74,6 +74,15 @@ namespace bbtk _objectActor->GetProperty()->SetColor(BOXCONTOUR_SELECTED_R,BOXCONTOUR_SELECTED_G,BOXCONTOUR_SELECTED_B); } + double xInic, yInic,zInic,xFin, yFin,zFin; + _model->getInicPoint(xInic,yInic,zInic); + _model->getFinalPoint(xFin, yFin,zFin); + + _pts->SetPoint(0, xInic, yInic, 0 ); + _pts->SetPoint(1, xInic, yFin, 0 ); + _pts->SetPoint(2, xFin, yFin, 0 ); + _pts->SetPoint(3, xFin, yInic, 0 ); + _baseView->GetRenWin()->Render(); } @@ -81,7 +90,7 @@ namespace bbtk void vtkGBlackBoxView::createVtkObjects() //virtual { - vtkPoints *_pts = vtkPoints::New(); + _pts = vtkPoints::New(); vtkCellArray *lines = vtkCellArray::New(); vtkPolyData *_pd = vtkPolyData::New(); vtkPolyDataMapper* _bboxMapper=vtkPolyDataMapper::New(); diff --git a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBlackBoxView.h b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBlackBoxView.h index 34b4c5b..05a536a 100644 --- a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBlackBoxView.h +++ b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGBlackBoxView.h @@ -74,11 +74,12 @@ namespace bbtk vtkGBlackBoxView(); ~vtkGBlackBoxView(); - //Public methods + //Public methods private: //Private Attributes + vtkPoints *_pts; //Private Methods @@ -88,7 +89,7 @@ namespace bbtk //Protected Methods virtual void createVtkObjects(); - virtual void update(); + virtual void update(int command); }; diff --git a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGObjectView.cxx b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGObjectView.cxx index c20afad..4e92f74 100644 --- a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGObjectView.cxx +++ b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGObjectView.cxx @@ -45,6 +45,7 @@ namespace bbtk { _baseView=NULL; _objectActor=NULL; + _isFirstDragging=false; } //========================================================================= @@ -53,7 +54,7 @@ namespace bbtk } //========================================================================= - void vtkGObjectView::update()//virtual + void vtkGObjectView::update(int command)//virtual { //virtual } @@ -97,7 +98,7 @@ namespace bbtk //========================================================================= - bool vtkGObjectView::isPointInside(int X,int Y) + bool vtkGObjectView::isPointInside(int X,int Y) //virtual { double xx=X,yy=Y,zz=0; _baseView->TransCoordScreenToWorld(xx,yy,zz); @@ -106,6 +107,38 @@ namespace bbtk //========================================================================= + void vtkGObjectView::moveObject(int X,int Y) //virtual + { + double xx=X,yy=Y,zz=0; + _baseView->TransCoordScreenToWorld(xx,yy,zz); + + + + if(_isFirstDragging) + { + _isFirstDragging=false; + + double xInic,yInic,zInic; + _model->getInicPoint(xInic,yInic,zInic); + dragDifX=xx-xInic; + dragDifY=yy-yInic; + } + + _model->move(xx-dragDifX,yy-dragDifY,zz); + + } + + //========================================================================= + + void vtkGObjectView::isFirstDragging(bool param) + { + _isFirstDragging=param; + dragDifX=0; + dragDifX=0; + } + + //========================================================================= + } // EO namespace bbtk // EOF diff --git a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGObjectView.h b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGObjectView.h index 1397ef4..97ea577 100644 --- a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGObjectView.h +++ b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGObjectView.h @@ -79,13 +79,19 @@ namespace bbtk void setBaseView(wxVtkBaseView* baseView); void initVtkObjects(); - bool isPointInside(int X,int Y); + virtual bool isPointInside(int X,int Y); + virtual void moveObject(int X, int Y); - virtual void update(); + virtual void update(int command); + void isFirstDragging(bool param); private: //Private Attributes + bool _isFirstDragging; + double dragDifX; + double dragDifY; + //Private Methods @@ -95,7 +101,7 @@ namespace bbtk wxVtkBaseView *_baseView; GObjectModel *_model; vtkActor *_objectActor; - + //Protected Methods virtual void createVtkObjects(); virtual void addVtkActors(); diff --git a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGPortView.cxx b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGPortView.cxx index d224f30..d1ab127 100644 --- a/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGPortView.cxx +++ b/lib/EditorGraphicBBS/bbsVtkGUIEditorGraphic/vtkGPortView.cxx @@ -51,25 +51,37 @@ namespace bbtk } //========================================================================= - void vtkGPortView::update() + void vtkGPortView::update(int command) { - //paint(); if(_model->getState()==HIGHLIGHTED) { - _objectActor->GetProperty()->SetColor(0.0,0.2,0.5); + _objectActor->GetProperty()->SetColor(0.8,0.2,0.5); } else { _objectActor->GetProperty()->SetColor(0.3,0.2,0.2); } + + double xInic, yInic,zInic,xFin, yFin,zFin; + + _model->getInicPoint(xInic,yInic,zInic); + _model->getFinalPoint(xFin, yFin,zFin); + + _pts->SetPoint(0, xInic, yInic, 0 ); + _pts->SetPoint(1, xInic, yFin, 0 ); + _pts->SetPoint(2, xFin, yFin, 0 ); + _pts->SetPoint(3, xFin, yInic, 0 ); + _baseView->GetRenderer()->Render(); + _baseView->GetRenWin()->Render(); + } //========================================================================= void vtkGPortView::createVtkObjects() //virtual { - vtkPoints *_pts = vtkPoints::New(); + _pts = vtkPoints::New(); vtkCellArray *lines = vtkCellArray::New(); vtkPolyData *_pd = vtkPolyData::New(); vtkPolyDataMapper* _bboxMapper=vtkPolyDataMapper::New(); @@ -81,8 +93,6 @@ namespace bbtk _model->getInicPoint(xInic,yInic,zInic); _model->getFinalPoint(xFin, yFin,zFin); - cout<<"RaC vtkGPortView::createVtkObjects() xInic="<