//=========================================================================
+ void GBlackBoxModel::move(double xx,double yy,double zz)
+ {
+ setInicPoint(xx,yy,zz);
+ //std::cout<<"GBlackBoxModel::move xx:"<<xx<<" yy:"<<yy<<" zz:"<<zz<<std::endl;
+
+ //Refresh inputs position
+ int i;
+ for(i=0;i<_inputs.size();i++)
+ {
+ _inputs[i]->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
//Includes same project
#include "GlobalConstants.h"
#include "GObjectModel.h"
+#include "GPortModel.h"
//Includes creaMaracasVisu
void addOutputPort(GPortModel *outputport);
int getNumInputPorts();
int getNumOutputPorts();
+ virtual void move(double xx,double yy,double zz);
+ GPortModel* getStartInputPort();
private:
//=========================================================================
+ void GObjectModel::move(double xx,double yy,double zz)//virtual
+ {
+ setInicPoint(xx,yy,zz);
+ }
//=========================================================================
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);
int getGObjectType();
void setGObjectType(int obtype);
+
private:
//Private Attributes
}
//=========================================================================
- 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
~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
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;
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;
//=========================================================================
- 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;
}
#include "Observer.h"
+//Includes same project
+#include "GlobalConstants.h"
+
//Includes std
#include <iostream>
#include <vector>
bool hasChanged();
- void notifyObservers();
+ void notifyObservers(int command=REPAINT);
void setChanged();
#include "Observer.h"
+
namespace bbtk
{
}
//=========================================================================
- void Observer::update() //virtual
+ void Observer::update(int command) //virtual
{
//virtual
}
~Observer();
//Public methods
- virtual void update();
+ virtual void update(int command);
private:
///// ******* TO ERASE *******
//JUST TO TEST
//
+
+
+
vtkConeSource *cone = vtkConeSource::New();
cone->SetResolution(10);
_pointVtkActor->SetMapper(_bboxMapper);
getRenderer()->AddActor(_pointVtkActor);
+
+
// ******* TO ERASE *******
/////////////////////
model->setInicPoint(xx,yy,zz);
model->addObserver(view);
+ model->addObserver(this);
//Iterate and create the input ports
std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
std::map<std::string, BlackBoxInputDescriptor*>::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<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
-
+ i=0;
for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
{
BlackBoxOutputDescriptor *desc = itOutput->second;
- createGOutputPort(desc,model);
-
+ createGOutputPort(desc,model,i);
+ i++;
}
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;
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);
//=========================================================================
- void wxVtkSceneManager::createGInputPort(BlackBoxInputDescriptor *desc,GBlackBoxModel *blackBox)
+ void wxVtkSceneManager::createGInputPort(BlackBoxInputDescriptor *desc,GBlackBoxModel *blackBox, int pos)
{
int type = GPORT;
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)
//=========================================================================
+ 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; i<sizeLstPoints; i++ )
+ {
+ manViewerContour->AddPoint();
+ }
+
+ manContourControl->CreateNewManualContour();
+ manViewerContour->RefreshContour();
+ registerController((InteractorStyleMaracas*) manContourControl);
+
+ }
+
+ //=========================================================================
+
void wxVtkSceneManager::registerController(InteractorStyleMaracas *param)
{
vtkInteractorStyleBaseView* baseViewControlManager = (vtkInteractorStyleBaseView*)_baseView->GetInteractorStyleBaseView();
{
return true;
}
+
//=========================================================================
+
+ void wxVtkSceneManager::update(int command)
+ {
+
+ if(command==INIT_CREATION_CONTOUR)
+ {
+ std::cout<<"wxVtkSceneManager::update size:"<<_objects.size()<<std::endl;
+ for(int i = 0; i<_objects.size();i++)
+ {
+ std::cout<<"wxVtkSceneManager::update type:"<<_objects[i]->getGObjectType()<<std::endl;
+ if(_objects[i]->getGObjectType() == GBLACKBOX)
+ {
+
+ GPortModel* startInputPort=((GBlackBoxModel*)_objects[i])->getStartInputPort();
+ std::cout<<"wxVtkSceneManager::update "<<startInputPort<<std::endl;
+ createGConnector(startInputPort);
+
+ }
+ else
+ {
+ // The others must not react to events
+ }
+ }
+ }
+ }
+
+ //=========================================================================
+
} // EO namespace bbtk
// EOF
//Includes same project
#include "GObjectsMVCFactory.h"
+#include "Observer.h"
+#include "GPortModel.h"
//Includes bbtk
#include <bbtkBlackBoxInputDescriptor.h>
#include <wxVtk3DBaseView.h>
#include <InteractorStyleMaracas.h>
#include <vtkInteractorStyleBaseView2D.h>
+#include <manualContourControler.h>
+#include <manualViewContour.h>
+#include <manualContourModel.h>
//Includes vtk
#include <vtkRenderWindow.h>
namespace bbtk
{
- class wxVtkSceneManager : public InteractorStyleMaracas
+ class wxVtkSceneManager : public InteractorStyleMaracas , public Observer
{
public:
wxVtkSceneManager(wxDropTarget *parent, wxVtk3DBaseView *baseView, int id);
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<GObjectModel*> objects;
- std::vector<GObjectModel*> selectedObjects;
+ std::vector<GObjectModel*> _objects;
+ std::vector<GObjectModel*> _selectedObjects;
protected:
//Evaluate new state
if(!_model->hasChanged() && state == DRAG)
{
- //MoveObject(X,Y);
-
+ moveObject(X,Y);
+ _model->setChanged();
}
if(!_model->hasChanged() && state == NOTHING_HAPPENS)
//Evaluate new state
if(!_model->hasChanged() && state==HIGHLIGHTED)
{
+ _view->isFirstDragging(true);
_model->setState(DRAG);
_model->setChanged();
}
{
if(_view->isPointInside(X,Y))
{
+ _view->isFirstDragging(true);
_model->setState(DRAG);
_model->setChanged();
}
}
return true;
}
+
//=========================================================================
+void GObjectController::moveObject(int X,int Y)
+{
+ _view->moveObject(X,Y);
+}
+
+//=========================================================================
} // EO namespace bbtk
private:
//Attributes
- GObjectModel* _model;
- vtkGObjectView* _view;
+
//Private Methods
protected:
//Protected Attributes
-
+ GObjectModel* _model;
+ vtkGObjectView* _view;
//Protected Methods
virtual bool OnMouseMove();
virtual bool OnLeftDClick();
virtual bool OnRightButtonDown();
+ virtual void moveObject(int X,int Y);
+
};
{
model = new GPortModel();
}
+
+ model->setGObjectType(type);
+
return model;
}
}
//=========================================================================
+ 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;
+ }
//=========================================================================
//Includes same project
#include "GlobalConstants.h"
#include "GObjectController.h"
+#include "GPortModel.h"
//Includes creaMaracasVisu
//Public methods
+ virtual bool OnLeftButtonDown();
+ virtual bool OnLeftButtonUp();
private:
}
//=========================================================================
- void vtkGBlackBoxView::update()
+ void vtkGBlackBoxView::update(int command)
{
if(_model->getState()==NOTHING_HAPPENS)
{
_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();
}
void vtkGBlackBoxView::createVtkObjects() //virtual
{
- vtkPoints *_pts = vtkPoints::New();
+ _pts = vtkPoints::New();
vtkCellArray *lines = vtkCellArray::New();
vtkPolyData *_pd = vtkPolyData::New();
vtkPolyDataMapper* _bboxMapper=vtkPolyDataMapper::New();
vtkGBlackBoxView();
~vtkGBlackBoxView();
- //Public methods
+ //Public methods
private:
//Private Attributes
+ vtkPoints *_pts;
//Private Methods
//Protected Methods
virtual void createVtkObjects();
- virtual void update();
+ virtual void update(int command);
};
{
_baseView=NULL;
_objectActor=NULL;
+ _isFirstDragging=false;
}
//=========================================================================
}
//=========================================================================
- void vtkGObjectView::update()//virtual
+ void vtkGObjectView::update(int command)//virtual
{
//virtual
}
//=========================================================================
- 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);
//=========================================================================
+ 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
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
wxVtkBaseView *_baseView;
GObjectModel *_model;
vtkActor *_objectActor;
-
+
//Protected Methods
virtual void createVtkObjects();
virtual void addVtkActors();
}
//=========================================================================
- 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();
_model->getInicPoint(xInic,yInic,zInic);
_model->getFinalPoint(xFin, yFin,zFin);
- cout<<"RaC vtkGPortView::createVtkObjects() xInic="<<xInic<< " yInic="<<yInic<<" zInic="<<zInic<<endl;
- cout<<"RaC vtkGPortView::createVtkObjects() xFin="<<xFin<< " yFin="<<yFin<<" zFin="<<zFin<<endl;
_pts->SetPoint(0, xInic, yInic, 0 );
_pts->SetPoint(1, xInic, yFin, 0 );
private:
//Private Attributes
+ vtkPoints *_pts;
//Private Methods
//Protected Methods
virtual void createVtkObjects();
- virtual void update();
+ virtual void update(int command);
};