}
//=========================================================================
+ void GBlackBoxModel::setInicPoint(double& x, double& y, double& z)
+ {
+ GObjectModel::setInicPoint(x,y,z);
+
+ double xFin=x+BOX_WIDTH,yFin=y-BOX_HEIGHT;
+ setFinalPoint(xFin,yFin,z);
+ }
+
+ //=========================================================================
+
void GBlackBoxModel::addInputPort(GPortModel *inputport)
{
_inputs.push_back(inputport);
//=========================================================================
+ int GBlackBoxModel::getNumInputPorts()
+ {
+ return _inputs.size();
+ }
+
+ //=========================================================================
+
+ int GBlackBoxModel::getNumOutputPorts()
+ {
+ return _outputs.size();
+ }
+
+ //=========================================================================
+
} // EO namespace bbtk
// EOF
~GBlackBoxModel();
//Public methods
+ virtual void setInicPoint(double& x, double& y, double& z);
void addInputPort(GPortModel *inputport);
void addOutputPort(GPortModel *outputport);
+ int getNumInputPorts();
+ int getNumOutputPorts();
private:
void GObjectModel::getFinalPoint(double& x, double& y, double& z)
{
- x = _xInic+BOX_SIDE;
- y = _yInic-BOX_SIDE;
+ x = _xFin;
+ y = _yFin;
z = _zFin;
}
//=========================================================================
bool GObjectModel::isPointInside(double x,double y, double z)//virtual
{
if(x>=_xInic && x<=_xFin && y<=_yInic && y>=_yFin)
+ {
return true;
+ }
else
+ {
return false;
+ }
}
//=========================================================================
void getInicPoint(double& x, double& y, double& z);
void getFinalPoint(double& x, double& y, double& z);
- void setInicPoint(double& x, double& y, double& z);
- void setFinalPoint(double& x, double& y, double& z);
+ virtual void setInicPoint(double& x, double& y, double& z);
+ virtual void setFinalPoint(double& x, double& y, double& z);
void setState(int state);
int getState();
GPortModel::GPortModel()
{
_parentBox = NULL;
+ _portType=-1;
}
//=========================================================================
}
//=========================================================================
- void GPortModel::registerInBox(GBlackBoxModel *blackBox)
+ void GPortModel::registerInBox(GBlackBoxModel *blackBox,int portType)
{
_parentBox = blackBox;
+ _portType = portType;
+
+ 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;
+
+ setInicPoint(posX,posY,posZ);
+
+ posX=posX+PORT_WIDTH;
+ posY=posY-PORT_HEIGHT;
+
+ setFinalPoint(posX,posY,posZ);
+
}
//=========================================================================
//Includes same project
#include "GlobalConstants.h"
#include "GObjectModel.h"
+#include "GBlackBoxModel.h"
//Includes creaMaracasVisu
~GPortModel();
//Public methods
- void registerInBox(GBlackBoxModel *blackBox);
+ void registerInBox(GBlackBoxModel *blackBox,int portType);
private:
//Attributes
GBlackBoxModel *_parentBox;
+ int _portType;
+
//Private Methods
protected:
const int SELECTED=105;
// Object dimensions
- const double BOX_SIDE=1.0;
+ const double BOX_HEIGHT=0.1;
+ const double BOX_WIDTH=1.0;
+ const double PORT_HEIGHT=0.04;
+ const double PORT_WIDTH=0.04;
+
+ // Colors (object_state_(R|G|B))
+ const double BOXCONTOUR_NH_R=0.0;
+ const double BOXCONTOUR_NH_G=0.0;
+ const double BOXCONTOUR_NH_B=0.0;
+
+ const double BOXCONTOUR_HIGHLIGHTED_R=0.05;
+ const double BOXCONTOUR_HIGHLIGHTED_G=0.35;
+ const double BOXCONTOUR_HIGHLIGHTED_B=0.55;
+
+ const double BOXCONTOUR_DRAG_R=0.75;
+ const double BOXCONTOUR_DRAG_G=0.75;
+ const double BOXCONTOUR_DRAG_B=0.75;
+
+ const double BOXCONTOUR_SELECTED_R=0.65;
+ const double BOXCONTOUR_SELECTED_G=0.65;
+ const double BOXCONTOUR_SELECTED_B=0.05;
}
// namespace bbtk
#endif
if(_changed)
{
int i;
-
for(i=0;i<_observers.size();i++)
{
_observers[i]->update();
void Observable::addObserver(Observer *observer)
{
+ std::cout<<"RaC Observable::addObserver "<<observer<<std::endl;
_observers.push_back(observer);
}
~Observer();
//Public methods
- void update();
+ virtual void update();
private:
_baseView->GetWxVTKRenderWindowInteractor()->SetDropTarget(parent);
registerController(this);
-
configureBaseView();
- /*//JUST TO TEST
+ ///// ******* TO ERASE *******
+ //JUST TO TEST
+ //
vtkConeSource *cone = vtkConeSource::New();
cone->SetResolution(10);
act->SetMapper(map);
- /////////////////////
-
-
vtkPoints *_pts = vtkPoints::New();
_pts->SetNumberOfPoints(4);
_pointVtkActor->SetMapper(_bboxMapper);
getRenderer()->AddActor(_pointVtkActor);
-
-*/
+ // ******* TO ERASE *******
/////////////////////
-
- //getRenderer()->AddActor(act);
-
- //getRenderer()->Render();
-
-
+
}
}
_baseView->SetInteractorStyleBaseView(interactorstylebaseview);
+ // Important to activate the 2D interaction system
wxVTKRenderWindowInteractor *iren = _baseView->GetWxVTKRenderWindowInteractor();
interactorstylebaseview->SetInteractor ( iren );
iren->SetInteractorStyle(interactorstylebaseview);
interactorstylebaseview->SetwxVtkBaseView(_baseView);
-
- //_baseView->GetRenderer()->SetActiveCamera(_baseView->GetCamera());
- //_baseView->GetRenderer()->ResetCamera ();
- //_baseView->GetCamera()->SetParallelProjection(true);
_baseView->GetRenderer()->SetBackground(0.9,0.9,0.9);
_baseView->GetRenderer()->GradientBackgroundOff();
_baseView->Refresh();
+
}
//=========================================================================
void wxVtkSceneManager::createGBlackBox(int x, int y, std::string packageName, std::string boxName)
{
+
+ int windowWidth=_baseView->GetRenWin()->GetSize()[0];
+ int windowHeight=_baseView->GetRenWin()->GetSize()[1];
+
int type = GBLACKBOX;
//Create the MVC Objects
+
GBlackBoxModel *model = (GBlackBoxModel*)GObjectsMVCFactory::getInstance()->createGObjectModel(type);
vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
BlackBoxDescriptor::Pointer descriptor = GObjectsMVCFactory::getInstance()->getBlackBoxDescriptor(packageName, boxName);
//Prepares the initial model
+ //The coordinates obtained are the following. Top-Left:x=0,y=0 Bottom-Right:x=width,y=height
+
double xx = x;
- double yy = _baseView->GetRenWin()->GetSize()[1]-y;
+ double yy = windowHeight-y;
+
+ //z value is not important yet, because it is only used a parallel projection
double zz = 0;
+
_baseView->TransCoordScreenToWorld(xx,yy,zz);
model->setInicPoint(xx,yy,zz);
+
model->addObserver(view);
//Iterate and create the input ports
std::map<std::string, BlackBoxInputDescriptor*> descriptorInMap = descriptor->GetInputDescriptorMap();
std::map<std::string, BlackBoxInputDescriptor*>::iterator itInput;
- //ERASE
- cantTemp=0;
-
for(itInput = descriptorInMap.begin(); itInput != descriptorInMap.end(); ++itInput)
{
BlackBoxInputDescriptor *desc = itInput->second;
createGInputPort(desc,model);
-
- //ERASE
- cantTemp+=2;
}
-
//Iterate and create the output ports
std::map<std::string, BlackBoxOutputDescriptor*> descriptorOutMap = descriptor->GetOutputDescriptorMap();
std::map<std::string, BlackBoxOutputDescriptor*>::iterator itOutput;
- //ERASE
- cantTemp=0;
for(itOutput = descriptorOutMap.begin();itOutput != descriptorOutMap.end(); ++itOutput)
{
BlackBoxOutputDescriptor *desc = itOutput->second;
createGOutputPort(desc,model);
- //ERASE
- cantTemp+=2;
}
//Associates the controller with the correspondent model and view
controller->setModelAndView(model,view);
- //Refresh renderwindow with new objects
- refreshRenderWindow();
+ //Resgiter change to the observers of the actual model
+ model->setChanged();
+ model->notifyObservers();
//Register the controller of the new object
registerController((InteractorStyleMaracas*) controller);
vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
- model->registerInBox(blackBox);
+ model->registerInBox(blackBox,GOUTPUTPORT);
blackBox->addOutputPort(model);
- //Prepares the initial model
- double xx = 0;
- double yy = 0;
- double zz = 0;
- blackBox->getInicPoint(xx,yy,zz);
-
- xx++;
- yy+=cantTemp;
- model->setInicPoint(xx,yy,zz);
-
//Associates the view with the correspondent renderer and the model.
//(NOTE: Refresh is only made by the view)
view->setModel(model);
vtkGObjectView *view = GObjectsMVCFactory::getInstance()->createGObjectView(type);
GObjectController* controller = GObjectsMVCFactory::getInstance()->createGObjectController(type);
- model->registerInBox(blackBox);
+ model->registerInBox(blackBox,GINPUTPORT);
blackBox->addInputPort(model);
-
- //Prepares the initial model
- double xx = 0;
- double yy = 0;
- double zz = 0;
- blackBox->getInicPoint(xx,yy,zz);
-
- xx--;
- yy+=cantTemp;
- model->setInicPoint(xx,yy,zz);
//Associates the view with the correspondent renderer and the model.
//(NOTE: Refresh is only made by the view)
return _baseView->GetRenWin();
}
//=========================================================================
-
- void wxVtkSceneManager::refreshRenderWindow()
- {
- _baseView->GetRenWin()->Render();
- }
- //=========================================================================
bool wxVtkSceneManager::OnMouseMove()
{
- //cout<<"RaC wxVtkSceneManager::OnMouseMove "<<endl;
return true;
}
//=========================================================================
int _id;
wxVtk3DBaseView *_baseView;
+
std::vector<GObjectModel*> objects;
std::vector<GObjectModel*> selectedObjects;
- void refreshRenderWindow();
-
- //ERASE
- int cantTemp;
protected:
};
bool GObjectController::OnMouseMove()
{
- cout<<"RaC GObjectController::OnMouseMove "<<endl;
+
if ( _vtkInteractorStyleBaseView!=NULL)
{
int X,Y;
int state = _model->getState();
//Evaluate new state
- if(state == CLICKED)
- {
- _model->setState(DRAG);
- //MoveObject(X,Y);
-
- }
- if(state == DRAG)
+ if(!_model->hasChanged() && state == DRAG)
{
//MoveObject(X,Y);
}
- if(state == NOTHING_HAPPENS)
+
+ if(!_model->hasChanged() && state == NOTHING_HAPPENS)
{
if(_view->isPointInside(X,Y))
{
- _model->setState(HIGHLIGHTED);
+ _model->setState(HIGHLIGHTED);
+ _model->setChanged();
}
}
- if(state==HIGHLIGHTED)
+ if(!_model->hasChanged() && state==HIGHLIGHTED)
{
if(!_view->isPointInside(X,Y))
{
- _model->setState(NOTHING_HAPPENS);
+ _model->setState(NOTHING_HAPPENS);
+ _model->setChanged();
}
}
- _view->update();
+ _model->notifyObservers();
}
return true;
}
wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
wxVTKiren->GetEventPosition(X,Y);
- //MouseClickLeft(X,Y);
+ int state = _model->getState();
+
+ //Evaluate new state
+ if(!_model->hasChanged() && state==HIGHLIGHTED)
+ {
+ _model->setState(DRAG);
+ _model->setChanged();
+ }
+
+ if( !_model->hasChanged() && state == SELECTED)
+ {
+ if(_view->isPointInside(X,Y))
+ {
+ _model->setState(DRAG);
+ _model->setChanged();
+ }
+ }
+
+ _model->notifyObservers();
}
return true;
}
{
int X,Y;
wxVTKRenderWindowInteractor *wxVTKiren;
- wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
+ wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
wxVTKiren->GetEventPosition(X,Y);
- //MouseReleaseLeft(X,Y);
+
+ int state = _model->getState();
+
+ //Evaluate new state
+ if(!_model->hasChanged() && state==CLICKED)
+ {
+ _model->setState(SELECTED);
+ _model->setChanged();
+ }
+
+ if( !_model->hasChanged() && state == DRAG)
+ {
+ _model->setState(SELECTED);
+ _model->setChanged();
+ }
+
+ _model->notifyObservers();
+
}
return true;
}
{
int X,Y;
wxVTKRenderWindowInteractor *wxVTKiren;
- wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
+ wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
wxVTKiren->GetEventPosition(X,Y);
- //this->MouseDLeft(X,Y);
+ _model->notifyObservers();
}
return true;
}
//=========================================================================
-bool GObjectController::OnMiddleButtonDown()
-{
- if ( _vtkInteractorStyleBaseView!=NULL )
- {
- int X,Y;
- wxVTKRenderWindowInteractor *wxVTKiren;
- wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
- wxVTKiren->GetEventPosition(X,Y);
- //GetManualViewBaseContour()->InitMove( X, Y,GetZ());
- }
- return true;
-}
-//=========================================================================
-bool GObjectController::OnMiddleButtonUp()
-{
- return true;
-}
-//=========================================================================
bool GObjectController::OnRightButtonDown()
{
if( _vtkInteractorStyleBaseView!= NULL )
{
int X,Y;
wxVTKRenderWindowInteractor *wxVTKiren;
- wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
+ wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
wxVTKiren->GetEventPosition(X, Y);
+
+ int state = _model->getState();
+
+ //Evaluate new state
+ if( !_model->hasChanged() && state == SELECTED)
+ {
+ _model->setState(NOTHING_HAPPENS);
+ _model->setChanged();
+ }
- //SetCompleteCreation( true );
- //SetKeyBoardMoving( false );
- //this->GetManualContourModel()->SetCloseContour(true);
- //MouseClickRight(X,Y);
+ _model->notifyObservers();
}
return true;
}
//=========================================================================
-bool GObjectController::OnRightButtonUp()
-{
- return true;
-}
-//=========================================================================
+
} // EO namespace bbtk
virtual bool OnLeftButtonDown();
virtual bool OnLeftButtonUp();
virtual bool OnLeftDClick();
- virtual bool OnMiddleButtonDown();
- virtual bool OnMiddleButtonUp();
virtual bool OnRightButtonDown();
- virtual bool OnRightButtonUp();
};
//=========================================================================
void vtkGBlackBoxView::update()
{
- //paint();
- if(_model->getState()==HIGHLIGHTED)
+ if(_model->getState()==NOTHING_HAPPENS)
{
- _objectActor->GetProperty()->SetColor(0.0,0.2,0.5);
+ _objectActor->GetProperty()->SetLineWidth(1);
+ _objectActor->GetProperty()->SetColor(BOXCONTOUR_NH_R,BOXCONTOUR_NH_G,BOXCONTOUR_NH_B);
}
- else
+ else if(_model->getState()==HIGHLIGHTED)
{
- _objectActor->GetProperty()->SetColor(0.3,0.2,0.2);
+ _objectActor->GetProperty()->SetLineWidth(2);
+ _objectActor->GetProperty()->SetColor(BOXCONTOUR_HIGHLIGHTED_R,BOXCONTOUR_HIGHLIGHTED_G,BOXCONTOUR_HIGHLIGHTED_B);
}
- _baseView->GetRenderer()->Render();
+ else if(_model->getState()==DRAG)
+ {
+ _objectActor->GetProperty()->SetLineWidth(1.2);
+ _objectActor->GetProperty()->SetColor(BOXCONTOUR_DRAG_R,BOXCONTOUR_DRAG_G,BOXCONTOUR_DRAG_B);
+ }
+ else if(_model->getState()==SELECTED)
+ {
+ _objectActor->GetProperty()->SetLineWidth(2);
+ _objectActor->GetProperty()->SetColor(BOXCONTOUR_SELECTED_R,BOXCONTOUR_SELECTED_G,BOXCONTOUR_SELECTED_B);
+ }
+
+ _baseView->GetRenWin()->Render();
}
//=========================================================================
double xInic, yInic,zInic,xFin, yFin,zFin;
_model->getInicPoint(xInic,yInic,zInic);
_model->getFinalPoint(xFin, yFin,zFin);
- cout<<"RaC ----------"<<endl;
- cout<<"RaC vtkGBlackBoxView::createVtkObjects() inic:"<<xInic<<" "<<yInic<<" "<<zInic<<endl;
- cout<<"RaC vtkGBlackBoxView::createVtkObjects() fin:"<<xFin<<" "<<yFin<<" "<<zFin<<endl;
_pts->SetPoint(0, xInic, yInic, 0 );
_pts->SetPoint(1, xInic, yFin, 0 );
_bboxMapper->SetInput(_pd);
_objectActor->SetMapper(_bboxMapper);
- _objectActor->GetProperty()->SetColor(0.3,0.2,0.2);
+ _objectActor->GetProperty()->SetColor(BOXCONTOUR_NH_R,BOXCONTOUR_NH_G,BOXCONTOUR_NH_B);
}
}
//=========================================================================
- void vtkGObjectView::update()
+ void vtkGObjectView::update()//virtual
{
- if(_model->getState()==NOTHING_HAPPENS)
- {
- _objectActor->GetProperty()->SetColor(0,0,0);
- }
-
- if(_model->getState()==HIGHLIGHTED)
- {
- _objectActor->GetProperty()->SetColor(1,0,0);
- }
- _baseView->GetRenderer()->Render();
- //paint();
+ //virtual
}
//=========================================================================
_pts->SetNumberOfPoints(4);
double xInic, yInic,zInic,xFin, yFin,zFin;
+
_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 );
_bboxMapper->SetInput(_pd);
_objectActor->SetMapper(_bboxMapper);
- _objectActor->GetProperty()->SetColor(0.8,0.0,0.0);
+ _objectActor->GetProperty()->SetColor(BOXCONTOUR_NH_R,BOXCONTOUR_NH_G,BOXCONTOUR_NH_B);
}
std::string packageName="";
std::string boxName="";
-
wxString foo( wxT(data) );
char str[150];
strcpy( str, (const char*)foo.mb_str(wxConvUTF8) );
_sceneManager->createGBlackBox(x,y,packageName, boxName);
- //cout<<"result is pkg:"<<packageName<<" box:"<<boxName<<endl;
- //cout<<"RaC DyD:"<<data<<" x:"<<x<<" t:"<<y<<endl;
return true;
}