bool Cistern::on_button_press_event(GdkEventButton *event)
{
- if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1))
+ GdkEventExpose e;
+ CItem *logic_item;
+ t_line tmp_line;
+ if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) {
combo_entry->set_text(name);
+ if (CItem::logic_connect) {
+ std::cout<<workplace<<std::endl;
+ tmp_line.logic = workplace->get_logic_item(CItem::quien);
+ tmp_line.store = this;
+ workplace->lista_lineas.push_back(tmp_line);
+ workplace->on_expose_event(&e);
+
+ }
+ CItem::logic_connect = false;
+ }
if ((event->type == GDK_BUTTON_PRESS) && ( event->button ==2)){
image = null;
workplace->drag_dest_set(listTargets);
workplace->signal_drag_data_received().connect( SigC::slot(*this, &Constructor::on_item_drop_drag_received) );
workplace->listaItems = &listaItems;
+ workplace->listaItems = &lista_logic_Items;
logica = false;
}
void Constructor::on_item_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context, CItem *item)
{
+ GdkEventExpose e;
context->set_icon(item->get_image(), 5, 5);
+ workplace->on_expose_event(&e);
}
void Constructor::on_item_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, GtkSelectionData* selection_data, guint info, guint time)
if ((selection_data->length >= 0) && (selection_data->format == 8)) {
CItem *a;
if (strcmp((const char *)selection_data->data, "codo_o.png")==0)
- a = new Splitter();
- else if (strcmp((const char *)selection_data->data, "canio_n.png")==0)
- a = new Conduct();
- else if (strcmp((const char *)selection_data->data, "y_n.png")==0)
- a = new Union();
- else if (strcmp((const char *)selection_data->data, "tanque_e.png")==0)
- a = new Cistern();
- else if (strcmp((const char *)selection_data->data, "bomba_e.png")==0)
- a =new Pump();
- else if (strcmp((const char *)selection_data->data, "exclusa_h.png")==0)
- a = new Exclusa();
- else if (strcmp((const char *)selection_data->data, "drain_n.png")==0)
- a = new Drain();
- else if (strcmp((const char *)selection_data->data, "and_e.png")==0)
- a = new And();
- else if (strcmp((const char *)selection_data->data, "or_e.png")==0)
- a = new Or();
- else if (strcmp((const char *)selection_data->data, "not_e.png")==0)
- a = new Not();
+ a = new Splitter();
+ else if (strcmp((const char *)selection_data->data, "canio_n.png")==0)
+ a = new Conduct();
+ else if (strcmp((const char *)selection_data->data, "y_n.png")==0)
+ a = new Union();
+ else if (strcmp((const char *)selection_data->data, "tanque_e.png")==0)
+ a = new Cistern();
+ else if (strcmp((const char *)selection_data->data, "bomba_e.png")==0)
+ a =new Pump();
+ else if (strcmp((const char *)selection_data->data, "exclusa_h.png")==0)
+ a = new Exclusa();
+ else if (strcmp((const char *)selection_data->data, "drain_n.png")==0)
+ a = new Drain();
+ else if (strcmp((const char *)selection_data->data, "and_e.png")==0){
+ a = new And(); a->is_logic = true;
+ } else if (strcmp((const char *)selection_data->data, "or_e.png")==0) {
+ a = new Or(); a->is_logic = true;
+ } else if (strcmp((const char *)selection_data->data, "not_e.png")==0) {
+ a = new Not(); a->is_logic = true;
+ }
char char_id[10];
sprintf(char_id,"%d",id);
- a->set_id(++id);
+ a->set_id(id++);
a->set_name( a->get_name()+char_id );
if ( can_drop(a, i*32, j*32) ) {
workplace->put(*a, i*32, j*32);
a->combo_entry = combo_entry;
//Apunto a la listaItems.
a->listaItems = &listaItems;
+ //Apunto a la lista de items logicos
+ a->lista_logic_Items = &lista_logic_Items;
//Seteo la posicion del item
a->set_position(i*32,j*32);
// Seteo la lista de tipos de drags
// raro se vea el widget tal cual.
a->signal_drag_begin().connect(SigC::bind( SigC::slot(*this, &Constructor::on_item_drag_begin), a));
a->show();
- listaItems.push_back(a);
+ if (! a->is_logic )
+ listaItems.push_back(a);
+ else
+ lista_logic_Items.push_back(a);
} else {
id--;
delete a;
Glib::RefPtr<Gdk::Pixbuf> ico_canio, ico_y, ico_codo, ico_tanque, ico_bomba, ico_exclusa, ico_drain, ico_and, ico_or, ico_not;
Glib::RefPtr<Gdk::Pixbuf> ico_last;
std::list<Gtk::TargetEntry> listTargets;
- std::list<CItem *> listaItems;
+ std::list<CItem *> listaItems, lista_logic_Items;
WorkPlace *workplace;
bool logica;
bool can_drop(CItem *, int , int);
#include "item.h"
-#include "workplace.h"
+
+bool CItem:: logic_connect = false;
+int CItem::quien = -1;
+
CItem::CItem(const char *filename):Gtk::DrawingArea()
{
caudal_max = 0.0;
is_union = true;
is_connected = false;
+ is_logic =false;
property_wnd->item = this;
menu_image_propiedades.set(Gtk::Stock::PREFERENCES, Gtk::ICON_SIZE_MENU);
menu_image_delete.set(Gtk::Stock::CANCEL, Gtk::ICON_SIZE_MENU);
#include <libglademm.h>
#include <gtkmm/entry.h>
#include "itemptywnd.h"
+#include "workplace.h"
///Tipo de estado en el que pueden estar los conectores de un item
typedef enum { UNDEF, IN, OUT } ConnectorType;
}
};
-class WorkPlace;
+//class WorkPlace;
class CItem:public Gtk::DrawingArea {
public:
///Puntero a la lista de items
std::list<CItem *> *listaItems;
+ ///Puntero a la lista de Items logicos
+ std::list<CItem *> *lista_logic_Items;
+
///TODO poner esto en Union y crear una ventana nueva de propiedades
bool is_union;
///indica si el item ya esta conectado con sus conectores bien definidos
bool is_connected;
+ ///Indica si es una compuerta logica
+ bool is_logic;
+
+ ///Indica si puede realizarse la conexion logica con una compuerta
+ static bool logic_connect;
+ static int quien;
+
/**Vector de connectores donde se mantiene la siguiente referencia:
* indice 0 = "arriba/izquierda" para la exclusa, el tubo, el codo, el empalme y el tanque.
* "derecha" para la bomba.
protected:
///Indica el numero que le corresponde a la imagen actual del item.
int imgActual;
+
///Numero "unico" que identifica al item.
int ID;
+
///Nombre del item
Glib::ustring name;
+
///Caudal maximo que puede contener un item.
double caudal_max;
+
///Menu flotante del item
Gtk::Menu menu_popup;
+
///Lista de opciones del menu flotante
Gtk::Menu::MenuList menulist;
+
///Imagenes del menu flotante
Gtk::Image menu_image_delete, menu_image_rotar, menu_image_propiedades, menu_image_linea;
+
///Puntero a la imagen del item
Glib::RefPtr<Gdk::Pixbuf> image;
+
///Puntero a la ventana de propiedades del item
ItemPtyWnd *property_wnd;
+
///Posicion del item en el area de trabajo
int x, y;
};
bool Or::on_button_press_event(GdkEventButton *event)
{
- if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1))
+ if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) {
+ std::cout<<ID<<std::endl;
combo_entry->set_text(name);
+ }
if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 2)){
image = null;
}
return true;
}
+
void Or::on_menu_popup_rotar()
{
GdkEventButton event;
Or::on_button_press_event(&event);
}
-
+void Or::on_menu_popup_conectar()
+{
+ CItem::logic_connect = true;
+ CItem::quien = ID;
+}
void Or::save(FILE *archivo)
{
virtual ~Or();
virtual bool on_button_press_event(GdkEventButton *event);
virtual void on_menu_popup_rotar();
+ virtual void on_menu_popup_conectar();
virtual void save(FILE *archivo);
virtual bool check_connection();
+ std::list<int> connected_items;
private:
Glib::RefPtr<Gdk::Pixbuf> imageN; // 0
Glib::RefPtr<Gdk::Pixbuf> imageS; // 1
#include "workplace.h"
+#include "item.h"
WorkPlace::WorkPlace( BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml> &refGlade):Gtk::Fixed(cobject)
{
- refGlade->get_widget_derived("viewport",viewport);
- viewport->workplace = this;
}
WorkPlace::~WorkPlace()
get_window()->draw_point (get_style()->get_black_gc(), x-1,y);
}
-/* std::list<t_line>::iterator i = lista_lineas.begin();
+ std::list<t_line>::iterator i = lista_lineas.begin();
while ( i != lista_lineas.end() ) {
t_line temp = *i;
- get_window()->draw_line (get_style()->get_black_gc(), temp.x,temp.y,temp.w,temp.z);
+ get_window()->draw_line (get_style()->get_black_gc(), temp.logic->get_position_x(),temp.logic->get_position_y(), temp.store->get_position_x(),temp.store->get_position_y());
i++;
- }*/
+ }
return true;
}
i++;
}
}
+
+CItem* WorkPlace::get_logic_item(int _id)
+{
+ std::list<CItem *>::iterator i = lista_logic_Items->begin();
+ while ( i != lista_logic_Items->end() ){
+ CItem *temp = *i;
+ if ( temp->get_id() == _id )
+ return temp;
+ i++;
+ }
+ return NULL;
+}
#include <gdkmm/gc.h>
#include <gtkmm.h>
#include <libglademm.h>
-#include "activezone.h"
-#include "item.h"
class CItem;
-class ActiveZone;
+
+typedef struct {
+ CItem *logic, *store;
+}t_line;
class WorkPlace:public Gtk::Fixed {
public:
virtual ~WorkPlace();
virtual bool on_expose_event(GdkEventExpose *event);
void delete_item(int _id);
- std::list<CItem *> *listaItems;
+ CItem *get_logic_item(int _id);
+ std::list<CItem *> *listaItems, *lista_logic_Items;
std::list<t_line> lista_lineas;
- ActiveZone *viewport;
};
#endif