virtual void get_in_logic_connect_position(int& _a, int& _b);
virtual void get_out_logic_connect_position(int& _a, int& _b);
virtual void set_out_connected(bool _o);
+ virtual void draw_connectors();
private:
int in_x, in_y, out_x, out_y;
bool out_connected;
/**Detecta si el click fue en el area de entrada o salida logica, devuelve UNDEF si no fue ninguna de las dos
*/
ConnectorType detect_click_position(int _a, int _b);
+ /**Dibuja los conectores logicos, que seran ambos azules pues son salidas.
+ */
+ virtual void draw_connectors();
protected:
/**Atributos que definen su comportamiento
*/
virtual void set_out_connected(bool _o);
virtual void set_in_connected(bool _o);
- /**Dibuja los conectores logicos del Item, AZUL == ENTRADA, ROJO == SALIDA.
+ /**Dibuja los conectores logicos del Item, AZUL == SALIDA, ROJO == ENTRADA.
*/
virtual void draw_connectors();
virtual void get_out_logic_connect_position(int& _a, int& _b);
virtual void set_out_connected(bool _o);
virtual void set_in_connected(bool _o);
+ virtual bool get_out_logic_connect();
+ virtual void draw_connectors();
private:
int in_x, in_y, out_x, out_y;
bool in_connected, out_connected;
virtual void get_in_logic_connect_position(int& _a, int& _b);
virtual void get_out_logic_connect_position(int& _a, int& _b);
virtual void set_out_connected(bool _o);
+ virtual void draw_connectors();
private:
int in_x, in_y, out_x, out_y;
bool out_connected;
std::list<CItem *> *listaItems, *lista_logic_Items;
/** Listas de lineas que van de una compuerta a la entrada de un item y de la salida de un item a una compuerta
- lista_lineas_in = (salida) compuerta --> (entrada) item
- lista_lineas_out= (entrada) compuerta --> (salida) item
+ * lista_lineas_in = (salida) compuerta --> (entrada) item
+ * lista_lineas_out= (entrada) compuerta --> (salida) item
+ * lista_lineas_logic = (salida) compuerta --> (entrada) compuerta.
+ * Esta ultima lista contiene las lineas que van desde la compuerta seleccionada que se guarda en gate_id hasta
+ * la compuerta clickeada en segundo termino.
*/
- std::list<t_line> lista_lineas_in, lista_lineas_out;
+ std::list<t_line> lista_lineas_in, lista_lineas_out, lista_lineas_logic;
/**Variable global que identifica cual item logico fue apuntado para
*conectarlo mediante una linea a un item de transporte
bool And::on_button_press_event(GdkEventButton *event)
{
if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) {
- if ( CItem::logic_connect ) {
- if ( detect_click_position((int)event->x, (int)event->y ) == OUT && !out_connected) {
+ WorkPlace::pointed = ID;
+ t_line tmp_line;
+ std::cout << CItem::gate_id << std::endl;
+ if (CItem::logic_connect) {
+ if (CItem::gate_id != -1 ) {
+ if ( detect_click_position((int)event->x, (int)event->y ) == IN && CItem::gate_id != ID ) {
+ tmp_line.logic_id = CItem::gate_id;
+ workplace->get_logic_item(CItem::gate_id)->set_out_connected(true);
+ tmp_line.store_id = ID;
+ workplace->lista_lineas_logic.push_back(tmp_line);
+ workplace->queue_draw();
+ CItem::gate_id = -1;
+ }
+ } else {
CItem::gate_id = ID;
- WorkPlace::pointed = ID;
}
- if ( detect_click_position((int)event->x, (int)event->y ) == IN ) {
- CItem::gate_id = ID;
- WorkPlace::pointed = ID;
- }
- }
+ }
+ if ( CItem::logic_connect && detect_click_position((int)event->x, (int)event->y ) == OUT && !out_connected) {
+ CItem::gate_id = ID;
+ }
list_pointed->push_back(name);
combo_entry->set_popdown_strings(*list_pointed);
combo_entry->get_entry()->set_text (name);
{
out_connected = _o;
}
+
+void And::draw_connectors()
+{
+ Glib::RefPtr<Gdk::Window> window = get_window();
+ int a,b,c,d;
+ switch (imgActual) {
+ case 0:
+ a = in_x-x;
+ b = in_y-y-5;
+ c = out_x-x-10;
+ d = out_y-y-5;
+ break;
+ case 1:
+ a = in_x-x-5;
+ b = in_y-y;
+ c = out_x-x-5;
+ d = out_y-y-10;
+ break;
+ case 2:
+ a = in_x-x-10;
+ b = in_y-y-5;
+ c = out_x-x;
+ d = out_y-y-5;
+ break;
+ case 3:
+ a = in_x-x-5;
+ b = in_y-y-10;
+ c = out_x-x-5;
+ d = out_y-y;
+ }
+ gc->set_foreground(red);
+ gc->set_background(red);
+ window->draw_rectangle(gc, 1, a, b, 10, 10);
+ gc->set_foreground(blue);
+ gc->set_background(blue);
+ window->draw_rectangle(gc, 1, c, d, 10, 10);
+ queue_draw();
+}
#include "cistern.h"
#include "cisternptywnd.h"
+#include "not.h"
Cistern::Cistern(int orientacion)
{
temp.type = IN;
connect_vec.push_back(temp); // entrada arriba
temp.type = OUT;
- connect_vec.push_back(temp); // salida abajo
+ connect_vec.push_back(temp); // entrada abajo
}
Cistern::~Cistern()
GdkEventExpose e;
t_line tmp_line;
if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) {
+ WorkPlace::pointed = ID;
list_pointed->push_back(name);
combo_entry->set_popdown_strings(*list_pointed);
combo_entry->get_entry()->set_text (name);
- WorkPlace::pointed = ID;
if (CItem::logic_connect && CItem::gate_id != -1) {
if ( detect_click_position((int)event->x, (int)event->y) == IN ){
tmp_line.logic_id = workplace->get_logic_item(CItem::gate_id)->get_id();
workplace->get_logic_item(CItem::gate_id)->set_out_connected(true);
tmp_line.store_id = ID;
- workplace->lista_lineas_in.push_back(tmp_line);
- workplace->queue_draw();
- } else if (detect_click_position((int)event->x, (int)event->y) == OUT) {
-// if (dynamic_cast<Not *>(get_item(temp.logic_id)))
- // get_logic_item(temp.logic_id)->set_in_connected(true);
- tmp_line.logic_id = workplace->get_logic_item(CItem::gate_id)->get_id();
- tmp_line.store_id = ID;
workplace->lista_lineas_out.push_back(tmp_line);
workplace->queue_draw();
+ } else if (detect_click_position((int)event->x, (int)event->y) == OUT ) {
+ if (dynamic_cast<Not *>(workplace->get_logic_item(CItem::gate_id))) {
+ if ( !dynamic_cast<Not *>(workplace->get_logic_item(CItem::gate_id))->get_out_logic_connect()) {
+ workplace->get_logic_item(CItem::gate_id)->set_in_connected(true);
+ tmp_line.logic_id = CItem::gate_id;
+ tmp_line.store_id = ID;
+ workplace->lista_lineas_out.push_back(tmp_line);
+ workplace->queue_draw();
+ }
+ } else {
+ tmp_line.logic_id = CItem::gate_id;
+ tmp_line.store_id = ID;
+ workplace->lista_lineas_out.push_back(tmp_line);
+ workplace->queue_draw();
+ }
}
CItem::gate_id = -1;
}
ConnectorType Cistern::detect_click_position(int _a, int _b)
{
- //VER DONDE CAEN LOS CLICKS!!!!!!!!!!!!!! SI ES CON RESPECTO AL WORKPLACE O AL ITEM!!!
switch(imgActual) {
case 0:
if ( (_a<=32) &&(_a>=0)&&(_b<=32)&&(_b>=0) )
out_y = y + image->get_height();
}
}
+
+void Cistern::draw_connectors()
+{
+ if ( in_x != -1 ) {
+ Glib::RefPtr<Gdk::Window> window = get_window();
+ gc->set_foreground(blue);
+ window->draw_rectangle(gc, 1, in_x-5-x, in_y-y, 10, 10);
+ window->draw_rectangle(gc, 1, out_x-5-x, out_y-y-10, 10, 10);
+ queue_draw();
+ }
+}
}
std::cout << "CARGA COMPLETA" << std::endl;
file_open_selection->hide();
- id = listaItems.size()+lista_logic_Items.size()+1;
+ id = listaItems.size()+lista_logic_Items.size()+2;
}
void Constructor::on_btn_file_ok_clicked()
#include "exclusa.h"
#include "exclusaptywnd.h"
+#include "not.h"
Exclusa::Exclusa(int orientacion)
{
{
t_line tmp_line;
if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) {
+ WorkPlace::pointed = ID;
list_pointed->push_back(name);
combo_entry->set_popdown_strings(*list_pointed);
combo_entry->get_entry()->set_text (name);
- WorkPlace::pointed = ID;
if (CItem::logic_connect && CItem::gate_id != -1) {
if ( detect_click_position((int)event->x, (int)event->y) == IN) {
tmp_line.logic_id = workplace->get_logic_item(CItem::gate_id)->get_id();
tmp_line.store_id = ID;
workplace->lista_lineas_in.push_back(tmp_line);
workplace->queue_draw();
- } else if (detect_click_position((int)event->x, (int)event->y) == OUT) {
- tmp_line.logic_id = workplace->get_logic_item(CItem::gate_id)->get_id();
- tmp_line.store_id = ID;
- workplace->lista_lineas_out.push_back(tmp_line);
- workplace->queue_draw();
+ } else if (detect_click_position((int)event->x, (int)event->y) == OUT ) {
+ if (dynamic_cast<Not *>(workplace->get_logic_item(CItem::gate_id))) {
+ if (!dynamic_cast<Not *>(workplace->get_logic_item(CItem::gate_id))->get_out_logic_connect()) {
+ workplace->get_logic_item(CItem::gate_id)->set_in_connected(true);
+ tmp_line.logic_id = CItem::gate_id;
+ tmp_line.store_id = ID;
+ workplace->lista_lineas_out.push_back(tmp_line);
+ workplace->queue_draw();
+ }
+ } else {
+ tmp_line.logic_id = CItem::gate_id;
+ tmp_line.store_id = ID;
+ workplace->lista_lineas_out.push_back(tmp_line);
+ workplace->queue_draw();
+ }
}
CItem::gate_id = -1;
}
// XXX Esto no deberia ser necesario! en todo caso devolves false en
// vez de true para que siga llamando a los otros handlers :)
//Gtk::DrawingArea::on_expose_event(event);
- if (logic_connect && !is_logic) {
+ if (CItem::logic_connect) {
draw_connectors();
}
return true;
{
if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) {
+ WorkPlace::pointed = ID;
+ t_line tmp_line;
+ if (CItem::logic_connect) {
+ if (CItem::gate_id != -1) {
+ if ( detect_click_position((int)event->x, (int)event->y) == IN && !in_connected) {
+ tmp_line.logic_id = CItem::gate_id;
+ workplace->get_logic_item(CItem::gate_id)->set_out_connected(true);
+ set_in_connected(true);
+ tmp_line.store_id = ID;
+ workplace->lista_lineas_logic.push_back(tmp_line);
+ workplace->queue_draw();
+ CItem::gate_id = -1;
+ }
+ } else
+ CItem::gate_id = ID;
+ }
if ( CItem::logic_connect ) {
if ( detect_click_position((int)event->x, (int)event->y ) == OUT && !out_connected ) {
CItem::gate_id = ID;
- WorkPlace::pointed = ID;
}
if ( detect_click_position((int)event->x, (int)event->y ) == IN && !in_connected) {
CItem::gate_id = ID;
- WorkPlace::pointed = ID;
}
}
list_pointed->push_back(name);
{
in_connected = _o;
}
+
+bool Not::get_out_logic_connect()
+{
+ return out_connected;
+}
+
+void Not::draw_connectors()
+{
+ Glib::RefPtr<Gdk::Window> window = get_window();
+ int a,b,c,d;
+ switch (imgActual) {
+ case 0:
+ a = in_x-x;
+ b = in_y-y-5;
+ c = out_x-x-10;
+ d = out_y-y-5;
+ break;
+ case 1:
+ a = in_x-x-5;
+ b = in_y-y;
+ c = out_x-x-5;
+ d = out_y-y-10;
+ break;
+ case 2:
+ a = in_x-x-10;
+ b = in_y-y-5;
+ c = out_x-x;
+ d = out_y-y-5;
+ break;
+ case 3:
+ a = in_x-x-5;
+ b = in_y-y-10;
+ c = out_x-x-5;
+ d = out_y-y;
+ }
+ gc->set_foreground(red);
+ gc->set_background(red);
+ window->draw_rectangle(gc, 1, a, b, 10, 10);
+ gc->set_foreground(blue);
+ gc->set_background(blue);
+ window->draw_rectangle(gc, 1, c, d, 10, 10);
+ queue_draw();
+}
bool Or::on_button_press_event(GdkEventButton *event)
{
if ((event->type == GDK_BUTTON_PRESS) && ( event->button == 1)) {
+ WorkPlace::pointed = ID;
+ t_line tmp_line;
+ if (CItem::logic_connect) {
+ if (CItem::gate_id != -1) {
+ if ( detect_click_position((int)event->x, (int)event->y) == IN) {
+ tmp_line.logic_id = CItem::gate_id;
+ workplace->get_logic_item(CItem::gate_id)->set_out_connected(true);
+ tmp_line.store_id = ID;
+ workplace->lista_lineas_logic.push_back(tmp_line);
+ workplace->queue_draw();
+ }
+ } else
+ CItem::gate_id = ID;
+ }
if ( CItem::logic_connect ) {
if ( detect_click_position((int)event->x, (int)event->y ) == OUT && !out_connected) {
CItem::gate_id = ID;
- WorkPlace::pointed = ID;
}
- if ( detect_click_position((int)event->x, (int)event->y ) == IN ) {
- CItem::gate_id = ID;
- WorkPlace::pointed = ID;
- }
}
list_pointed->push_back(name);
combo_entry->set_popdown_strings(*list_pointed);
{
out_connected = _o;
}
+
+void Or::draw_connectors()
+{
+ Glib::RefPtr<Gdk::Window> window = get_window();
+ int a,b,c,d;
+ switch (imgActual) {
+ case 0:
+ a = in_x-x;
+ b = in_y-y-5;
+ c = out_x-x-10;
+ d = out_y-y-5;
+ break;
+ case 1:
+ a = in_x-x-5;
+ b = in_y-y;
+ c = out_x-x-5;
+ d = out_y-y-10;
+ break;
+ case 2:
+ a = in_x-x-10;
+ b = in_y-y-5;
+ c = out_x-x;
+ d = out_y-y-5;
+ break;
+ case 3:
+ a = in_x-x-5;
+ b = in_y-y-10;
+ c = out_x-x-5;
+ d = out_y-y;
+ }
+ gc->set_foreground(red);
+ gc->set_background(red);
+ window->draw_rectangle(gc, 1, a, b, 10, 10);
+ gc->set_foreground(blue);
+ gc->set_background(blue);
+ window->draw_rectangle(gc, 1, c, d, 10, 10);
+ queue_draw();
+}
#include "pump.h"
#include "pumpptywnd.h"
+#include "not.h"
Pump::Pump(int orientacion)
{
combo_entry->set_popdown_strings(*list_pointed);
combo_entry->get_entry()->set_text (name);
WorkPlace::pointed = ID;
+ std::cout<< "CItem::gate_id = "<<CItem::gate_id<<std::endl;
if (CItem::logic_connect && CItem::gate_id != -1) {
if ( detect_click_position((int)event->x, (int)event->y) == IN) {
- tmp_line.logic_id = workplace->get_logic_item(CItem::gate_id)->get_id();
+ tmp_line.logic_id = CItem::gate_id;
workplace->get_logic_item(CItem::gate_id)->set_out_connected(true);
tmp_line.store_id = ID;
workplace->lista_lineas_in.push_back(tmp_line);
workplace->queue_draw();
- } else if (detect_click_position((int)event->x, (int)event->y) == OUT) {
- tmp_line.logic_id = workplace->get_logic_item(CItem::gate_id)->get_id();
- tmp_line.store_id = ID;
- workplace->lista_lineas_out.push_back(tmp_line);
- workplace->queue_draw();
+ } else if (detect_click_position((int)event->x, (int)event->y) == OUT ) {
+ if (dynamic_cast<Not *>(workplace->get_logic_item(CItem::gate_id))) {
+ if ( !dynamic_cast<Not *>(workplace->get_logic_item(CItem::gate_id))->get_out_logic_connect()) {
+ workplace->get_logic_item(CItem::gate_id)->set_in_connected(true);
+ tmp_line.logic_id = CItem::gate_id;
+ tmp_line.store_id = ID;
+ workplace->lista_lineas_out.push_back(tmp_line);
+ workplace->queue_draw();
+ }
+ } else {
+ tmp_line.logic_id = CItem::gate_id;
+ tmp_line.store_id = ID;
+ workplace->lista_lineas_out.push_back(tmp_line);
+ workplace->queue_draw();
+ }
}
CItem::gate_id = -1;
}
y_offset = -15;
}
get_logic_item(temp.logic_id)->get_out_logic_connect_position(a, b);
- get_logic_item(temp.logic_id)->set_out_connected(true);
get_item(temp.store_id)->get_in_logic_connect_position(w,z);
draw_line(a+x_offset, b+y_offset, w+item_x_offset, z+item_y_offset, color_in);
get_window()->draw_line(gc, a, b, a+x_offset, b+y_offset);
y_offset = 15;
}
get_item(temp.store_id)->get_out_logic_connect_position(w,z);
- if (dynamic_cast<Not *>(get_logic_item(temp.logic_id)))
- get_logic_item(temp.logic_id)->set_in_connected(true);
get_logic_item(temp.logic_id)->get_in_logic_connect_position(a, b);
draw_line(w+item_y_offset, z+item_y_offset, a+x_offset, b+y_offset,color_out);
get_window()->draw_line(gc, a, b, a+x_offset, b+y_offset);
}
i++;
}
+
+ i = lista_lineas_logic.begin();
+ while ( i != lista_lineas_logic.end() ) {
+ t_line temp = *i;
+ if ( get_logic_item(temp.store_id) != NULL && get_logic_item(temp.logic_id) != NULL ) {
+ get_logic_item(temp.logic_id)->get_out_logic_connect_position(w,z);
+ get_logic_item(temp.store_id)->get_in_logic_connect_position(a, b);
+ get_window()->draw_line(gc, a, b, w,z);
+ }
+ i++;
+ }
return true;
}