[Jderobot-admin] jderobot-r882 - tags/jde-old_29-09-2008 tags/old-5.0/examples/jde-swig trunk/src/components/visualHFSM-3.1
bmenendez en jderobot.org
bmenendez en jderobot.org
Dom Mar 10 14:06:56 CET 2013
Author: bmenendez
Date: 2013-03-10 14:05:56 +0100 (Sun, 10 Mar 2013)
New Revision: 882
Added:
trunk/src/components/visualHFSM-3.1/CMakeLists.txt
trunk/src/components/visualHFSM-3.1/build/
trunk/src/components/visualHFSM-3.1/camera.cpp
trunk/src/components/visualHFSM-3.1/camera.h
trunk/src/components/visualHFSM-3.1/generate.cpp
trunk/src/components/visualHFSM-3.1/int2string.cpp
trunk/src/components/visualHFSM-3.1/int2string.h
trunk/src/components/visualHFSM-3.1/interfaz.cpp
trunk/src/components/visualHFSM-3.1/interfaz.h
trunk/src/components/visualHFSM-3.1/nodo.cpp
trunk/src/components/visualHFSM-3.1/nodo.h
trunk/src/components/visualHFSM-3.1/recta.cpp
trunk/src/components/visualHFSM-3.1/recta.h
trunk/src/components/visualHFSM-3.1/reemplazar.cpp
trunk/src/components/visualHFSM-3.1/reemplazar.h
trunk/src/components/visualHFSM-3.1/tipos.h
trunk/src/components/visualHFSM-3.1/transicion.cpp
trunk/src/components/visualHFSM-3.1/transicion.h
trunk/src/components/visualHFSM-3.1/ventanas.cpp
trunk/src/components/visualHFSM-3.1/ventanas.h
trunk/src/components/visualHFSM-3.1/xml.cpp
trunk/src/components/visualHFSM-3.1/xml.h
Modified:
tags/jde-old_29-09-2008/
tags/old-5.0/examples/jde-swig/
Log:
[bmenendez] Merge de la 881 a la 880 por haberla liado
Property changes on: tags/jde-old_29-09-2008
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: tags/old-5.0/examples/jde-swig
___________________________________________________________________
Deleted: svn:mergeinfo
-
Added: trunk/src/components/visualHFSM-3.1/CMakeLists.txt
===================================================================
--- trunk/src/components/visualHFSM-3.1/CMakeLists.txt (rev 0)
+++ trunk/src/components/visualHFSM-3.1/CMakeLists.txt 2013-03-10 13:05:56 UTC (rev 882)
@@ -0,0 +1,70 @@
+cmake_minimum_required(VERSION 2.8)
+include(FindPkgConfig)
+
+SET( SOURCE_FILES_GENERATE reemplazar.cpp generate.cpp )
+SET( SOURCE_FILES_VISUALHFSM int2string.cpp recta.cpp nodo.cpp transicion.cpp ventanas.cpp xml.cpp interfaz.cpp )
+
+SET( INTERFACES_CPP_DIR /usr/local/lib )
+SET( LIBS_DIR /usr/include )
+
+SET( CMAKE_CXX_FLAGS "-g -Wall -fpermissive" ) # Opciones para el compilador
+
+include_directories (
+ /usr/include/gtksourceview-2.0
+ ${INTERFACES_CPP_DIR}
+ ${LIBS_DIR}
+)
+
+PKG_CHECK_MODULES(gtk20 REQUIRED gtk+-2.0)
+include_directories(${gtk20_INCLUDE_DIRS})
+link_directories(${gtk20_LIBRARY_DIRS})
+
+PKG_CHECK_MODULES(gtkmm REQUIRED gtkmm-2.4)
+include_directories(${gtkmm_INCLUDE_DIRS})
+link_directories(${gtkmm_LIBRARY_DIRS})
+
+PKG_CHECK_MODULES(libglademm REQUIRED libglademm-2.4)
+include_directories(${libglademm_INCLUDE_DIRS})
+link_directories(${libglademm_LIBRARY_DIRS})
+
+PKG_CHECK_MODULES(libglade REQUIRED libglade-2.0)
+include_directories(${libglade_INCLUDE_DIRS})
+link_directories(${libglade_LIBRARY_DIRS})
+
+PKG_CHECK_MODULES(libgnomecanvas REQUIRED libgnomecanvas-2.0)
+include_directories(${libgnomecanvas_INCLUDE_DIRS})
+link_directories(${libgnomecanvas_LIBRARY_DIRS})
+
+PKG_CHECK_MODULES(libgnomecanvasmm REQUIRED libgnomecanvasmm-2.6)
+include_directories(${libgnomecanvasmm_INCLUDE_DIRS})
+link_directories(${libgnomecanvasmm_LIBRARY_DIRS})
+
+PKG_CHECK_MODULES(libxml REQUIRED libxml-2.0)
+include_directories(${libxml_INCLUDE_DIRS})
+link_directories(${libxml_LIBRARY_DIRS})
+
+PKG_CHECK_MODULES(gtk+-unix-print REQUIRED gtk+-unix-print-2.0)
+include_directories(${gtk+-unix-print_INCLUDE_DIRS})
+link_directories(${gtk+-unix-print_LIBRARY_DIRS})
+
+message(${gtk20_LIBRARIES})
+
+add_executable (generate ${SOURCE_FILES_GENERATE})
+
+TARGET_LINK_LIBRARIES ( generate
+ ${libxml_LIBRARIES}
+)
+
+add_executable (visualHFSM ${SOURCE_FILES_VISUALHFSM})
+
+TARGET_LINK_LIBRARIES ( visualHFSM
+ ${gtkmm_LIBRARIES}
+ ${libglademm_LIBRARIES}
+ ${libglade_LIBRARIES}
+ ${libgnomecanvasmm_LIBRARIES}
+ ${libgnomecanvas_LIBRARIES}
+ ${gtk+-unix-print_LIBRARIES}
+ ${gtk20_LIBRARIES}
+ ${libxml_LIBRARIES}
+ /usr/lib/libgtksourceview-2.0.so
+)
Added: trunk/src/components/visualHFSM-3.1/camera.cpp
===================================================================
--- trunk/src/components/visualHFSM-3.1/camera.cpp (rev 0)
+++ trunk/src/components/visualHFSM-3.1/camera.cpp 2013-03-10 13:05:56 UTC (rev 882)
@@ -0,0 +1,378 @@
+/*
+ * Copyright (C) 2008 Roberto Calvo Palomino
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors : Roberto Calvo Palomino <rocapal en gsyc.escet.urjc.es>,
+ * Jose María Cañas Plaza <jmplaza en gsyc.es>
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include "camera.h"
+
+#define DEBUG(x...) printf(x)
+#define N_LINES_CAM 16
+#define DESVIACIONY 0
+#define DESVIACIONZ 0
+
+
+camera::camera (char* configFile): m_nameFile(NULL),
+ m_R (NULL),
+ m_RES (NULL),
+ m_RT (NULL),
+ m_T (NULL),
+ m_K (NULL),
+ m_pos (NULL)
+{
+ if (configFile!=NULL)
+ {
+ m_nameFile = (char*) malloc (sizeof(char)*(strlen(configFile)+1));
+ if (m_nameFile)
+ {
+ strncpy(m_nameFile,configFile,strlen(configFile));
+ m_nameFile[strlen(configFile)]='\0';
+ }
+ }
+
+ m_R = gsl_matrix_alloc(3,3);
+ m_K = gsl_matrix_alloc(3,3);
+ m_T = gsl_matrix_alloc(3,4);
+ m_RT = gsl_matrix_alloc(4,4);
+ m_RES = gsl_matrix_alloc(3,4);
+
+ m_pos = gsl_vector_alloc(3);
+
+}
+
+/// \brief Destructor
+camera::~camera()
+{
+ if (m_nameFile)
+ free(m_nameFile);
+
+ if (m_R)
+ gsl_matrix_free(m_R);
+
+ if (m_RES)
+ gsl_matrix_free(m_RES);
+
+ if (m_RT)
+ gsl_matrix_free(m_RT);
+
+ if (m_T)
+ gsl_matrix_free(m_T);
+
+ if (m_K)
+ gsl_matrix_free(m_K);
+
+ if (m_pos)
+ gsl_vector_free(m_pos);
+
+}
+
+TPinHoleCamera& camera::readConfig()
+{
+
+ const int limit = 256;
+ char word1[limit],word2[limit];
+ int i=0;
+ char buffer_file[limit];
+ int number;
+ FILE *myfile;
+ int k=0;
+ int counter=0;
+
+ if ((myfile=fopen(m_nameFile,"r"))==NULL){
+ printf("Cannot find camera configuration file\n");
+ //return -1;
+ }
+
+
+ DEBUG("camera::readConfig: %s\n",m_nameFile);
+
+ do{
+ again:
+ i=0;
+ buffer_file[0]=fgetc(myfile);
+ if (feof(myfile))
+ k=EOF;
+ if (buffer_file[0]==(char)255)
+ k=EOF;
+ if (buffer_file[0]==' '){
+ while(buffer_file[0]==' ')
+ buffer_file[0]=fgetc(myfile);
+ }
+ if (buffer_file[0]=='#'){
+ while(buffer_file[0]=fgetc(myfile)!='\n');
+ goto again;
+ }
+ if (buffer_file[0]==' '){
+ while(buffer_file[0]==' ')
+ buffer_file[0]=fgetc(myfile);
+ }
+ if (buffer_file[0]=='\t'){
+ while(buffer_file[0]=='\t')
+ buffer_file[0]=fgetc(myfile);
+ }
+
+
+
+
+ /* Captures a line and then we will process it with sscanf checking that the last character is \n. We can't doit with fscanf because this function does not difference \n from blank space. */
+ while ((buffer_file[i]!='\n')&&(buffer_file[i] != (char)255) && (i<limit-1)) {
+ buffer_file[++i]=fgetc(myfile);
+ }
+ buffer_file[i]='\n';
+
+
+ if (i >= limit-1) {
+ printf("%s...\n", buffer_file);
+ printf ("Line too long in config file!\n");
+ exit(-1);
+ }
+ buffer_file[++i]='\0';
+
+ if (sscanf(buffer_file,"%s",word1)!=1){
+ }
+ else {
+ number=sscanf(buffer_file,"%s %s ",word1,word2);
+ if (strcmp(word1,"positionX")==0){
+ cam.position.X=atof(word2);
+ counter++;
+ }
+ else if (strcmp(word1,"positionY")==0){
+ cam.position.Y=atof(word2);
+ counter++;
+ }
+ else if (strcmp(word1,"positionZ")==0){
+ cam.position.Z=atof(word2);
+ counter++;
+ }
+ else if (strcmp(word1,"positionH")==0){
+ cam.position.H=atof(word2);
+ counter++;
+ }
+ else if (strcmp(word1,"FOApositionX")==0){
+ cam.foa.X=atof(word2);
+ counter++;;
+ }
+ else if (strcmp(word1,"FOApositionY")==0){
+ cam.foa.Y=atof(word2)-DESVIACIONY;
+ counter++;
+ }
+ else if (strcmp(word1,"FOApositionZ")==0){
+ cam.foa.Z=atof(word2)-DESVIACIONZ;
+ counter++;
+ }
+ else if (strcmp(word1,"FOApositionH")==0){
+ cam.foa.H=atof(word2);
+ counter++;
+ }
+ else if (strcmp(word1,"roll")==0){
+ cam.roll=atof(word2);
+ //cam.roll=3.14/2;
+ counter++;
+ }
+ else if (strcmp(word1,"fx")==0){
+ cam.fdistx=atof(word2);
+ counter++;
+ }
+ else if (strcmp(word1,"fy")==0){
+ cam.fdisty=atof(word2);
+ counter++;
+ }
+ else if (strcmp(word1,"skew")==0){
+ cam.skew=atof(word2);
+ counter++;
+ }
+ else if (strcmp(word1,"u0")==0){
+ cam.u0=atof(word2);
+ counter++;
+ }
+ else if (strcmp(word1,"v0")==0){
+ cam.v0=atof(word2);
+ counter++;
+ }
+ else if (strcmp(word1,"columns")==0){
+ cam.columns=atof(word2);
+ counter++;
+ }
+ else if (strcmp(word1,"rows")==0){
+ cam.rows=atof(word2);
+ counter++;
+ }
+ else{
+ printf("NaoVision: line: %s not valid in camera configuration file\n",buffer_file);
+ }
+ }
+ } while(k!=EOF);
+
+ update_camera_matrix(&cam);
+ //if (counter==N_LINES_CAM){
+ //return 1;
+ //}
+
+
+ //updateMatrix();
+
+ //return true;
+ return cam;
+}
+
+void camera::updateMatrix()
+{
+/*
+ // Fill matrix T
+ gsl_matrix_set(m_T, 0,0,1);
+ gsl_matrix_set(m_T, 1,1,1);
+ gsl_matrix_set(m_T, 2,2,1);
+
+ gsl_matrix_set(m_T,0,3,gsl_vector_get(m_pos,0));
+ gsl_matrix_set(m_T,1,3,gsl_vector_get(m_pos,1));
+ gsl_matrix_set(m_T,2,3,gsl_vector_get(m_pos,2));
+
+ // Multiplicate R * T = RES
+ gsl_linalg_matmult (m_R,m_T,m_RES);
+
+
+ for (int i=0;i<3;i++)
+ for (int j=0;j<4;j++)
+ gsl_matrix_set(m_RT,i,j,gsl_matrix_get(m_RES,i,j));
+
+ // set 0001 in the last row of RT
+ gsl_matrix_set(m_RT,3,0,0);
+ gsl_matrix_set(m_RT,3,1,0);
+ gsl_matrix_set(m_RT,3,2,0);
+ gsl_matrix_set(m_RT,3,3,1);
+
+ //gsl_matrix_set(m_K,0,2,142.60000610);
+ //gsl_matrix_set(m_K,1,2,150.39999390);
+
+ //gsl_matrix_set(m_K,1,1,gsl_matrix_get(m_K,0,0));
+ gsl_matrix_set(m_K,0,1,0.0);
+ */
+
+}
+
+TPinHoleCamera& camera::getProgeoCam()
+{
+/*
+ HPoint3D positionCam;
+
+ positionCam.X= -gsl_vector_get(m_pos,0);
+ positionCam.Y= -gsl_vector_get(m_pos,1);
+ positionCam.Z= -gsl_vector_get(m_pos,2);
+ positionCam.H= 0.0;
+
+ m_progeoCam.position = positionCam;
+
+ // Seting intrensic matrix
+ m_progeoCam.k11 = gsl_matrix_get(m_K,0,0);
+ m_progeoCam.k12 = gsl_matrix_get(m_K,0,1);
+ m_progeoCam.k13 = gsl_matrix_get(m_K,0,2);
+ m_progeoCam.k14 = 0;
+
+ m_progeoCam.k21 = gsl_matrix_get(m_K,1,0);
+ m_progeoCam.k22 = gsl_matrix_get(m_K,1,1);
+ m_progeoCam.k23 = gsl_matrix_get(m_K,1,2);
+ m_progeoCam.k24 = 0;
+
+ m_progeoCam.k31 = gsl_matrix_get(m_K,2,0);
+ m_progeoCam.k32 = gsl_matrix_get(m_K,2,1);
+ m_progeoCam.k33 = gsl_matrix_get(m_K,2,2);
+ m_progeoCam.k34 = 0;
+
+ // Seting extrensic
+ m_progeoCam.rt11 = gsl_matrix_get(m_RT,0,0);
+ m_progeoCam.rt12 = gsl_matrix_get(m_RT,0,1);
+ m_progeoCam.rt13 = gsl_matrix_get(m_RT,0,2);
+ m_progeoCam.rt14 = gsl_matrix_get(m_RT,0,3);
+
+ m_progeoCam.rt21 = gsl_matrix_get(m_RT,1,0);
+ m_progeoCam.rt22 = gsl_matrix_get(m_RT,1,1);
+ m_progeoCam.rt23 = gsl_matrix_get(m_RT,1,2);
+ m_progeoCam.rt24 = gsl_matrix_get(m_RT,1,3);
+
+ m_progeoCam.rt31 = gsl_matrix_get(m_RT,2,0);
+ m_progeoCam.rt32 = gsl_matrix_get(m_RT,2,1);
+ m_progeoCam.rt33 = gsl_matrix_get(m_RT,2,2);
+ m_progeoCam.rt34 = gsl_matrix_get(m_RT,2,3);
+
+ m_progeoCam.rt41 = gsl_matrix_get(m_RT,3,0);
+ m_progeoCam.rt42 = gsl_matrix_get(m_RT,3,1);
+ m_progeoCam.rt43 = gsl_matrix_get(m_RT,3,2);
+ m_progeoCam.rt44 = gsl_matrix_get(m_RT,3,3);
+
+ return m_progeoCam;
+*/
+}
+
+void camera::test()
+{
+
+ HPoint3D point3D;
+ HPoint2D point2D;
+
+ point3D.X = 10;
+ point3D.Y = 10;
+ point3D.Z = 10;
+ point3D.H = 1;
+
+ printf ("======== TEST 1 ========\n");
+
+ if (project(point3D, &point2D, cam))
+ printf("Project a 2D: %2.2f,%2.2f,%2.2f \n",point2D.x,point2D.y,point2D.h);
+ else
+ printf("Error in project\n");
+
+ point2D.h=1.0;
+ if (backproject(&point3D,point2D,cam)!=-1)
+ printf("Backproject a 3D (de nuevo): %.2f,%.2f,%.2f,%.2f \n",point3D.X, point3D.Y, point3D.Z, point3D.H);
+ else
+ printf("Error in backproject\n");
+
+ printf ("======== TEST 2 ========\n");
+
+ point2D.x = 85.;
+ point2D.y = 154.;
+ point2D.h = 1.;
+
+ printf ("Pto en 2D: %2.2f,%2.2f,%2.2f \n",point2D.x,point2D.y,point2D.h);
+
+ if (backproject(&point3D,point2D,cam)!=-1)
+ printf("Backproject a 3D: %.2f,%.2f,%.2f,%.2f \n",point3D.X, point3D.Y, point3D.Z, point3D.H);
+ else
+ printf("Error in backproject\n");
+
+ if (project(point3D, &point2D, cam))
+ printf("Project a 2D (de nuevo): %2.2f,%2.2f,%2.2f \n",point2D.x,point2D.y,point2D.h);
+ else
+ printf("Error in project\n");
+
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
Added: trunk/src/components/visualHFSM-3.1/camera.h
===================================================================
--- trunk/src/components/visualHFSM-3.1/camera.h (rev 0)
+++ trunk/src/components/visualHFSM-3.1/camera.h 2013-03-10 13:05:56 UTC (rev 882)
@@ -0,0 +1,88 @@
+
+/*
+ * Copyright (C) 2008 Roberto Calvo Palomino
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors : Roberto Calvo Palomino <rocapal en gsyc.escet.urjc.es>,
+ * Jose María Cañas Plaza <jmplaza en gsyc.es>
+ *
+ */
+
+#ifndef CAMERA_H_
+#define CAMERA_H_
+
+/**
+ \class camera
+ \brief This class implement a camera instance
+ \autor Roberto Calvo <rocapal en gsyc.es>
+ \date 17/05/2008
+**/
+
+#include <gsl/gsl_linalg.h>
+#include <gsl/gsl_multifit.h>
+
+extern "C"
+{
+#include "progeo/progeo.h"
+}
+
+class camera
+{
+ public:
+ /// \brief Constructor
+ camera (char* configFile);
+
+ /// \brief Destructor
+ ~camera();
+
+ /// \brief Reaf file config and fill the matrix R and K
+ TPinHoleCamera& readConfig();
+
+ /// \brief Return a progeo camera with configurated matrix
+ TPinHoleCamera& getProgeoCam();
+
+ /// \brief Do test of cams
+ void test();
+
+ private:
+
+ /// \brief Update Matrix
+ void updateMatrix();
+
+ /// \brief
+ //TPinHoleCamera m_progeoCam;
+ TPinHoleCamera cam;
+ /// \brief name file
+ char* m_nameFile;
+
+ /// \brief R Matrix
+ gsl_matrix *m_R;
+
+ /// \brief aux Matrix
+ gsl_matrix *m_RES;
+
+ /// \brief RT Matrix
+ gsl_matrix *m_RT;
+
+ /// \brief T Matrix
+ gsl_matrix *m_T;
+
+ /// \brief K Matrix
+ gsl_matrix *m_K;
+
+ /// \brief Position vector of cam (x,y,z)
+ gsl_vector *m_pos;
+};
+#endif /*CAMERA_H_*/
Added: trunk/src/components/visualHFSM-3.1/generate.cpp
===================================================================
--- trunk/src/components/visualHFSM-3.1/generate.cpp (rev 0)
+++ trunk/src/components/visualHFSM-3.1/generate.cpp 2013-03-10 13:05:56 UTC (rev 882)
@@ -0,0 +1,1606 @@
+
+//#include <string.h>
+
+#include <stdio.h>
+
+#include <stdlib.h>
+#include <math.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <ctype.h>
+#include <sys/stat.h>
+//#include <boost/filesystem.hpp>
+
+
+
+#include <sstream>
+#include <iostream>
+#include <string>
+#include <cstring>
+#include <fstream>
+#include <list>
+
+/*#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <libgnomecanvas/libgnomecanvas.h>
+#include <libglade-2.0/glade/glade.h>
+#include <libxml/tree.h>*/
+
+#include <gdk/gdk.h>
+/*#include <gdkmm-3.0/gdkmm.h> */
+#include <gtk/gtk.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+/*#include <gdk-pixbuf-2.0/gdkmm.h> */
+#include <libgnomecanvas/libgnomecanvas.h>
+#include <glade/glade.h>
+#include <libxml/tree.h>
+
+/*
+#include <gdk.h>
+#include <gtk.h>
+#include <gdk-pixbuf.h>
+#include <libgnomecanvas.h>
+#include <glade/glade.h>
+#include <tree.h>
+*/
+
+//extern "C" { // Incluir ficheros de C
+ #include "reemplazar.h"
+// }
+
+
+//#define filename ""
+
+using namespace std;
+
+
+typedef struct nombre_id {
+ string id;
+ string nombre;
+} nombre_id;
+
+
+typedef struct interfaces {
+ bool laser;
+ bool motor;
+ bool radar;
+ bool encoders;
+ bool lat_lon;
+ bool camara;
+ bool ptencoders;
+} interfaces;
+
+list <nombre_id> ListaNombres;
+
+interfaces interIce;
+
+int def = 0; // contador de estados sin identificar (nombre). //Ya no se usa, se concatena el id del estado 'RSB'
+
+//string varAux, funAux;//**********************Comentado por RSB
+
+ofstream fs;
+
+string directorio, esquema, tiempo_esquema, estado_inicial;
+
+
+
+string int2string(int n){
+ std::stringstream flujo;
+
+ flujo << n;
+
+ return (flujo.str());
+}
+
+string DameNombre(string id){
+
+ list<nombre_id>::iterator pos;
+
+ pos = ListaNombres.begin();
+
+ while ( (pos != ListaNombres.end()) & (pos->id != id) )
+ {
+ pos++;
+ }
+ return pos->nombre;
+}
+
+
+string DameNombrePadre(xmlDocPtr doc,int idPadre,int idSub){
+
+ xmlNodePtr root, nodeS, nodeE, nodeN;
+
+ root = xmlDocGetRootElement (doc);
+
+ nodeS = root->xmlChildrenNode;
+
+ bool encontrado;
+
+ string nombrePadre;
+
+ int idEstado;
+
+
+ encontrado = FALSE;
+
+ while (strcmp((const char*)nodeS->name, "SubAutomata")==0 and encontrado == FALSE) {
+
+ nodeE = nodeS->xmlChildrenNode;
+
+ if (atoi((const char*)xmlNodeGetContent (nodeE)) == idPadre) {
+
+ while (strcmp((const char*)nodeE->name, "Estado")!=0){
+ nodeE = nodeE->next;
+ }
+
+ while (strcmp((const char*)nodeE->name, "Estado")==0 and encontrado == FALSE){
+
+ nodeN = nodeE->xmlChildrenNode;
+
+ while (strcmp((const char*)nodeN->name, "hijo")!=0){
+ nodeN = nodeN->next;
+ }
+
+ if (atoi((const char*)xmlNodeGetContent (nodeN)) == idSub) {
+ nodeN = nodeN->prev;
+
+ nombrePadre = (const char*)xmlNodeGetContent (nodeN);
+
+ if (nombrePadre == ""){
+
+ nodeN = nodeE->xmlChildrenNode;
+
+ idEstado = atoi((const char*)xmlNodeGetContent (nodeN));
+
+ nombrePadre = "default_"+int2string(idEstado);
+
+ }
+
+ encontrado = TRUE;
+ }
+ nodeE = nodeE->next;
+ }
+ }
+ nodeS = nodeS->next;
+ }
+
+ return nombrePadre;
+
+}
+
+void
+variablesH(xmlDocPtr doc){
+
+ xmlNodePtr root;
+ xmlNodePtr node;
+ xmlNodePtr nodeL;
+ char *libreria;
+
+ root = xmlDocGetRootElement (doc);
+
+ node = root->xmlChildrenNode;
+
+ while (strcmp((const char*)node->name, "Librerias")!=0)
+
+ node = node->next;
+
+ nodeL = node->xmlChildrenNode;
+
+ while (nodeL!=NULL) {
+
+ libreria = (char*)xmlNodeGetContent (nodeL);
+
+ if (strcmp((const char*)libreria, "laser")==0){
+
+ fs << "extern float laser[NUM_LASER];" << endl;
+
+ }
+ else if (strcmp((const char*)libreria, "motor")==0){
+
+ fs << "extern float v;" << endl;
+ fs << "extern float w;" << endl;
+
+ }
+ else if (strcmp((const char*)libreria, "radar")==0){
+
+ }
+ else if (strcmp((const char*)libreria, "ptencoders")==0){
+
+ }
+ else if (strcmp((const char*)libreria, "encoders")==0){
+
+ fs << "float robot[5];" << endl;
+
+ }
+ else if (strcmp((const char*)libreria, "lat_lon")==0){
+
+ }
+ else if (strcmp((const char*)libreria, "camara")==0){
+
+ fs << "extern char imagenRGB[SIFNTSC_COLUMNS*SIFNTSC_ROWS*3];" << endl;
+
+ }
+ //}//añadido
+
+ nodeL = nodeL->next;
+ }
+
+ fs << endl;
+}
+
+
+int
+generar_lista_nombres(xmlDocPtr doc, fstream *fs)
+{
+ xmlNodePtr root;
+ xmlNodePtr nodeS;
+ xmlNodePtr nodeE;
+ xmlNodePtr nodeN;
+
+ string id;
+ string nombre;
+
+ int idSub;
+ int idPadre;
+
+ list<nombre_id>::iterator pos;
+
+ root = xmlDocGetRootElement (doc);
+
+ nodeS = root->xmlChildrenNode;
+
+ while (strcmp((const char*)nodeS->name, "SubAutomata")==0) {
+
+ nodeE = nodeS->xmlChildrenNode;
+
+ idSub = atoi((const char*)xmlNodeGetContent (nodeE));
+
+ nodeE = nodeE->next;
+
+ idPadre = atoi((const char*)xmlNodeGetContent (nodeE));
+
+ nodeE = nodeE->next;//nos posicionamos en el primer estado
+
+ if (idPadre == 0) {
+
+ nombre_id t;
+
+ while (strcmp((const char*)nodeE->name, "Estado")==0){
+
+ nodeN = nodeE->xmlChildrenNode;
+
+ id = (const char*)xmlNodeGetContent (nodeN);
+
+ t.id = id;
+
+ while (strcmp((const char *)nodeN->name, (const char *)("nombre")) != 0){
+ nodeN = nodeN->next;
+ }
+
+ nombre = (const char*)xmlNodeGetContent (nodeN);
+
+ if (nombre != "")
+ {
+ t.nombre = nombre;
+ }
+ else{
+ t.nombre = "default_" + id;
+ }
+
+ nodeE = nodeE->next;
+
+ ListaNombres.push_back(t);
+
+ }
+
+ //Componemos el struct de este subAutomata y borramos la lista para componer el siguiente
+ pos = ListaNombres.begin();
+
+ *fs << "typedef enum Estado_Sub_"+int2string(idSub)+" {" << endl;
+ *fs << " "+pos->nombre;
+ pos++;
+
+ while (pos != ListaNombres.end()){
+
+ *fs << "," << endl;
+ *fs << " "+pos->nombre;
+
+ pos++;
+ }
+
+ *fs << endl;
+ *fs << "}Estado_Sub_"+int2string(idSub)+";" << endl;
+ *fs << endl;
+
+ //Antes de borrar la lista componemos un array con los nombres para luego poder mostrarlos en el GUI
+ pos = ListaNombres.begin();
+
+ *fs << "const char *Nombres_Sub_"+int2string(idSub)+"[] = {" << endl;
+ *fs << " \""+pos->nombre+"\"";
+ pos++;
+
+ while (pos != ListaNombres.end()){
+
+ *fs << "," << endl;
+ *fs << " \""+pos->nombre+"\"";
+
+ pos++;
+ }
+
+ *fs << endl;
+ *fs << "};" << endl;
+ *fs << endl;
+
+ //****************************************************************************************************************************
+
+ /*const char *myEnumTypeNames[] =
+ {
+ "enum1",
+ "enum2",
+ "enum3"
+ };*/
+
+ //****************************************************************************************************************************
+
+ ListaNombres.clear();
+
+ }
+ else{//Si no es el nodo padre tenemos que hacer estados "Ghost"
+
+ nombre_id t;
+
+ while (strcmp((const char*)nodeE->name, "Estado")==0){
+
+ nodeN = nodeE->xmlChildrenNode;
+
+ id = (const char*)xmlNodeGetContent (nodeN);
+
+ t.id = id;
+
+ while (strcmp((const char *)nodeN->name, (const char *)("nombre")) != 0){
+ nodeN = nodeN->next;
+ }
+
+ nombre = (const char*)xmlNodeGetContent (nodeN);
+
+ if (nombre != "")
+ {
+ t.nombre = nombre;
+ }
+ else{
+ t.nombre = "default_" + id;
+ }
+
+ nodeE = nodeE->next;
+
+ ListaNombres.push_back(t);
+
+ }
+
+ //Componemos el struct de este subAutomata y borramos la lista para componer el siguiente
+ pos = ListaNombres.begin();
+
+ *fs << "typedef enum Estado_Sub_"+int2string(idSub)+" {" << endl;
+ *fs << " "+pos->nombre+"," << endl;
+ *fs << " "+pos->nombre+"_ghost";
+ pos++;
+
+ while (pos != ListaNombres.end()){
+
+ //Al no ser el subautomata padre hacemos estados ghost
+ *fs << "," << endl;
+ *fs << " "+pos->nombre+"," << endl;
+ *fs << " "+pos->nombre+"_ghost";
+ pos++;
+ }
+
+ *fs << endl;
+ *fs << "}Estado_Sub_"+int2string(idSub)+";" << endl;
+ *fs << endl;
+
+ //Antes de borrar la lista componemos un array con los nombres para luego poder mostrarlos en el GUI
+ pos = ListaNombres.begin();
+
+ *fs << "const char *Nombres_Sub_"+int2string(idSub)+"[] = {" << endl;
+ *fs << " \""+pos->nombre+"\"";
+ pos++;
+
+ while (pos != ListaNombres.end()){
+
+ *fs << "," << endl;
+ *fs << " \""+pos->nombre+"\"";
+
+ pos++;
+ }
+
+ *fs << endl;
+ *fs << "};" << endl;
+ *fs << endl;
+
+ ListaNombres.clear();
+
+ }
+
+ nodeS = nodeS->next;
+
+ }
+ return 0;
+}
+
+
+char InvierteMayusculas(char c)
+{
+ return c^0x20;
+}
+
+string s_toupper(string cadena)
+{
+ unsigned int i;
+
+ for(i = 0; i<cadena.length(); i++)
+ cadena.at(i) = toupper(cadena.at(i)); //<--convierte a minusculas la cadena
+
+ return cadena;
+}
+
+string s_reemplazar(string cadena, string subcadena, string reemplazo)
+{
+
+ int indice;
+
+ for(;;)
+ {
+ indice = posicion((char *)cadena.c_str(), (char *)subcadena.c_str());
+ if(indice==-1)
+ break;
+ else
+ cadena.replace(indice,subcadena.length(),reemplazo);
+ }
+
+ return cadena;
+}
+
+string get_file_name (string file)
+{
+ size_t found;
+
+ found=file.rfind("/");
+
+ return file.substr (++found);
+
+}
+
+
+int cfg (string path, xmlDocPtr doc)
+{
+ fstream fs;
+
+ fs.open(path.c_str(), ofstream::out);
+ if (fs.is_open()){
+ xmlNodePtr root;
+ xmlNodePtr node;
+ xmlNodePtr nodeL;
+ char *libreria;
+
+ root = xmlDocGetRootElement (doc);
+
+ node = root->xmlChildrenNode;
+
+ while (strcmp((const char*)node->name, "Librerias")!=0)
+
+ node = node->next;
+
+ nodeL = node->xmlChildrenNode;
+
+ while (nodeL!=NULL) {
+
+ libreria = (char*)xmlNodeGetContent (nodeL);
+
+ if (strcmp((const char*)libreria, "laser")==0){
+
+ fs << "Introrob.Laser.Proxy=laser1:tcp -h localhost -p 9999" << endl;
+
+ }
+ else if (strcmp((const char*)libreria, "motor")==0){
+
+ fs << "Introrob.Motors.Proxy=motors1:tcp -h localhost -p 9999" << endl;
+
+ }
+ else if (strcmp((const char*)libreria, "radar")==0){
+ fs << "Introrob.Sonars.Proxy=sonar1:tcp -h localhost -p 9999" << endl;
+ }
+ else if (strcmp((const char*)libreria, "ptencoders")==0){
+ fs << "Introrob.PTEncoders1.Proxy=ptencoders1:tcp -h localhost -p 9999" << endl;
+ fs << "Introrob.PTEncoders2.Proxy=ptencoders2:tcp -h localhost -p 9999" << endl;
+ }
+ else if (strcmp((const char*)libreria, "encoders")==0){
+
+ fs << "Introrob.Encoders.Proxy=encoders1:tcp -h localhost -p 9999" << endl;
+
+ }
+ else if (strcmp((const char*)libreria, "lat_lon")==0){
+ fs << "Introrob.PTMotors1.Proxy=ptmotors1:tcp -h localhost -p 9999" << endl;
+ fs << "Introrob.PTMotors2.Proxy=ptmotors2:tcp -h localhost -p 9999" << endl;
+ }
+ else if (strcmp((const char*)libreria, "camara")==0){
+
+ fs << "Introrob.Camera1.Proxy=cameraA:tcp -h localhost -p 9999" << endl;
+ fs << "Introrob.Camera2.Proxy=cameraB:tcp -h localhost -p 9999" << endl;
+
+
+ }
+
+ nodeL = nodeL ->next;
+ }
+
+ fs << endl;
+ fs.close();
+
+ return 0;
+ }else{
+ return 1;
+ }
+
+}
+
+
+int navegaH (string path, xmlDocPtr doc)
+{
+ fstream fs;
+ xmlNodePtr root, nodeS, nodeE;
+ int idSub;
+
+ fs.open(path.c_str(), ofstream::out);
+ if (fs.is_open()){
+
+ fs << "#ifndef MYCOMPONENT_CONTROL_H"<< endl;
+ fs << "#define MYCOMPONENT_CONTROL_H"<< endl;
+ fs << endl;
+ fs << endl;
+ fs << "#include <iostream>" << endl;
+ fs << "#include <Ice/Ice.h>" << endl;
+ fs << "#include <IceUtil/IceUtil.h>" << endl;
+ fs << "#include <jderobot/camera.h>" << endl;
+ fs << "#include <jderobot/motors.h>" << endl;
+ fs << "#include <jderobot/ptmotors.h>" << endl;
+ fs << "#include <jderobot/laser.h>" << endl;
+ fs << "#include <jderobot/encoders.h>" << endl;
+ fs << "#include <jderobot/ptencoders.h>" << endl;
+ fs << "#include <colorspaces/colorspacesmm.h>" << endl;
+ fs << "#include <pthread.h>" << endl;
+ fs << endl;
+ fs << endl;
+ fs << "namespace mycomponent {" << endl;
+ fs << " class Gui;" << endl;
+ fs << " class Control {" << endl;
+ fs << " public:" << endl;
+ fs << endl;
+ fs << " virtual ~Control();" << endl;
+ fs << endl;
+
+ fs << " //FUNCTIONS" << endl;
+ fs << " void handleCameras();" << endl;
+ fs << " void resetControl();" << endl;
+
+ fs << " //HANDLE THREADS" << endl;
+ fs << " pthread_t thr_gui;" << endl;
+
+
+ root = xmlDocGetRootElement (doc);
+
+ nodeS = root->xmlChildrenNode;
+
+ while (strcmp((const char*)nodeS->name, "SubAutomata")==0) {
+
+ nodeE = nodeS->xmlChildrenNode;
+
+ idSub = atoi((const char*)xmlNodeGetContent (nodeE));
+
+ fs << " pthread_t thr_sub_"+int2string(idSub)+";" << endl;
+
+ nodeS = nodeS->next;
+
+ }
+
+ fs << " pthread_mutex_t controlGui;" << endl;
+
+ fs << endl;
+ fs << " // INTERFACES DATA" << endl;
+ fs << " jderobot::EncodersDataPtr ed;" << endl;
+ fs << " jderobot::LaserDataPtr ld;" << endl;
+ fs << " jderobot::ImageDataPtr data1; // Contains the image info" << endl;
+ fs << " jderobot::ImageDataPtr data2; // Contains the image info" << endl;
+ fs << " jderobot::PTEncodersDataPtr pted1;" << endl;
+ fs << " jderobot::PTEncodersDataPtr pted2;" << endl;
+ fs << endl;
+ fs << " // INTERFACES" << endl;
+ fs << " jderobot::MotorsPrx mprx;" << endl;
+ fs << " jderobot::EncodersPrx eprx;" << endl;
+ fs << " jderobot::LaserPrx lprx;" << endl;
+ fs << " jderobot::CameraPrx cprx1;" << endl;
+ fs << " jderobot::CameraPrx cprx2;" << endl;
+ fs << " jderobot::PTMotorsPrx ptmprx1;" << endl;
+ fs << " jderobot::PTEncodersPrx pteprx1;" << endl;
+ fs << " jderobot::PTMotorsPrx ptmprx2;" << endl;
+ fs << " jderobot::PTEncodersPrx pteprx2;" << endl;
+ fs << endl;
+ fs << " colorspaces::Image* image1; // Prepare the image to use with openCV" << endl;
+ fs << " colorspaces::Image* image2;" << endl;
+ fs << endl;
+ fs << " };//class" << endl;
+ fs << " } // namespace" << endl;
+ fs << "#endif /*MYCOMPONENT_Control_H*/" << endl;
+
+ return 0;
+ }else{
+ return 1;
+ }
+
+}
+
+
+int navegaCPP (string path, xmlDocPtr doc)
+{
+ list<nombre_id>::iterator pos;
+ fstream fs;
+ xmlNodePtr root, nodeS, nodeE, nodeN, nodeT;
+ string id, codigo, nombre;using namespace std;
+
+ int idSub;
+ int idPadre;
+ bool escrito_inicial = false;
+
+ int ciclo;
+ string varAux, funAux;
+
+ fs.open(path.c_str(), ofstream::out);
+ if (fs.is_open()){
+
+
+ fs << "#include \"control_class.h\"" <<endl;
+ fs << "#include \"gui.h\"" << endl;
+ fs << endl;
+ fs << endl;
+ fs << "mycomponent::Control *control;" << endl;
+ fs << endl;
+
+ //ITERAR PARA DEFINIR LOS STRUCT DE LOS ESTADOS
+ //...
+ generar_lista_nombres(doc, &fs);
+ fs << endl;
+ //...
+
+ //Variables para los automatas
+ //...
+
+ //fs << " " << funAux << endl;
+ //fs << endl;
+ //fs << endl;
+ //fs << " " << varAux << endl;
+ //fs << endl;
+ //fs << endl;
+ //...
+
+ //DEFINIR ESTADOS INICIALES
+ //...
+ root = xmlDocGetRootElement (doc);
+
+ nodeS = root->xmlChildrenNode;
+
+ while (strcmp((const char*)nodeS->name, "SubAutomata")==0) {
+
+ nodeE = nodeS->xmlChildrenNode;
+
+ idSub = atoi((const char*)xmlNodeGetContent (nodeE));
+
+ nodeE = nodeE->next;
+ idPadre = atoi((const char*)xmlNodeGetContent (nodeE));
+ nodeE = nodeE->next;//nos posicionamos en el primer estado
+
+ escrito_inicial = false;
+
+ while ((strcmp((const char*)nodeE->name, "Estado")==0) and (escrito_inicial == false)){
+ if (strcmp((const char*)xmlGetProp (nodeE, (const xmlChar*)"estado_inicial"), (const char*)"true")==0){
+
+ nombre_id t;
+
+ nodeN = nodeE->xmlChildrenNode;
+
+ id = (const char*)xmlNodeGetContent (nodeN);
+
+ t.id = id;
+
+ while (strcmp((const char *)nodeN->name, (const char *)("nombre")) != 0){
+ nodeN = nodeN->next;
+ }
+
+ nombre = (const char*)xmlNodeGetContent (nodeN);
+
+ if (nombre != "")
+ {
+ t.nombre = nombre;
+ }
+ else{
+ t.nombre = "default_" + id;
+ }
+
+ //Si es un subautómata hijo tiene que empezar en estado "_ghost"
+ if (idPadre == 0) {
+ fs << "Estado_Sub_"+int2string(idSub)+" Sub_"+int2string(idSub)+"="+t.nombre+";" << endl;
+ }else{
+ fs << "Estado_Sub_"+int2string(idSub)+" Sub_"+int2string(idSub)+"="+t.nombre+"_ghost;" << endl;
+ }
+
+ escrito_inicial = true;
+
+ }
+
+ nodeE = nodeE->next;
+ }
+
+ if (escrito_inicial == false){//Si el usuario no definió estado inicial para el nivel ponemos como inicial al primero
+ nodeE = nodeS->xmlChildrenNode;
+ nodeE = nodeE->next;
+ nodeE = nodeE->next;//nos posicionamos en el primer estado
+
+ nombre_id t;
+
+ nodeN = nodeE->xmlChildrenNode;
+
+ id = (const char*)xmlNodeGetContent (nodeN);
+
+ t.id = id;
+
+ while (strcmp((const char *)nodeN->name, (const char *)("nombre")) != 0){
+ nodeN = nodeN->next;
+ }
+
+ nombre = (const char*)xmlNodeGetContent (nodeN);
+
+ if (nombre != "")
+ {
+ t.nombre = nombre;
+ }
+ else{
+ t.nombre = "default_" + id;
+ }
+
+ //Si es un subautómata hijo tiene que empezar en estado "_ghost"
+ if (idPadre == 0) {
+ fs << "Estado_Sub_"+int2string(idSub)+" Sub_"+int2string(idSub)+"="+t.nombre+";" << endl;
+ }else{
+ fs << "Estado_Sub_"+int2string(idSub)+" Sub_"+int2string(idSub)+"="+t.nombre+"_ghost;" << endl;
+ }
+
+ }
+
+ nodeS = nodeS->next;
+
+ }
+
+ fs << endl;
+ fs << endl;
+
+ fs << "namespace mycomponent {" << endl;
+ fs << endl;
+
+ //Comentar handleCameras?? si no selecciona camara fallará-----##############################################################################
+ fs << "void Control::handleCameras(){" << endl;
+ fs << endl;
+ fs << " this->data1 = cprx1->getImageData();" << endl;
+ fs << " colorspaces::Image::FormatPtr fmt1 = colorspaces::Image::Format::searchFormat(this->data1->description->format);" << endl;
+ fs << " if (!fmt1)" << endl;
+ fs << " throw \"Format not supported\";" << endl;
+ fs << endl;
+ fs << " this->image1 = new colorspaces::Image (this->data1->description->width, this->data1->description->height, fmt1, &(this->data1->pixelData[0])); // Prepare the image to use with openCV " << endl;
+ fs << endl;
+ fs << " this->data2 = cprx2->getImageData();" << endl;
+ fs << " colorspaces::Image::FormatPtr fmt2 = colorspaces::Image::Format::searchFormat(this->data2->description->format);" << endl;
+ fs << " if (!fmt2)" << endl;
+ fs << " throw \"Format not supported\";" << endl;
+ fs << endl;
+ fs << " this->image2 = new colorspaces::Image (this->data2->description->width, this->data2->description->height, fmt2, &(this->data2->pixelData[0])); // Prepare the image to use with openCV" << endl;
+ fs << endl;
+ fs << "}" << endl;
+ fs << endl;
+
+ fs << "void Control::resetControl(){" << endl;
+ fs << endl;
+ fs << "this->mprx->setV(0);" << endl;
+ fs << "this->mprx->setW(0);" << endl;
+ fs << "this->mprx->setL(0);" << endl;
+ fs << endl;
+ fs << "}" << endl;
+ fs << endl;
+
+ fs << "Control::~Control() {}" << endl;
+ fs << endl;
+ fs << "}" << endl;
+ fs << endl;
+
+ fs << "void *showGui(void*){" << endl;
+ fs << " mycomponent::Gui *gui;" << endl;
+ fs << " struct timeval a, b; " << endl;
+ fs << " int cycle = 100;" << endl;
+ fs << " long totalb,totala;" << endl;
+ fs << " long diff;" << endl;
+ fs << endl;
+ fs << "using namespace std;" << endl;
+ fs << " string tab=\"\";" << endl;
+ fs << endl;
+
+ fs << " gui = new mycomponent::Gui(control);" << endl;
+ fs << endl;
+
+ fs << " while(true){" << endl;
+ fs << endl;
+ fs << " gettimeofday(&a,NULL);" << endl;
+ fs << " totala=a.tv_sec*1000000+a.tv_usec;" << endl;
+ fs << endl;
+ fs << " system(\"clear\");" << endl;
+ fs << endl;
+//**********************Se genera el gui automatico**********************************************************************************************
+
+ root = xmlDocGetRootElement (doc);
+
+ nodeS = root->xmlChildrenNode;
+
+ while (strcmp((const char*)nodeS->name, "SubAutomata")==0) {
+
+ nodeE = nodeS->xmlChildrenNode;
+ idSub = atoi((const char*)xmlNodeGetContent (nodeE));
+
+ nodeE = nodeE->next;
+ idPadre = atoi((const char*)xmlNodeGetContent (nodeE));
+
+ if (idPadre == 0){
+ fs << " printf(\"%s\\n\", Nombres_Sub_"+int2string(idSub)+"[Sub_"+int2string(idSub)+"]);" << endl;
+ fs << " tab = tab+\" \";" << endl;
+ fs << endl;
+ }else{
+ fs << " if (Sub_"+int2string(idSub)+"%2 == 0){" << endl; //Si no esta en un estado "_ghost"
+ fs << " printf(\"%s%s\\n\", tab.c_str(), Nombres_Sub_"+int2string(idSub)+"[Sub_"+int2string(idSub)+"/2]);" << endl;
+ fs << " tab = tab+\" \";" << endl;
+ fs << " }" << endl;
+ fs << endl;
+ }
+
+ nodeS = nodeS->next;
+ }
+
+ fs << " tab = \"\";" << endl;
+
+ //Controll->update();
+ //fs << " control->handleCameras();" << endl;
+ //fs << " gui->display(*control->image1,*control->image2);" << endl;
+ //fs << endl;
+//**********************FIN Se genera el gui automatico******************************************************************************************
+
+
+ fs << " gettimeofday(&b,NULL);" << endl;
+ fs << " totalb=b.tv_sec*1000000+b.tv_usec;" << endl;
+ //std::cout << "Introrob takes " << (totalb-totala)/1000 << " ms" << std::endl;
+ fs << " diff = (totalb-totala)/1000;" << endl;
+ fs << endl;
+
+ fs << " if(diff < 0 || diff > cycle)" << endl;
+ fs << " diff = cycle;" << endl;
+ fs << " else" << endl;
+ fs << " diff = cycle-diff;" << endl;
+ fs << endl;
+
+ //Sleep Algorithm
+ fs << " usleep(diff*1000);" << endl;
+ fs << " if(diff < 33)" << endl;
+ fs << " usleep(33*1000);" << endl;
+ fs << " }" << endl;
+ fs << "}" << endl;
+ fs << endl;
+ fs << endl;
+ fs << endl;
+
+//---------------ITERAR PARA CREAR EL MOTOR TEMPORAL/CONTROL DE CADA HILO**********************************
+
+ root = xmlDocGetRootElement (doc);
+
+ nodeS = root->xmlChildrenNode;
+
+ while (strcmp((const char*)nodeS->name, "SubAutomata")==0) {
+
+ ListaNombres.clear();
+
+ nodeE = nodeS->xmlChildrenNode;
+
+ idSub = atoi((const char*)xmlNodeGetContent (nodeE));
+
+ nodeE = nodeE->next;
+
+ idPadre = atoi((const char*)xmlNodeGetContent (nodeE));
+
+ nodeE = nodeE->next;//Nos posicionamos en el primer estado
+
+ //Saltamos todos los estados
+ while (strcmp((const char*)nodeE->name, "Estado")==0){
+ nodeE = nodeE->next;
+ }
+
+ nodeE = nodeE->next;//Pasamos los interfaces ICE
+ nodeE = nodeE->next;//Pasamos las variables auxiliares
+ nodeE = nodeE->next;//Nos colocamos en las funciones auxiliares
+
+ funAux = (char*)xmlNodeGetContent (nodeE);
+
+ //Hemos ido hasta las funciones aux porque hay que ponerlas antes del motor del hilo, sino no compilará
+ fs << funAux <<endl;
+
+ //Despues de eso volvemos a la posición adecuada para continuar componiento el motor de cada hilo
+ nodeE = nodeS->xmlChildrenNode;//Saltamos idSub...
+ nodeE = nodeE->next;//... y idPadre
+ nodeE = nodeE->next;//Nos posicionamos en el primer estado y ya podemos continuar
+
+ fs << "void *motor_sub_"+int2string(idSub)+"(void*){" << endl;//Cabecera del motor del subautomata
+ fs << endl;
+
+ nombre_id t;
+
+ while (strcmp((const char*)nodeE->name, "Estado")==0){
+
+ nodeN = nodeE->xmlChildrenNode;
+
+ id = (const char*)xmlNodeGetContent (nodeN);
+
+ t.id = id;
+
+ while (strcmp((const char *)nodeN->name, (const char *)("nombre")) != 0){
+ nodeN = nodeN->next;
+ }
+
+ nombre = (const char*)xmlNodeGetContent (nodeN);
+
+ if (nombre != "")
+ {
+ t.nombre = nombre;
+ }
+ else{
+ t.nombre = "default_" + id;
+ }
+
+ nodeE = nodeE->next;
+
+ ListaNombres.push_back(t);
+
+ }
+
+ //Salimos posicionados en el tiempo de iteración
+
+ ciclo = atoi((const char*)xmlNodeGetContent (nodeE)); //Ciclo de iteracion del subautomata
+
+ nodeE = nodeE->next;//Pasamos los interfaces ICE
+ nodeE = nodeE->next;//Nos colocamos en las variables auxiliares
+
+ varAux = (char*)xmlNodeGetContent (nodeE);
+
+ nodeE = nodeE->next;//Nos colocamos en las funciones auxiliares
+
+ //funAux = (char*)xmlNodeGetContent (nodeE);
+
+ fs << " struct timeval a, b;" << endl;
+ fs << " int cycle="+int2string(ciclo)+";" << endl;
+ fs << " long totalb,totala;" << endl;
+ fs << " long diff;" << endl;
+ fs << " time_t t_ini;"<< endl;
+ fs << " time_t t_fin;"<< endl;
+ fs << " double secs;" << endl;
+ fs << " bool t_activated;" << endl;
+ fs << endl;
+ fs << " " << varAux << endl;
+ fs << endl;
+ fs << endl;
+ fs << " while(true){" << endl;
+ fs << " gettimeofday(&a,NULL);" << endl;
+ fs << " totala=a.tv_sec*1000000+a.tv_usec;" << endl;
+ fs << endl;
+
+
+ if (idPadre != 0) { //Si es el subautomata raiz
+
+ fs << " if (Sub_"+int2string(idPadre)+"=="+DameNombrePadre(doc,idPadre,idSub)+"){" << endl;
+ fs << " if(";
+
+ pos = ListaNombres.begin();
+
+ fs << "Sub_"+int2string(idSub)+"=="+pos->nombre+"_ghost";
+
+ pos++;
+
+ while (pos != ListaNombres.end()) {
+
+ fs << " || Sub_"+int2string(idSub)+"=="+pos->nombre+"_ghost";
+ pos++;
+
+ }
+
+ fs << "){" << endl;
+ fs << " Sub_"+int2string(idSub)+"= (Estado_Sub_"+int2string(idSub)+")(Sub_"+int2string(idSub)+"-1);" << endl;
+ fs << " }" << endl;
+
+ }
+
+
+ fs << " //Switch de evaluación de transiciones" << endl;
+ fs << " switch (Sub_"+int2string(idSub)+"){" << endl;
+
+ pos = ListaNombres.begin();
+
+ nodeE = nodeS->xmlChildrenNode;//Volvemos a recorrer el subautomata
+ nodeE = nodeE->next;
+ nodeE = nodeE->next;//Nos posicionamos en el primer estado
+
+ while (pos != ListaNombres.end()){
+ fs << " case "+pos->nombre+":" << endl;
+ fs << " {" << endl;
+
+ nodeN = nodeE->xmlChildrenNode;
+
+ while (strcmp((const char *)nodeN->name, (const char *)("transiciones")) != 0){
+ nodeN = nodeN->next;
+ }//Nos colocamos en las transiciones del estado
+
+ nodeT = nodeN->xmlChildrenNode;
+
+ if (nodeT!=NULL){
+
+ while (nodeT!=NULL){
+ id = (const char*)xmlNodeGetContent (nodeT->xmlChildrenNode->next->next);
+ if (nodeT->xmlChildrenNode->next->next->next != NULL){
+ if(strcmp((const char*)nodeT->xmlChildrenNode->next->next->next->name,"codigo") == 0)
+ {
+ codigo = (const char*)xmlNodeGetContent (nodeT->xmlChildrenNode->next->next->next);
+ fs << " if (" << codigo << "){" << endl;
+ // fs << " this->ventana->change_nodo_color (Estado_Actual, 3);" << endl;
+ // fs << " Estado_Anterior = Estado_Actual;" << endl;
+ fs << " Sub_"+int2string(idSub)+"="<< DameNombre(id) << ";" << endl;
+ fs << " }" << endl;
+ }else if (strcmp((const char*)nodeT->xmlChildrenNode->next->next->next->name,"tiempo") == 0){
+ int tiempoTrans = atoi((const char*)xmlNodeGetContent (nodeT->xmlChildrenNode->next->next->next));
+
+ fs << " if (!t_activated){" << endl;
+ fs << " t_ini = time(NULL);" << endl;
+
+ fs << " t_activated = true;" << endl;
+ fs << " }else{" << endl;
+ fs << " t_fin = time(NULL);" << endl;
+ fs << " secs = difftime(t_fin, t_ini);" << endl;
+ fs << " if (secs > (double) "<< ((double)tiempoTrans/1000) <<"){" << endl;
+ // fs << " this->ventana->change_nodo_color (Estado_Actual, 3);" << endl;
+ // fs << " Estado_Anterior = Estado_Actual;" << endl;
+ fs << " Sub_"+int2string(idSub)+"="<< DameNombre(id) << ";" << endl;
+ fs << " t_activated = false;" << endl;
+
+ fs << " }" << endl;
+ fs << " }" << endl;
+
+ }
+ }
+ nodeT = nodeT->next;
+ }//fin while de transiciones
+
+ }
+
+ fs << " break;" << endl;
+ fs << " }" << endl;
+
+ pos++;
+ nodeE = nodeE->next;
+
+ }//fin while listaNombres para switch de evaluacion de transiciones
+
+ fs << " }" << endl; //Para cerrar el switch
+
+
+ //Volvemos al principio del subautomata para hacer el switch de actuacion
+ pos = ListaNombres.begin();
+
+ nodeE = nodeS->xmlChildrenNode;//Volvemos a recorrer el subautomata
+ nodeE = nodeE->next;
+ nodeE = nodeE->next;//Nos posicionamos en el primer estado
+
+ fs << " //Switch de actuacion" << endl;
+ fs << " switch (Sub_"+int2string(idSub)+"){" << endl;
+
+ while (pos != ListaNombres.end()){
+
+ fs << " case "+pos->nombre+":" << endl;
+ fs << " {" << endl;
+
+ nodeN = nodeE->xmlChildrenNode;
+
+ while (strcmp((const char *)nodeN->name, (const char *)("codigo")) != 0){
+ nodeN = nodeN->next;
+ }//Nos colocamos en el codigo del estado
+
+ codigo = (const char*)xmlNodeGetContent (nodeN);
+
+ fs << " " << codigo << endl;
+
+ fs << " break;" << endl;
+ fs << " }" << endl;
+
+ pos++;
+ nodeE = nodeE->next;
+
+ }//fin while listaNombres para el switch de actuacion
+
+ fs << " }" << endl; //Para cerrar el switch
+
+
+ if (idPadre != 0) {
+
+ fs << "}else{" << endl;
+ fs << " if(";
+
+ pos = ListaNombres.begin();
+
+ fs << "Sub_"+int2string(idSub)+"=="+pos->nombre;
+
+ pos++;
+
+ while (pos != ListaNombres.end()) {
+
+ fs << " || Sub_"+int2string(idSub)+"=="+pos->nombre;
+ pos++;
+
+ }
+
+ fs << "){" << endl;
+ fs << " Sub_"+int2string(idSub)+"= (Estado_Sub_"+int2string(idSub)+")(Sub_"+int2string(idSub)+"+1);" << endl;
+ fs << " }" << endl;
+ fs << " }" << endl;
+
+ }
+
+ fs << endl;
+ fs << endl;
+ fs << "//Motor temporal del subautomata" << endl;
+ fs << endl;
+
+ fs << " gettimeofday(&b,NULL);" << endl;
+ fs << " totalb=b.tv_sec*1000000+b.tv_usec;" << endl;
+ fs << " diff = (totalb-totala)/1000;" << endl;
+ fs << " if(diff < 0 || diff > cycle)" << endl;
+ fs << " diff = cycle;" << endl;
+ fs << " else" << endl;
+ fs << " diff = cycle-diff;" << endl;
+ fs << endl;
+ fs << " //Sleep Algorithm" << endl;
+ fs << " usleep(diff*1000);" << endl;
+ fs << " if(diff < 33)" << endl;
+ fs << " usleep(33*1000);" << endl;
+ fs << " }" << endl;
+ fs << "}" << endl;
+ fs << endl;
+ fs << endl;
+
+ nodeS = nodeS->next;
+
+ }//fin while subautomata
+
+
+//---------------FIN DE ITERAR PARA CREAR EL MOTOR TEMPORAL/CONTROL DE CADA HILO***************************
+
+ fs << "int main(int argc, char** argv){" << endl;
+ fs << endl;
+
+ fs << endl;
+
+ fs << " int status;" << endl;
+ fs << " Ice::CommunicatorPtr ic;" << endl;
+ fs << " struct timeval a, b;" << endl;
+ fs << " int cycle = 300;" << endl;
+ fs << " long totalb,totala;" << endl;
+ fs << " long diff;" << endl;
+ fs << " bool guiActivated=0;" << endl;
+ fs << " bool controlActivated=0;" << endl;
+ fs << endl;
+
+
+ //th_data data_1;
+ //th_data data_2;
+ //th_data data_3;
+
+ fs << " control = new mycomponent::Control();" << endl;
+ fs << endl;
+ fs << " pthread_mutex_init(&control->controlGui, NULL);" << endl;
+
+ fs << " controlActivated=1;" << endl;
+ fs << " guiActivated=1;" << endl;
+
+ //if(guiActivated){
+ fs << " pthread_create(&control->thr_gui, NULL, &showGui, NULL);" << endl;//OBJETIVo2
+ //}
+
+ fs << " try{" << endl;
+ fs << endl;
+
+ fs << " ic = Ice::initialize(argc,argv);" << endl;
+ fs << " //-----------------ICE----------------//" << endl;
+
+//--------Se cargan los interfaces que usen todos los subautomatas en conjunto********
+
+
+ interIce.laser = false;
+ interIce.motor = false;
+ interIce.radar = false;
+ interIce.encoders = false;
+ interIce.lat_lon = false;
+ interIce.camara = false;
+ interIce.ptencoders = false;
+
+ root = xmlDocGetRootElement (doc);
+
+ nodeS = root->xmlChildrenNode;
+
+ while (strcmp((const char*)nodeS->name, "SubAutomata")==0) {
+
+ nodeE = nodeS->xmlChildrenNode;
+
+ while (strcmp((const char*)nodeE->name, "Librerias")!=0) {
+ nodeE = nodeE->next;
+ }
+
+ nodeT = nodeE->xmlChildrenNode;
+
+ string interface;
+ while (nodeT != NULL){
+ interface = (const char*)xmlNodeGetContent (nodeT);
+ if (interface == "laser")
+ interIce.laser = true;
+ if (interface == "motor")
+ interIce.motor = true;
+ if (interface == "radar")
+ interIce.radar = true;
+ if (interface == "encoders")
+ interIce.encoders = true;
+ if (interface == "lat_lon")
+ interIce.lat_lon = true;
+ if (interface == "camara")
+ interIce.camara = true;
+ if (interface == "ptencoders")
+ interIce.ptencoders = true;
+
+ nodeT = nodeT->next;
+ }
+
+ nodeS = nodeS->next;
+
+ }
+
+ //Añadimos los interfaces que hemos detectado como necesarios
+ if (interIce.laser == true){
+ fs << " // Contact to LASER interface" << endl;
+ fs << " Ice::ObjectPrx baseLaser = ic->propertyToProxy(\"Mycomponent.Laser.Proxy\");" << endl;
+ fs << " if (0==baseLaser)" << endl;
+ fs << " throw \"Could not create proxy with laser\";" << endl;
+ fs << endl;
+ fs << " // Cast to laser" << endl;
+ fs << " control->lprx = jderobot::LaserPrx::checkedCast(baseLaser);" << endl;
+ fs << " if (0== control->lprx)" << endl;
+ fs << " throw \"Invalid proxy Mycomponent.Laser.Proxy\";" << endl;
+ fs << endl;
+ }
+
+ if (interIce.motor == true){
+ fs << " // Contact to MOTORS interface" << endl;
+ fs << " Ice::ObjectPrx baseMotors = ic->propertyToProxy(\"Mycomponent.Motors.Proxy\");" << endl;
+ fs << " if (0==baseMotors)" << endl;
+ fs << " throw \"Could not create proxy with motors\";" << endl;
+ fs << endl;
+ fs << " // Cast to motors" << endl;
+ fs << " control->mprx = jderobot::MotorsPrx::checkedCast(baseMotors);" << endl;
+ fs << " if (0== control->mprx)" << endl;
+ fs << " throw \"Invalid proxy Mycomponent.Motors.Proxy\";" << endl;
+ fs << endl;
+ }
+
+ //if (interIce.radar == true){
+ //}
+
+ if (interIce.encoders == true){
+ fs << " // Contact to ENCODERS interface" << endl;
+ fs << " Ice::ObjectPrx baseEncoders = ic->propertyToProxy(\"Mycomponent.Encoders.Proxy\");" << endl;
+ fs << " if (0==baseEncoders)" << endl;
+ fs << " throw \"Could not create proxy with encoders\";" << endl;
+ fs << endl;
+ fs << " // Cast to encoders" << endl;
+ fs << " control->eprx = jderobot::EncodersPrx::checkedCast(baseEncoders);" << endl;
+ fs << " if (0== control->eprx)" << endl;
+ fs << " throw \"Invalid proxy Mycomponent.Encoders.Proxy\";" << endl;
+ fs << endl;
+ }
+
+ if (interIce.lat_lon == true){
+ fs << " // Contact to PTMOTORS interface" << endl;
+ fs << " Ice::ObjectPrx ptmotors1 = ic->propertyToProxy(\"Mycomponent.PTMotors1.Proxy\");" << endl;
+ fs << " if (0==ptmotors1)" << endl;
+ fs << " throw \"Could not create proxy with motors\";" << endl;
+ fs << endl;
+ fs << " // Cast to ptmotors" << endl;
+ fs << " control->ptmprx1 = jderobot::PTMotorsPrx::checkedCast(ptmotors1);" << endl;
+ fs << " if (0== control->ptmprx1)" << endl;
+ fs << " throw \"Invalid proxy Mycomponent.PTMotors1.Proxy\";" << endl;
+ fs << endl;
+ fs << " // Contact to PTMOTORS interface" << endl;
+ fs << " Ice::ObjectPrx ptmotors2 = ic->propertyToProxy(\"Mycomponent.PTMotors2.Proxy\");" << endl;
+ fs << " if (0==ptmotors2)" << endl;
+ fs << " throw \"Could not create proxy with motors\";" << endl;
+ fs << " // Cast to ptmotors" << endl;
+ fs << endl;
+ fs << " control->ptmprx2 = jderobot::PTMotorsPrx::checkedCast(ptmotors2);" << endl;
+ fs << " if (0== control->ptmprx2)" << endl;
+ fs << " throw \"Invalid proxy Mycomponent.PTMotors2.Proxy\";" << endl;
+ fs << endl;
+ }
+
+ if (interIce.camara == true){
+ fs << " // Get driver camera" << endl;
+ fs << " Ice::ObjectPrx camara1 = ic->propertyToProxy(\"Mycomponent.Camera1.Proxy\");" << endl;
+ fs << " if (0==camara1)" << endl;
+ fs << " throw \"Could not create proxy to camera1 server\";" << endl;
+ fs << endl;
+ fs << " // cast to CameraPrx" << endl;
+ fs << " control->cprx1 = jderobot::CameraPrx::checkedCast(camara1);" << endl;
+ fs << " if (0== control->cprx1)" << endl;
+ fs << " throw \"Invalid proxy\";" << endl;
+ fs << endl;
+ fs << " // Get driver camera" << endl;
+ fs << " Ice::ObjectPrx camara2 = ic->propertyToProxy(\"Mycomponent.Camera2.Proxy\");" << endl;
+ fs << " if (0==camara2)" << endl;
+ fs << " throw \"Could not create proxy to camera2 server\";" << endl;
+ fs << endl;
+ fs << " // cast to CameraPrx" << endl;
+ fs << " control->cprx2 = jderobot::CameraPrx::checkedCast(camara2);" << endl;
+ fs << " if (0== control->cprx2)" << endl;
+ fs << " throw \"Invalid proxy\";" << endl;
+ fs << endl;
+ }
+
+ if (interIce.ptencoders == true){
+ fs << " // Contact to PTENCODERS interface" << endl;
+ fs << " Ice::ObjectPrx ptencoders1 = ic->propertyToProxy(\"Mycomponent.PTEncoders1.Proxy\");" << endl;
+ fs << " if (0==ptencoders1)" << endl;
+ fs << " throw \"Could not create proxy with encoders\";" << endl;
+ fs << endl;
+ fs << " // Cast to encoders" << endl;
+ fs << " control->pteprx1 = jderobot::PTEncodersPrx::checkedCast(ptencoders1);" << endl;
+ fs << " if (0== control->pteprx1)" << endl;
+ fs << " throw \"Invalid proxy Mycomponent.PTEncoders1.Proxy\";" << endl;
+ fs << endl;
+ fs << " // Contact to PTENCODERS interface" << endl;
+ fs << " Ice::ObjectPrx ptencoders2 = ic->propertyToProxy(\"Mycomponent.PTEncoders2.Proxy\");" << endl;
+ fs << " if (0==ptencoders2)" << endl;
+ fs << " throw \"Could not create proxy with encoders\";" << endl;
+ fs << endl;
+ fs << " // Cast to encoders" << endl;
+ fs << " control->pteprx2 = jderobot::PTEncodersPrx::checkedCast(ptencoders2);" << endl;
+ fs << " if (0== control->pteprx2)" << endl;
+ fs << " throw \"Invalid proxy Mycomponent.PTEncoders2.Proxy\";" << endl;
+ fs << endl;
+ }
+
+
+//------------------------------fin carga interfaces ICE *****************************
+
+
+ fs << " //-----------------ICE----------------//" << endl;
+ fs << "//****************************** Processing the Control ******************************///" << endl;
+ fs << " //---------------- ITERATIONS CONTROL -----------//" << endl;
+ fs << endl;
+ fs << endl;
+ fs << "//Inicializacion de datos para los distintos hilos de control y creacion de hilos" << endl;
+
+
+ root = xmlDocGetRootElement (doc);
+
+ nodeS = root->xmlChildrenNode;
+
+ while (strcmp((const char*)nodeS->name, "SubAutomata")==0) {
+
+ nodeE = nodeS->xmlChildrenNode;
+
+ idSub = atoi((const char*)xmlNodeGetContent (nodeE));
+
+ fs << " pthread_create(&control->thr_sub_"+int2string(idSub)+",NULL, &motor_sub_"+int2string(idSub)+", NULL);" << endl;
+
+ nodeS = nodeS->next;
+
+ }
+
+ fs << endl;
+ fs << endl;
+ fs << " pthread_join(control->thr_gui, NULL);" << endl;
+ fs << endl;
+
+ root = xmlDocGetRootElement (doc);
+
+ nodeS = root->xmlChildrenNode;
+
+ while (strcmp((const char*)nodeS->name, "SubAutomata")==0) {
+
+ nodeE = nodeS->xmlChildrenNode;
+
+ idSub = atoi((const char*)xmlNodeGetContent (nodeE));
+
+ fs << " pthread_join(control->thr_sub_"+int2string(idSub)+",NULL);" << endl;
+
+ nodeS = nodeS->next;
+
+ }
+
+ fs << endl;
+ fs << endl;
+ fs << " }//del try" << endl;
+ fs << " catch (const Ice::Exception& ex) {" << endl;
+ fs << " std::cerr << ex << std::endl;" << endl;
+ fs << " status = 1;" << endl;
+ fs << " }" << endl;
+ fs << " catch (const char* msg) {" << endl;
+ fs << " std::cerr << msg << std::endl;" << endl;
+ fs << " status = 1;" << endl;
+ fs << " }" << endl;
+ fs << endl;
+ fs << "if (ic)" << endl;
+ fs << " ic->destroy();" << endl;
+ fs << endl;
+ fs << "return 0;" << endl;
+ fs << endl;
+ fs << "}" << endl;
+ fs << endl;
+
+
+ fs.close();
+
+ return 0;
+ }else{
+ return 1;
+ }
+
+}
+
+int configuracionICE (string path)
+{
+ fstream fs;
+
+ fs.open(path.c_str(), ofstream::out);
+ if (fs.is_open()){
+
+ if (interIce.motor == true){
+ fs << "Mycomponent.Motors.Proxy=motors1:tcp -h localhost -p 9999" << endl;
+ }
+
+ if (interIce.camara == true){
+ fs << "Mycomponent.Camera1.Proxy=cameraA:tcp -h localhost -p 9999" << endl;
+ fs << "Mycomponent.Camera2.Proxy=cameraB:tcp -h localhost -p 9999" << endl;
+ }
+
+ //if (interIce.radar == true){
+ //}
+
+ if (interIce.encoders == true){
+ fs << "Mycomponent.Encoders.Proxy=encoders1:tcp -h localhost -p 9999" << endl;
+ }
+
+ if (interIce.lat_lon == true){
+ fs << "Mycomponent.PTMotors1.Proxy=ptmotors1:tcp -h localhost -p 9999" << endl;
+ fs << "Mycomponent.PTMotors2.Proxy=ptmotors2:tcp -h localhost -p 9999" << endl;
+ }
+
+ if (interIce.laser == true){
+ fs << "Mycomponent.Laser.Proxy=laser1:tcp -h localhost -p 9999" << endl;
+ }
+
+ if (interIce.ptencoders == true){
+ fs << "Mycomponent.PTEncoders1.Proxy=ptencoders1:tcp -h localhost -p 9999" << endl;
+ fs << "Mycomponent.PTEncoders2.Proxy=ptencoders2:tcp -h localhost -p 9999" << endl;
+ }
+
+ fs.close();
+
+ return 0;
+ }else{
+ return 1;
+ }
+}
+
+
+int main( int argc, char *argv[])
+{
+ xmlDocPtr doc;
+// xmlNodePtr root;
+// xmlNodePtr node;
+// xmlNodePtr nodeE;
+// xmlNodePtr nodeT, nodeTT;
+
+ string rutaAcopiar="";
+
+
+
+
+ string path;
+
+ char *filename = argv[1];
+
+ //strcpy(filename, "EstoEsUnaPrueba3.xml");
+
+ printf("ARG: %s %s\n", argv[0], argv[1]);
+
+ doc = xmlParseFile (argv[1]);
+
+
+
+ /* Nombre y Directorio Esquema */
+
+
+ printf("Fichero abierto: %s\n",filename);
+
+
+ string fich = filename;
+ int i;
+ size_t pos;
+ for (i=0; i < (int)fich.length(); i++)
+ {
+ if (fich.at(i) == '/')
+ pos = i;
+ }
+ string fichero = fich.substr (++pos); // Nombre del fichero (ejemplo.xml)
+
+ directorio = fich.substr (0,pos); // Directorio del fichero (/home/usuario/.../)
+
+ printf("Directorio: %s\n",directorio.c_str());
+
+ for (i=0; i < (int)fichero.length(); i++)
+ {
+ if (fichero.at(i) == '.')
+ pos = i;
+ }
+
+ esquema = fichero.substr (0,pos); // Nombre del fichero sin extension
+ printf("Esquema: %s\n",esquema.c_str());
+
+ if (!doc) {
+ printf("Error al cargar documento XML\n");
+ }
+ else{
+ printf("Antes de importar codigo\n");
+ //importarCodigoAux(doc);
+ printf("Despues de importar codigo\n");
+ path = directorio+ "src";
+
+ mkdir(path.c_str(), 0777);
+ printf("Creado path\n");
+ //char* aCopiar = "";
+ //strcpy (aCopiar,"cp -R ./datos_esquemas/my_component/* ");
+ //strcat (aCopiar,path.c_str());
+ //printf ("Orden cp: %s",aCopiar);
+
+ rutaAcopiar = "cp -R ./datos_esquemas/my_component/* "+directorio+"src";
+
+ system(rutaAcopiar.c_str());
+
+ //copiar_ficheros ("./datos_esquemas/my_component/", directorio+"src/");//-------------------------------------cambiada ubicacion
+
+ path = directorio+ "src/control_class.h"; //----------------------------------------------------------------cambiado el nombre del .h
+ navegaH (path, doc);
+
+ path = directorio+ "/src/control_class.cpp";//----------------------------------------------------------cambiado nombre del .cpp
+ navegaCPP (path, doc);
+
+ path = directorio+ "/src/mycomponent.cfg";
+ configuracionICE (path);
+
+ printf("Ficheros Generados \n");
+
+ }
+
+ return 0;
+}
Added: trunk/src/components/visualHFSM-3.1/int2string.cpp
===================================================================
--- trunk/src/components/visualHFSM-3.1/int2string.cpp (rev 0)
+++ trunk/src/components/visualHFSM-3.1/int2string.cpp 2013-03-10 13:05:56 UTC (rev 882)
@@ -0,0 +1,9 @@
+#include "int2string.h"
+
+string int2string(int n){
+ std:: stringstream flujo;
+
+ flujo << n;
+
+ return (flujo.str());
+}
Property changes on: trunk/src/components/visualHFSM-3.1/int2string.cpp
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/src/components/visualHFSM-3.1/int2string.h
===================================================================
--- trunk/src/components/visualHFSM-3.1/int2string.h (rev 0)
+++ trunk/src/components/visualHFSM-3.1/int2string.h 2013-03-10 13:05:56 UTC (rev 882)
@@ -0,0 +1,8 @@
+#ifndef IN2STRING_H
+#define IN2STRING_H
+
+#include <sstream>
+using namespace std;
+string int2string(int n);
+
+#endif
Property changes on: trunk/src/components/visualHFSM-3.1/int2string.h
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/src/components/visualHFSM-3.1/interfaz.cpp
===================================================================
--- trunk/src/components/visualHFSM-3.1/interfaz.cpp (rev 0)
+++ trunk/src/components/visualHFSM-3.1/interfaz.cpp 2013-03-10 13:05:56 UTC (rev 882)
@@ -0,0 +1,3953 @@
+#include "interfaz.h"
+
+//#include <gtkmm.h>
+//#include <gtkmm/main.h>
+
+#define FICH_GLADE "insercion.glade"
+
+GladeXML *prog = NULL;
+
+
+
+#define CANVAS_SIZE 1500
+
+using namespace std;
+
+//------------AÑADIDO ESTRUCTURA SUBAUTOMATA
+
+
+
+tSubAut reg_sub;
+list <tSubAut> ListaSubAutomatas;
+int idSubGlobal = 1; //Id máximo de subautomata en el esquema abierto, se usa para ir asignando id's correlativos en la creacion de nuevos niveles
+
+int subautomata_mostrado = 1; //Id del subautomata que se esta mostrando en el canvas
+
+GtkWidget* menu_estado;
+GtkWidget* menu_transicion;
+GtkWidget* menu_pegar;
+
+GtkWidget* nombrar_estado;
+GtkWidget* editar_estado;
+GtkWidget* marcar_inicial_estado;
+GtkWidget* copiar_estado;
+GtkWidget* eliminar_estado;
+GtkWidget* nombrar_transicion;
+GtkWidget* editar_transicion;
+GtkWidget* eliminar_transicion;
+GtkWidget* pegar_estado;
+
+GnomeCanvasItem *item_menu_estado;
+GnomeCanvasItem *item_group_menu_estado;
+GnomeCanvasItem *item_menu_transicion;
+GnomeCanvasItem *item_menu_pegar;
+
+GtkWidget *tree_view;
+
+enum
+{
+ COLUMN = 0,
+ NUM_COLS
+} ;
+
+GtkTreePath * arbolPath;
+
+bool estado_clipboard = FALSE;
+string estado_clipboard_codigo;
+int estado_clipboard_idHijo;
+
+bool estado_nombrado = FALSE;
+
+//------------FIN AÑADIDO ESTRUCTURA SUBAUTOMATA
+
+
+typedef struct reg {
+ GnomeCanvasGroup *root;
+ char *figura;
+} reg;
+
+typedef struct aux {
+
+ GnomeCanvasItem * origen;
+ GnomeCanvasItem * destino;
+ string codigo;
+ int tiempo;
+} aux;
+
+
+typedef enum TYPE_WIDGET {
+ TEXT_VIEW,
+ ENTRY,
+ SOURCE_VIEW
+}Estado;
+
+const string ayuda[5] = {"Para mover un estado (item), seleccionar el boton mover,\ny posteriormente arrastrar el estado. Para copiar, pulse el boton copiar y selecciona un estado.\nSe copiara automaticamenteen una posicion cercana al estado pulasado.\nPara eliminar un estado, seleccionar el boton y posteriormente pulsar con el boton izquierdo sobre el item.","Boton Estado: pinta un estado en el canvas. Selecionar y pinchar en el lugar donde se quiera posicionar\nBoton Transicion: pinta una transicion entre dos estados. Selecionar boton y selecionar los estados que conecta.","Guarda/Carga el automata en/desde un fichero xml.\nEstado inicial: marca que estado es el inicial.","Estado inicial: marca que estado es el inicial.\nNombrar: nombra el estado.\nEditar: inserta codigo en el estado/transicion.", "Generar C: genera fichero .c\nCompilar: genera ejecutable"};
+
+string codigo = "";
+
+string variables = "";
+string funciones = "";
+
+int tiempo = -1;
+
+int id = 0;
+
+list <tNodo> ListaElementos;
+
+list <tTransicion> ListaTransiciones;
+
+list <transicion_aux> ListaTransicionesTemporales; // Lista de transiciones temporales. Usadas para pintar las transiciones despues de cargar un fichero.
+
+list <GtkWidget *> ListaBotones;
+
+//string fichero = "";
+
+string directorio = ""; // directorio donde se guarda el esquema
+
+string nombreEsquema = ""; //nombre del esquema guardado
+
+int tiempoIteracion = 100;
+
+importar imp;
+
+//tNodo *TListaFiguras;
+
+tNodo registro;
+
+static GtkWidget *window; //ventana principal
+
+GtkWidget *canvas; // canvas principal
+
+GnomeCanvasGroup *root;
+
+GnomeCanvasGroup* new_group;
+
+//Movemos estos dos botones aqui para poder acceder a su estado desde todo el programa
+GtkWidget *botonLinea;
+GtkWidget *botonEstado;
+
+string botonPulsado = "Nada"; //Boton pulsado. Para diferenciar operaciones.
+
+GnomeCanvasPoints* points; /* 2 puntos */
+
+GnomeCanvasPoints* points2; /* 2 puntos */
+
+GnomeCanvasItem *item_guardado; // item guardado para operaciones
+
+GnomeCanvasItem *item_transicion_saved; // item guardado para operaciones
+
+int origenX, origenY; // Puntos (x,y) del canvas
+
+int pinta_linea;
+
+int color; // Guarda Color de la figura editada
+
+const char * compile_file;
+
+char* probar;
+
+double zoom = 1.0;
+
+extern int cont_transiciones;
+
+
+/* Prototipo de la funciónes que capturan las señales de los item */
+gint
+item_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data);
+
+
+void
+cuadro_informacion (char *szMessage)
+{
+ GtkWidget *label;
+ GtkWidget *dialog;
+
+ dialog = gtk_dialog_new_with_buttons ("Information",
+ GTK_WINDOW (window),
+ GTK_DIALOG_MODAL,
+ GTK_STOCK_OK,
+ GTK_RESPONSE_ACCEPT,
+ NULL);
+ gtk_window_set_title (GTK_WINDOW (dialog),"Information");
+ gtk_container_border_width(GTK_CONTAINER (dialog),5);
+
+ //Creamos el mensaje
+ label = gtk_label_new(szMessage);
+ gtk_misc_set_padding(GTK_MISC(label), 10, 10);
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)-> vbox), label, TRUE, TRUE, 0);
+ gtk_widget_show (label);
+
+ if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
+ gtk_widget_destroy (dialog);
+}
+
+
+
+void
+compilar (GtkWindow *window, gpointer data){
+
+ pid_t pid;
+
+ if (nombreEsquema ==""){
+
+ cuadro_informacion ((char*)"You must generate the code before you could compile it.");
+
+ }else {
+ if ((pid = fork()) == -1) {
+ printf("Error al crear proceso hijo\n");
+ exit(1);
+ }
+ else {
+ if (pid == 0){
+ printf("Compiling..\n");
+ execl("/usr/bin/cmake", "cmake", (const char*)strcat ((char*)directorio.c_str(), "src/build"));
+ execl("/usr/bin/make", "make", (const char*)strcat ((char*)directorio.c_str(), "src/build"));
+// execl("/usr/bin/make", "make", "-C", (const char*)strcat ((char*)directorio.c_str(), "src/"), "-f", "Makefile-mycomponent", NULL);
+ }
+ }
+ }
+}
+
+void
+generar_c (GtkWindow *windows, gpointer data){
+
+ pid_t pid;
+
+ const char *filename = "";
+
+
+ if (nombreEsquema ==""){
+
+ cuadro_informacion ((char*)"You must save the project before you could generate the code.");
+
+ }
+
+ else {
+ filename = (directorio + nombreEsquema + ".c").c_str();
+
+
+ if ((pid = fork()) == -1) {
+ printf("Error al crear proceso hijo\n");
+ exit(1);
+ }
+
+ if (pid == 0){
+ printf("Generando Codigo.. %s\n", filename);
+ execl("./generate", "generate",(directorio + nombreEsquema + ".xml").c_str(), (directorio + nombreEsquema + ".c").c_str(), NULL);
+
+ }
+
+ }
+}
+
+void
+marcar_estado_inicial (GnomeCanvasItem *item)
+{
+ list<tNodo>::iterator pos;
+ GnomeCanvasItem *estado_inicial;
+ tNodo n;
+
+ pos = ListaElementos.begin();
+
+ if (pos->estado_inicial != NULL){
+ gtk_object_destroy(GTK_OBJECT(pos->estado_inicial));
+ pos->estado_inicial = NULL;
+ }
+
+ while (pos->item != item){
+ pos++;
+ }
+
+
+ estado_inicial = pinta_estado_inicial (GNOME_CANVAS_GROUP(item->parent), item);
+ pos->estado_inicial=estado_inicial;
+
+ n = *pos;
+
+ ListaElementos.erase(pos);
+ ListaElementos.push_front (n);
+}
+
+void cargar_transiciones ()
+{
+ GList * list_items;
+ GnomeCanvasGroup *group, *group_parent ;
+ GnomeCanvasItem *box, *item_nombre;
+ double x1, x2, y1, y2;
+ list<transicion_aux>::iterator pos;
+ list<tTransicion>::iterator pos2;
+ list<tNodo>::iterator posNodos;
+
+ pos = ListaTransicionesTemporales.begin();
+
+
+ while (pos != ListaTransicionesTemporales.end())
+ {
+ if (pos->origen == pos->destino){
+ gtk_object_destroy (GTK_OBJECT (pos->item));
+ group = GNOME_CANVAS_GROUP (pinta_autotransicion (pos->origen));
+ goto NOMBRE;
+ }
+
+ group_parent = GNOME_CANVAS_GROUP(pos->item);
+
+ list_items = group_parent->item_list;
+
+ box = (GnomeCanvasItem *) g_list_nth_data (list_items, 0);
+
+ get_bounds (box, &x1, &y1, &x2, &y2);
+
+ group = repintar_transicion (GNOME_CANVAS_GROUP (root), pos->origen, pos->destino, (x1+x2)/2, (y1+y2)/2);
+
+ gnome_canvas_item_reparent (box, group);
+
+ NOMBRE:
+ /* Nombre Transicion */
+ if (pos->nombre.empty())
+ item_nombre = NULL;
+
+ else
+ item_nombre = gnome_canvas_item_new (root,
+ gnome_canvas_text_get_type (),
+ "text", pos->nombre.c_str(),
+ "x", (x2+x1)/2,
+ "y", (y2+y1)/2 + 5,
+ "font", "Sans 28",
+ "anchor", GTK_ANCHOR_N,
+ "fill_color", "black",
+ NULL);
+
+
+ add_transicion_lista (GNOME_CANVAS_ITEM(group),pos->origen, pos->destino, item_nombre, pos->codigo, pos->tiempo);
+
+ posNodos = ListaElementos.begin();
+
+ while( (posNodos != ListaElementos.end()) && (posNodos->item != pos->origen) )
+ posNodos++;
+
+ posNodos->listaAdyacentes.push_back(GNOME_CANVAS_ITEM(group));
+
+ if (pos->origen != pos->destino){
+ posNodos = ListaElementos.begin();
+
+ while( (posNodos != ListaElementos.end()) && (posNodos->item != pos->destino) )
+ posNodos++;
+
+ posNodos->listaAdyacentes.push_back(GNOME_CANVAS_ITEM(group));
+ }
+
+ pos++;
+ }
+
+}
+
+
+
+bool ventana_timer (GtkWindow *window, GdkEventMotion *event, gpointer data){
+
+ GtkWidget *ventana;
+
+ ventana = comprobar_ventana_abierta (NULL, TIMER);
+
+ if (ventana != NULL)
+ gtk_window_present (GTK_WINDOW(ventana));
+ else{
+ ventana = tiempo_iteracion();
+ add_ventana (ventana, NULL, TIMER);
+ }
+
+ return TRUE;
+
+}
+
+
+bool ventana_importar (GtkWindow *window, GdkEventMotion *event, gpointer data){
+
+ GtkWidget *ventana;
+
+ ventana = comprobar_ventana_abierta (NULL, LIBRERIAS);
+
+ if (ventana != NULL)
+ gtk_window_present (GTK_WINDOW(ventana));
+ else{
+ ventana = importar_librerias();
+ add_ventana (ventana, NULL, LIBRERIAS);
+ }
+
+ return TRUE;
+
+}
+
+
+
+bool codigo_esquema (GtkWindow *window, GdkEventMotion *event, gpointer data)
+{
+ GtkWidget *ventana;
+
+ ventana = comprobar_ventana_abierta (NULL, CODIGO);
+
+ if (ventana != NULL)
+ gtk_window_present (GTK_WINDOW(ventana));
+ else{
+ ventana = new_code_windows ();
+ add_ventana (ventana, NULL, CODIGO);
+ }
+
+ return TRUE;
+
+}
+
+
+
+void new_windows (GtkWindow *window, GdkEventMotion *event, gpointer data)
+{
+
+ static GtkWidget *window2;
+ GtkWidget *label;
+
+
+
+ /*Creamos Ventana*/
+ window2 = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+
+ /*Situamos la ventana en el medio*/
+ gtk_window_set_position(GTK_WINDOW(window2), GTK_WIN_POS_CENTER);
+
+ /*Ponemos borde a la ventana*/
+ gtk_container_set_border_width (GTK_CONTAINER (window2), 50);
+
+ /*Ponemos el titulo*/
+ gtk_window_set_title(GTK_WINDOW(window2), "Ayuda");
+
+ /* An option menu to change the position of the value */
+ label = gtk_label_new ((const char*)data);
+
+ gtk_container_add (GTK_CONTAINER(window2), label);
+
+ gtk_widget_show_all(window2);
+
+}
+
+
+
+/* Crea una Caja de Botones con los parámetros específicos */
+GtkWidget *create_bbox( gint horizontal,
+ char *title,
+ gint espacio,
+ gint child_w,
+ gint child_h,
+ gint layout,
+ gpointer data,
+ gpointer text)
+{
+ GtkWidget *frame;
+ GtkWidget *bbox;
+ GtkWidget *button;
+
+ frame = gtk_frame_new (title);
+ gtk_container_set_border_width (GTK_CONTAINER (frame), 0);
+
+ if (horizontal)
+ bbox = gtk_hbutton_box_new ();
+ else
+ bbox = gtk_vbutton_box_new ();
+
+ gtk_container_set_border_width (GTK_CONTAINER (bbox), 0);
+ gtk_container_add (GTK_CONTAINER (frame), bbox);
+
+ /* Establece la apariencia de la Caja de Botones */
+
+ gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GtkButtonBoxStyle(layout));
+
+ gtk_box_set_spacing (GTK_BOX (bbox), espacio);
+
+ list <GtkWidget *> ::iterator pos;
+
+ pos = ListaBotones.begin();
+ while (pos!=ListaBotones.end()){
+ gtk_container_add (GTK_CONTAINER (bbox), *pos);
+ pos++;
+ }
+
+ button = gtk_button_new_from_stock (GTK_STOCK_HELP);
+ gtk_signal_connect(GTK_OBJECT(button), "button_release_event", GTK_SIGNAL_FUNC(new_windows), text);
+
+ return frame;
+}
+
+
+void frame_callback(GtkWindow *window,
+ GdkEvent *event, gpointer data)
+{
+ int x, y;
+ char buf[10];
+ x = event->configure.x;
+ y = event->configure.y;
+ sprintf(buf, "%d, %d", x, y);
+ printf("Mover %d, %d\n", x, y);
+ gtk_window_set_title(window, buf);
+}
+
+void guardar(GtkWindow *windows, gpointer data)
+{
+ xmlDocPtr doc;
+
+ GtkWidget *dialog;
+ GtkFileFilter *filter;
+
+ cout << directorio << endl;
+ cout << (int)data << endl;
+
+ if ( (((int)data ==0) && (directorio == "")) || ((int)data == 1) ){
+ dialog = gtk_file_chooser_dialog_new ("Save File", NULL,
+ GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL);
+
+ gtk_window_set_title(GTK_WINDOW(dialog), "Save File");
+
+ gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER(dialog), TRUE);
+
+ filter = gtk_file_filter_new();
+ gtk_file_filter_set_name (filter, "xml");
+ gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
+ gtk_file_filter_add_pattern (filter, "*.[x][m][l]");
+
+ filter = gtk_file_filter_new();
+ gtk_file_filter_set_name (filter, "All files");
+ gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
+ gtk_file_filter_add_pattern (filter, "*");
+
+ }
+ if (((int)data ==0) & (directorio != "")){
+
+ doc = xml_new_doc ("VisualHFSM");
+
+ //**************************************************Antes de llamar a guardar ponemos en las variables del nodo del nivel en el que nos
+ //**************************************************encontremos las variables globales que estuviesemos usando en ese momento.
+ list<tSubAut>::iterator posNodoSub;
+ posNodoSub = ListaSubAutomatas.begin();
+
+ while (posNodoSub->idSub != subautomata_mostrado and posNodoSub != ListaSubAutomatas.end())
+ posNodoSub++;
+
+ posNodoSub->ListaElementosSub = ListaElementos;
+ posNodoSub->ListaTransicionesSub = ListaTransiciones;
+ posNodoSub->tiempoIteracionSub = tiempoIteracion;
+ posNodoSub->variablesSub = variables;
+ posNodoSub->funcionesSub = funciones;
+ posNodoSub->impSub = imp;
+ //**************************************************************************************************************************************
+
+ xml_new_entry (doc);
+
+ xmlSaveFile ((directorio + nombreEsquema + ".xml").c_str(), doc);
+ }
+ else if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
+ char *filename;
+
+ filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+
+ printf("File open: %s\n",filename);
+
+ compile_file = filename;
+
+ // Nombre y directorio fichero
+
+ string fich = filename;
+ int i;
+ size_t pos;
+ for (i=0; i < (signed)fich.length(); i++)
+ {
+ if (fich.at(i) == '/')
+ pos = i;
+ }
+ string fichero = fich.substr (++pos);
+
+ directorio = fich.substr (0,pos);
+
+ string nombre;
+
+ for (i=0; i < (signed)fichero.length(); i++)
+ {
+ if (fichero.at(i) == '.')
+ pos = i;
+ }
+
+ nombre = fichero.substr (0,pos);
+
+ nombreEsquema = nombre;
+
+ /*Ponemos el titulo*/
+ gtk_window_set_title(GTK_WINDOW(window), nombre.c_str());
+
+ doc = xml_new_doc ("VisualHFSM");
+
+ //**************************************************Antes de llamar a guardar ponemos en las variables del nodo del nivel en el que nos
+ //**************************************************encontremos las variables globales que estuviesemos usando en ese momento.
+ list<tSubAut>::iterator posNodoSub;
+ posNodoSub = ListaSubAutomatas.begin();
+
+ while (posNodoSub->idSub != subautomata_mostrado and posNodoSub != ListaSubAutomatas.end())
+ posNodoSub++;
+
+ posNodoSub->ListaElementosSub = ListaElementos;
+ posNodoSub->ListaTransicionesSub = ListaTransiciones;
+ posNodoSub->tiempoIteracionSub = tiempoIteracion;
+ posNodoSub->variablesSub = variables;
+ posNodoSub->funcionesSub = funciones;
+ posNodoSub->impSub = imp;
+ //**************************************************************************************************************************************
+
+ xml_new_entry (doc);
+
+ xmlSaveFile (filename, doc);
+
+ g_free (filename);
+
+ gtk_widget_destroy (dialog);
+
+ }
+ else
+ gtk_widget_destroy (dialog);
+
+}
+
+void remarcar_boton (GtkFileChooser *window, gpointer data)
+ {
+ gtk_widget_grab_focus ((GtkWidget *)data);
+ }
+
+void borrar_canvas ()
+{
+
+ list<tTransicion>::iterator posTransiciones;
+
+ posTransiciones = ListaTransiciones.begin();
+
+ while (posTransiciones != ListaTransiciones.end())
+ {
+ gtk_object_destroy (GTK_OBJECT ((posTransiciones->item_nombre)));
+ gtk_object_destroy (GTK_OBJECT ((posTransiciones->item)));
+ posTransiciones++;
+ }
+
+ ListaTransiciones.clear();
+
+ list<tNodo>::iterator posNodos;
+
+ posNodos = ListaElementos.begin();
+
+ while (posNodos != ListaElementos.end())
+ {
+ gtk_object_destroy (GTK_OBJECT ((posNodos->item->parent)));
+ posNodos++;
+ }
+
+ ListaElementos.clear();
+
+ gnome_canvas_update_now (GNOME_CANVAS(canvas));
+
+}
+
+
+void cargar(GtkWindow *windows, gpointer data)
+{
+ xmlDocPtr doc;
+
+ xmlNodePtr root;
+
+ xmlNodePtr nodeSub;
+
+ xmlNodePtr node;
+
+ list<tSubAut>::iterator posSub;//Añadido para luego poder cargar en las variables globales la primera posicion de la lista de subAut.
+
+ GtkFileFilter *filter;
+
+ GtkWidget *dialog;
+
+ dialog = gtk_file_chooser_dialog_new ("Open File",
+ NULL,
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ NULL);
+
+ filter = gtk_file_filter_new();
+ gtk_file_filter_set_name (filter, "xml");
+ gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
+ gtk_file_filter_add_pattern (filter, "*.[x][m][l]");
+
+ filter = gtk_file_filter_new();
+ gtk_file_filter_set_name (filter, "All files");
+ gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
+ gtk_file_filter_add_pattern (filter, "*");
+
+ gtk_window_set_title(GTK_WINDOW(dialog), "Open File");
+
+ if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
+ {
+ /* Dirección del fichero */
+ char *filename;
+
+ filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+
+ printf("Fichero abierto: %s\n",filename);
+
+ /* Abrir XML */
+
+ doc = xmlParseFile (filename);
+
+ if (!doc) {
+ g_print("Error al cargar documento XML\n");
+ }
+ else{
+ item_guardado = NULL;
+ root = xmlDocGetRootElement (doc);
+ nodeSub = root->xmlChildrenNode;
+ //node = nodeSub->xmlChildrenNode;
+
+
+ /* Borrar Canvas */
+
+ if (!ListaSubAutomatas.empty()){
+
+ posSub = ListaSubAutomatas.begin();
+
+ while (posSub != ListaSubAutomatas.end()){
+
+ ListaElementos = posSub->ListaElementosSub;
+ ListaTransiciones = posSub->ListaTransicionesSub;
+
+ borrar_canvas();
+ printf("Borrado nivel \n");
+
+ posSub++;
+
+ }
+
+ }
+ else
+ borrar_canvas();
+
+ ListaSubAutomatas.clear();
+
+ /* Recuperamos los datos */
+
+ while (nodeSub != NULL){
+ g_print("Encontrado Sub: %s\n", nodeSub->name);//*****************************************************************
+
+ node = nodeSub->xmlChildrenNode;
+
+ if (strcmp((const char *)nodeSub->name, "nombreEsquema")==0){
+
+ string fich = (const char*)xmlNodeGetContent (nodeSub);
+ if (fich != ""){
+ size_t pos;
+
+ pos = fich.rfind('/');
+ printf("fich: %s\n",fich.c_str());//**********************************************************************
+ nombreEsquema = fich.substr (++pos);
+
+ printf("nombreEsquema: %s\n",nombreEsquema.c_str());//****************************************************
+
+
+ directorio = filename;
+ pos = directorio.rfind('/');
+ directorio = directorio.substr (0,++pos);
+
+ /*Ponemos el titulo*/
+ gtk_window_set_title(GTK_WINDOW(window), nombreEsquema.c_str());
+ }else{
+ /*Ponemos el titulo*/
+ gtk_window_set_title(GTK_WINDOW(window),"Default");
+ }
+
+ }else if (strcmp((const char *)nodeSub->name, "SubAutomata")==0){
+
+ g_print("Entra por subautomata\n");//**************************************************************
+
+ while (node != NULL) {
+
+ g_print("Encontrado nodo %s\n", node->name);
+
+ if (strcmp((const char *)node->name, "idSub")==0){
+ reg_sub.idSub = atoi((const char*)xmlNodeGetContent (node));
+ if (reg_sub.idSub > idSubGlobal){
+ idSubGlobal = reg_sub.idSub;
+ }
+ }
+ else if (strcmp((const char *)node->name, "idPadre")==0)
+ reg_sub.idPadre = atoi((const char*)xmlNodeGetContent (node));
+ else if (strcmp((const char *)node->name, "tiempoIteracion")==0)
+ reg_sub.tiempoIteracionSub = atoi((const char*)xmlNodeGetContent (node));
+ else if (strcmp((const char *)node->name, "variables_aux")==0)
+ reg_sub.variablesSub = (const char*)xmlNodeGetContent (node);
+ else if (strcmp((const char *)node->name, "funciones_aux")==0)
+ reg_sub.funcionesSub = (const char*)xmlNodeGetContent (node);
+ else if (strcmp((const char *)node->name, "Librerias")==0){
+ xmlNodePtr child = node->xmlChildrenNode;
+ string lib;
+ while (child != NULL){
+ lib = (const char*)xmlNodeGetContent (child);
+ if (lib == "laser")
+ reg_sub.impSub.laser = true;
+ if (lib == "motor")
+ reg_sub.impSub.motor = true;
+ if (lib == "radar")
+ reg_sub.impSub.radar = true;
+ if (lib == "encoders")
+ reg_sub.impSub.encoders = true;
+ if (lib == "lat_lon")
+ reg_sub.impSub.lat_lon = true;
+ if (lib == "camara")
+ reg_sub.impSub.camara = true;
+ if (lib == "ptencoders")
+ reg_sub.impSub.ptencoders = true;
+
+ child = child->next;
+ }
+ }else//Aqui se extraen los datos de cada estado concreto
+ xml_get_entry (node);
+
+ node = node->next;
+
+ }//While node
+
+
+ /* Pintado de Transiciones */
+
+ list<transicion_aux>::iterator pos, pos2;
+
+ pos = ListaTransicionesTemporales.begin();
+
+ while (pos != ListaTransicionesTemporales.end())
+ {
+ if (pos->destino == NULL)
+ {
+ pos2 = ListaTransicionesTemporales.begin();
+ while (pos2 != ListaTransicionesTemporales.end()){
+ if (pos->destino_id == pos2->origen_xml)
+ pos->destino = pos2->origen;
+ pos2++;
+ }
+ }
+ pos++;
+ }
+
+ gnome_canvas_update_now (GNOME_CANVAS(canvas));
+
+ cout << "item_guardado " << item_guardado << endl;
+
+ item_guardado = NULL;
+
+ cargar_transiciones ();
+
+ ListaTransicionesTemporales.clear();
+
+ reg_sub.ListaElementosSub = ListaElementos;
+ reg_sub.ListaTransicionesSub = ListaTransiciones;
+
+ //Borramos el canvas a cada iteracion para que no se pinte todo a la vez, la información para poder
+ //restaurar cada nivel en el canvas ya la tenemos guardada en cada nodo de la lista de subAutómatas
+ //borrar_canvas();
+
+ ListaElementos.clear();
+ ListaTransiciones.clear();
+
+ ListaSubAutomatas.push_back(reg_sub);
+
+ //Borramos el subautomata que acabamos de pintar para al final de la carga pintar solo el primer nivel.
+ ocultar_subautomata(reg_sub.idSub);
+
+
+ }//else de SubAutomata
+
+ nodeSub = nodeSub->next;
+
+ }//While nodeSub
+
+ }
+
+ g_free (filename);
+
+ }
+
+ gtk_widget_destroy (dialog);
+
+ //Pintamos el canvas con los elementos del subautomata 1, la raiz.
+ printf("Antes de pintar sub\n");
+ mostrar_subautomata(1);
+ printf("Despues de pintar sub\n");
+
+ //Cargamos en las variables "globales" las correspondientes al primer nodo de la lista de subautómatas.
+ posSub = ListaSubAutomatas.begin();
+
+ imp = posSub->impSub;
+ funciones = posSub->funcionesSub;
+ variables = posSub->variablesSub;
+ tiempoIteracion = posSub->tiempoIteracionSub;
+
+ ListaElementos = posSub->ListaElementosSub;
+ ListaTransiciones = posSub->ListaTransicionesSub;
+
+ //Dejamos preparada la variable idSubGlobal con un numero correlativo mayor al máximo cargado.
+ idSubGlobal++;
+
+ //Recargamos el tree view con los nuevos datos cargados
+ actualizar_tree_view();
+
+}
+
+
+void mostrar_subautomata(int pidSub)
+{
+
+ list<tSubAut>::iterator posSub;
+
+ list <tNodo>::iterator Elem;
+ list <tTransicion>::iterator Trans;
+
+
+ posSub = ListaSubAutomatas.begin();
+
+ while(posSub->idSub != pidSub){
+ posSub++;
+ }
+
+ Elem = posSub->ListaElementosSub.begin();
+ Trans = posSub->ListaTransicionesSub.begin();
+
+ /*group = GNOME_CANVAS_GROUP (gnome_canvas_item_new (root,
+ gnome_canvas_group_get_type (),
+ "x", 0,
+ "y", 0,
+ NULL));*/
+ if (!posSub->ListaElementosSub.empty()){
+ while(Elem != posSub->ListaElementosSub.end()){
+
+ if (Elem->item != NULL)
+ gnome_canvas_item_show(Elem->item);
+
+ if (Elem->estado_inicial != NULL)
+ gnome_canvas_item_show(Elem->estado_inicial);
+
+ if (Elem->item_nombre != NULL)
+ gnome_canvas_item_show(Elem->item_nombre);
+
+ printf("Pintado nodo en el canvas\n");
+
+ Elem++;
+
+ }
+
+ while (Trans != posSub->ListaTransicionesSub.end()){
+
+ if(Trans->item != NULL)
+ gnome_canvas_item_show(Trans->item);
+
+ if(Trans->item_nombre != NULL)
+ gnome_canvas_item_show(Trans->item_nombre);
+
+ Trans++;
+
+ }
+ }
+
+
+ printf("Antes de update en el mostrar\n");
+ //gnome_canvas_update_now (GNOME_CANVAS(canvas));
+ printf("Despues de update en el mostrar\n");
+ subautomata_mostrado = pidSub;
+
+}
+
+
+void ocultar_subautomata(int pidSub)
+{
+
+ list<tSubAut>::iterator posSub;
+
+ list <tNodo>::iterator Elem;
+ list <tTransicion>::iterator Trans;
+
+
+ posSub = ListaSubAutomatas.begin();
+
+ while(posSub->idSub != pidSub){
+ posSub++;
+ }
+
+ Elem = posSub->ListaElementosSub.begin();
+ Trans = posSub->ListaTransicionesSub.begin();
+
+ /*group = GNOME_CANVAS_GROUP (gnome_canvas_item_new (root,
+ gnome_canvas_group_get_type (),
+ "x", 0,
+ "y", 0,
+ NULL));*/
+
+ while(Elem != posSub->ListaElementosSub.end()){
+
+ if (Elem->item != NULL)
+ gnome_canvas_item_hide(Elem->item);
+
+ if (Elem->estado_inicial != NULL)
+ gnome_canvas_item_hide(Elem->estado_inicial);
+
+ if (Elem->item_nombre != NULL)
+ gnome_canvas_item_hide(Elem->item_nombre);
+
+ Elem++;
+
+ }
+
+ while (Trans != posSub->ListaTransicionesSub.end()){
+
+ if(Trans->item != NULL)
+ gnome_canvas_item_hide(Trans->item);
+
+ if(Trans->item_nombre != NULL)
+ gnome_canvas_item_hide(Trans->item_nombre);
+
+ Trans++;
+
+ }
+
+ gnome_canvas_update_now (GNOME_CANVAS(canvas));
+
+
+}
+
+
+void coordenadas(GtkWindow *window, GdkEvent *event, gpointer data)
+{
+
+ origenX = event->button.x;
+ origenY = event->button.y;
+ printf("Click Press %d, %d\n", origenX, origenY);
+
+ if (event->button.button == 3){
+
+ gtk_menu_popup(GTK_MENU(menu_pegar),NULL,NULL,NULL,NULL,event->button.button,event->button.time);
+
+ }
+
+}
+
+
+void pinta_nodo(GtkWindow *window, GdkEventMotion *event, gpointer data)
+{
+ int x, y;
+
+ GnomeCanvasItem *item;
+ GnomeCanvasGroup *group;
+
+ list<tSubAut>::iterator posSub; //Añadido para poder iterar en la lista de subautomatas y actulizar el treeview con cada nuevo estado
+
+ //GtkWidget *button;
+
+ x = event->x;
+ y = event->y;
+
+ points = gnome_canvas_points_new(2); /* 2 puntos */
+ points->coords[0] = origenX;
+ points->coords[1] = origenY;
+ points->coords[2] = x;
+ points->coords[3] = y;
+
+ printf("Click %d, %d\n", x, y);
+ //printf("Pintamos Nodo \n");
+
+ if ((strcmp(botonPulsado.c_str(), "Cuadrado")==0) and (event->state & GDK_BUTTON1_MASK))
+ {
+
+ group = GNOME_CANVAS_GROUP (gnome_canvas_item_new (root,
+ gnome_canvas_group_get_type (),
+ "x", 0,
+ "y", 0,
+ NULL));
+
+ item = gnome_canvas_item_new(group,
+ gnome_canvas_ellipse_get_type(),
+ "x1", (double) origenX-20,
+ "y1", (double) origenY-20,
+ "x2", (double) (origenX + 20),
+ "y2", (double) (origenY + 20),
+ "fill_color_rgba", 0x00ffffff,
+ "outline_color", "black",
+ "width_units", 1.0,
+ NULL);
+
+
+ registro.item = item;
+ registro.item_nombre = NULL;
+ registro.estado_inicial = NULL;
+ registro.nombre = "";
+ registro.codigo = "";
+ registro.idHijo = 0;//***********Por defecto un estado no tiene hijos
+ id ++;
+
+ ListaElementos.push_back(registro);
+
+ /*Añadimos control (señal) al item creado*/
+ g_signal_connect (group, "event",
+ (GtkSignalFunc) item_event,
+ NULL);
+
+ //Actualizamos datos necesarios para mostrar cambios en el tree view
+ posSub = ListaSubAutomatas.begin();
+
+ while(posSub->idSub != subautomata_mostrado)
+ {
+ posSub++;
+ }
+
+ //guardamos el estado de la lista de elementos en el nodo del subautomata para poder recargar bien el tree view
+ posSub->ListaElementosSub = ListaElementos;
+
+ actualizar_tree_view();
+
+ gtk_tree_view_expand_to_path(GTK_TREE_VIEW(tree_view), arbolPath);
+
+ }
+
+}
+
+static gint nodo(GtkWindow *window, GdkEventMotion *event, gpointer data)
+{
+ int x, y;
+
+ x = event->x;
+ y = event->y;
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(botonLinea),FALSE);
+
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(botonEstado))){
+
+ botonPulsado="Nada";
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(botonEstado),FALSE);
+
+ }
+ else{
+ botonPulsado="Cuadrado";
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(botonEstado),TRUE);
+ }
+
+
+ /*if ((int)data == 1)
+ {
+ botonPulsado="EstadoInicial";
+ }
+ else{
+ printf("Click %d, %d\n", x, y);
+
+ botonPulsado="Cuadrado";
+
+ }*/
+
+ return TRUE;
+}
+
+
+static gint motion_notify_event(GtkWindow *window, GdkEventMotion *event, gpointer data)
+{
+ int x, y;
+
+ x = event->x;
+ y = event->y;
+
+ printf("Click %d, %d\n", x, y);
+
+ return TRUE;
+}
+
+void transicion(GtkWindow *window, GdkEventMotion *event, gpointer data)
+{
+ item_transicion_saved = NULL;
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(botonEstado),FALSE);
+
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(botonLinea))){
+
+ botonPulsado="Nada";
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(botonLinea),FALSE);
+
+ }
+ else{
+ botonPulsado="Linea";
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(botonLinea),TRUE);
+ }
+
+}
+
+
+void mover(GtkWindow *window, GdkEventMotion *event, gpointer data)
+{
+ botonPulsado = "Mover";
+}
+
+void eliminar(GtkWindow *window, GdkEventMotion *event, gpointer data)
+{
+ botonPulsado = "Eliminar";
+}
+
+void copiar(GtkWindow *window, GdkEventMotion *event, gpointer data)
+{
+ botonPulsado = "Copiar";
+}
+
+void editar(GtkWindow *window, GdkEventMotion *event, gpointer data)
+{
+ botonPulsado = "Editar";
+}
+
+void nombrar(GtkWindow *window, GdkEventMotion *event, gpointer data)
+{
+ botonPulsado = "Nombrar";
+}
+
+void set_zoom (GtkWidget *window, GdkEvent *event, gpointer data){
+
+ double incremento = 0.1;
+
+ cout << gdk_keyval_name (event->key.keyval) << endl;
+ cout << event->key.keyval << endl;
+
+ if (event->key.keyval == GDK_Up)
+ zoom += incremento;
+ if (event->key.keyval == GDK_Down)
+ zoom -= incremento;
+ if (event->key.keyval == GDK_KP_0)
+ zoom = 1.0;
+
+ gnome_canvas_set_pixels_per_unit ((GnomeCanvas*)canvas, zoom);
+
+}
+
+
+//------------Funcion arriba añadida para navegacion entre niveles jerarquicos
+void arriba(GtkWindow *window, GdkEventMotion *event, gpointer data)
+{
+
+ list<tSubAut>::iterator posSub;
+
+ list <tNodo>::iterator posNodo;
+ //list <tTransicion>::iterator Trans;
+
+ int idPadre;
+
+ printf("Entra ARRIBA\n");
+
+ botonPulsado = "Nada";//Para evitar interferencias con los eventos detectados en el canvas
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(botonEstado),FALSE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(botonLinea),FALSE);
+
+ posSub = ListaSubAutomatas.begin();
+
+ while(posSub->idSub != subautomata_mostrado){
+ posSub++;
+ }
+
+ idPadre = posSub->idPadre;
+
+ if (idPadre != 0){
+ printf("idPadre distinto de 0\n");
+ if (!ListaElementos.empty()){
+
+ printf("La lista NO esta vacia\n");
+
+ //Guardamos el nivel actual
+ posSub->ListaElementosSub = ListaElementos;
+ posSub->ListaTransicionesSub = ListaTransiciones;
+ posSub->tiempoIteracionSub = tiempoIteracion;
+ posSub->variablesSub = variables;
+ posSub->funcionesSub = funciones;
+ posSub->impSub = imp;
+
+ ocultar_subautomata(subautomata_mostrado);
+
+ posSub = ListaSubAutomatas.begin();
+
+ while (posSub->idSub != idPadre and posSub != ListaSubAutomatas.end())
+ posSub++;
+
+ mostrar_subautomata(idPadre);
+
+ ListaElementos.clear();
+ ListaTransiciones.clear();
+
+ //Cargamos el nivel que vamos a mostrar
+ ListaElementos = posSub->ListaElementosSub;
+ ListaTransiciones = posSub->ListaTransicionesSub;
+ tiempoIteracion = posSub->tiempoIteracionSub;
+ variables = posSub->variablesSub;
+ funciones = posSub->funcionesSub;
+ imp = posSub->impSub;
+
+ }
+ else
+ {
+ printf("La lista esta vacia\n");
+
+ posSub = ListaSubAutomatas.begin();
+
+ while (posSub->idSub != subautomata_mostrado and posSub != ListaSubAutomatas.end())
+ posSub++;
+
+ //Borramos el nodo que se había creado
+ ListaSubAutomatas.erase(posSub);
+
+ posSub = ListaSubAutomatas.begin();
+
+ while (posSub->idSub != idPadre and posSub != ListaSubAutomatas.end())
+ posSub++;
+
+ posNodo = posSub->ListaElementosSub.begin();
+
+ while (posNodo->idHijo != subautomata_mostrado and posNodo != posSub->ListaElementosSub.end())
+ posNodo++;
+
+ //Ponemos a 0 el hijo del estado que tenia como hijo al subautomata que se ha borrado.
+ posNodo->idHijo = 0;
+
+ change_item_color(posNodo->item, 3);
+
+ mostrar_subautomata(idPadre);
+
+ ListaElementos.clear();
+ ListaTransiciones.clear();
+
+ //Cargamos el nivel que vamos a mostrar
+ ListaElementos = posSub->ListaElementosSub;
+ ListaTransiciones = posSub->ListaTransicionesSub;
+ tiempoIteracion = posSub->tiempoIteracionSub;
+ variables = posSub->variablesSub;
+ funciones = posSub->funcionesSub;
+ imp = posSub->impSub;
+
+ }
+
+ actualizar_tree_view();
+
+ gtk_tree_path_up (arbolPath);
+
+ gtk_tree_view_expand_to_path(GTK_TREE_VIEW(tree_view), arbolPath);
+
+ }
+ else{
+
+ printf("idPadre igual a 0\n");
+
+ actualizar_tree_view();
+
+ gtk_tree_view_expand_to_path(GTK_TREE_VIEW(tree_view), arbolPath);
+
+ }
+
+ printf("Se ejecuta ARRIBA\n");
+
+
+}
+//------------FIN Funcion arriba añadida para navegacion entre niveles jerarquicos
+
+void actualizar_tree_view()
+{
+
+ list<tSubAut>::iterator posNodoSub;
+
+ //Guardamos los datos del nivel en el que estamos
+ posNodoSub = ListaSubAutomatas.begin();
+
+ while (posNodoSub->idSub != subautomata_mostrado and posNodoSub != ListaSubAutomatas.end())
+ posNodoSub++;
+
+ //Guardamos el nivel actual
+ posNodoSub->ListaElementosSub = ListaElementos;
+ posNodoSub->ListaTransicionesSub = ListaTransiciones;
+ posNodoSub->tiempoIteracionSub = tiempoIteracion;
+ posNodoSub->variablesSub = variables;
+ posNodoSub->funcionesSub = funciones;
+ posNodoSub->impSub = imp;
+
+ //actualizamos los datos del modelo del tree_view
+ gtk_tree_view_set_model(GTK_TREE_VIEW(tree_view), create_and_fill_model());
+
+}
+
+
+void rellenar_arbol_recursivo(GtkTreeStore *treestore, GtkTreeIter toplevel, int idSubautomata)
+{
+ GtkTreeIter child;
+ list<tSubAut>::iterator posNodoSub;
+ list<tNodo>::iterator posEst;
+
+ string cadena = "";
+
+ int contSinNombre = 1;
+
+ posNodoSub = ListaSubAutomatas.begin();
+
+ while (posNodoSub->idSub != idSubautomata and posNodoSub != ListaSubAutomatas.end())
+ {
+ posNodoSub++;
+ }
+
+ if (!posNodoSub->ListaElementosSub.empty())
+ {
+
+ posEst = posNodoSub->ListaElementosSub.begin();
+
+ while (posEst != posNodoSub->ListaElementosSub.end())
+ {
+
+ if (posEst->nombre != "")
+ {
+ cadena = posEst->nombre;
+ }
+ else
+ {
+ cadena = "NoName_"+int2string(contSinNombre);
+ contSinNombre++;
+ }
+
+ gtk_tree_store_append(treestore, &child, &toplevel);
+ gtk_tree_store_set(treestore, &child, COLUMN, cadena.c_str(),-1);
+
+ if (posEst->idHijo != 0)
+ {
+ //Con esta función recorreremos la lista de subautomatas recursivamente para ir añadiendo los datos correspondientes
+ //en el treeview
+ rellenar_arbol_recursivo(treestore, child, posEst->idHijo);
+
+ }
+
+ posEst++;
+
+ }
+
+ }
+
+}
+
+static GtkTreeModel *
+create_and_fill_model (void)
+{
+ GtkTreeStore *treestore;
+ GtkTreeIter toplevel;
+
+ list<tSubAut>::iterator posNodoSub;
+ list<tNodo>::iterator posEst;
+
+ string cadena = "";
+
+ int contSinNombre = 1;
+
+ treestore = gtk_tree_store_new(NUM_COLS, G_TYPE_STRING);
+
+ if (!ListaSubAutomatas.empty())
+ {
+ posNodoSub = ListaSubAutomatas.begin();
+
+ if (!posNodoSub->ListaElementosSub.empty())
+ {
+ posEst = posNodoSub->ListaElementosSub.begin();
+
+ while (posEst != posNodoSub->ListaElementosSub.end())
+ {
+
+ if (posEst->nombre != "")
+ {
+ cadena = posEst->nombre;
+ }
+ else
+ {
+ cadena = "NoName_"+int2string(contSinNombre);
+ contSinNombre++;
+ }
+
+ gtk_tree_store_append(treestore, &toplevel, NULL);
+ gtk_tree_store_set(treestore, &toplevel,
+ COLUMN, cadena.c_str(),
+ -1);
+
+ if (posEst->idHijo != 0)
+ {
+ //Con esta función recorreremos la lista de subautomatas recursivamente para ir añadiendo los datos correspondientes
+ //en el treeview
+ rellenar_arbol_recursivo(treestore, toplevel, posEst->idHijo);
+
+ }
+
+ posEst++;
+
+ }
+
+ }
+
+ }
+
+ return GTK_TREE_MODEL(treestore);
+}
+
+void treeview_onRowActivated(GtkTreeView *treeview,
+ GtkTreePath *path,
+ GtkTreeViewColumn *col,
+ gpointer userdata){
+
+ list<tSubAut>::iterator posSub;
+
+ list<tNodo>::iterator posNodo;
+
+ gint* indices;
+
+ int prof_path;
+
+ int niveles_restantes=0;
+ int i=0;
+
+ int sub_a_buscar = 1;
+ int sub_a_mostrar = 1;
+
+ int indice_leido = 0;
+ int contNodo = 0;
+
+ bool expandir = FALSE;
+
+
+ botonPulsado = "Nada";//Para evitar interferencias con los eventos detectados en el canvas
+
+ prof_path = gtk_tree_path_get_depth(path);
+
+
+
+ if (prof_path == 1) {//hemos seleccionado el primer nivel con lo cual mostramos la raiz
+
+ sub_a_mostrar = 1;
+
+ printf("Selecionado el raiz*********\n");
+
+ arbolPath = gtk_tree_path_new_first();
+ expandir = FALSE;
+
+ }
+ else{
+
+ //Quitamos el ultimo elemento del path porque queremos mostrar el subautomata con el ID que nos indique su padre
+ //con lo cual solo necesitaremos recorrer la lista de subautomatas hasta su padre.
+ gtk_tree_path_up (path);
+
+ arbolPath = gtk_tree_path_copy(path);
+
+ printf("path del doble click: %s\n", gtk_tree_path_to_string(path));
+
+ //Obtenemos sus indices en un array
+ indices = gtk_tree_path_get_indices(path);
+
+ //Obtenemos su profundidad para saber hasta cuando iterar al recorrer la lista de subautomatas
+ prof_path = gtk_tree_path_get_depth(path);
+
+ niveles_restantes = prof_path;
+
+ while (niveles_restantes != 0) {
+
+ printf("Niveles restantes: %d\n", niveles_restantes);
+ indice_leido = indices[i];
+
+ printf("Indice leido: %d\n", indice_leido);
+
+ posSub = ListaSubAutomatas.begin();
+
+ printf("Se busca por: %d\n", sub_a_buscar);
+
+ while(posSub->idSub != sub_a_buscar){
+ posSub++;
+ }
+
+ posNodo = posSub->ListaElementosSub.begin();
+
+ while(contNodo != indice_leido){
+ posNodo++;
+ contNodo++;
+
+ printf("Contador: %d\n", contNodo);
+ }
+
+ sub_a_buscar = posNodo->idHijo;
+
+ printf("Proxima busqueda: %d\n", sub_a_buscar);
+
+ contNodo = 0;
+ i++;
+ niveles_restantes--;
+
+ }
+
+ sub_a_mostrar = sub_a_buscar;
+
+ sub_a_buscar = 1;
+
+ printf("Sub a mostrar: %d\n", sub_a_mostrar);
+
+ expandir = TRUE;
+
+ }
+
+
+ //Ahora viene una gestion equivalente a la de el boton "UP"
+ int idPadre;
+
+ posSub = ListaSubAutomatas.begin();
+
+ while(posSub->idSub != subautomata_mostrado){
+ posSub++;
+ }
+
+ idPadre = posSub->idPadre;
+
+ if (!ListaElementos.empty()){
+
+ //Guardamos el nivel actual
+ posSub->ListaElementosSub = ListaElementos;
+ posSub->ListaTransicionesSub = ListaTransiciones;
+ posSub->tiempoIteracionSub = tiempoIteracion;
+ posSub->variablesSub = variables;
+ posSub->funcionesSub = funciones;
+ posSub->impSub = imp;
+
+ ocultar_subautomata(subautomata_mostrado);
+
+ posSub = ListaSubAutomatas.begin();
+
+ while (posSub->idSub != sub_a_mostrar and posSub != ListaSubAutomatas.end())
+ posSub++;
+
+ mostrar_subautomata(sub_a_mostrar);
+
+ ListaElementos.clear();
+ ListaTransiciones.clear();
+
+ //Cargamos el nivel que vamos a mostrar
+ ListaElementos = posSub->ListaElementosSub;
+ ListaTransiciones = posSub->ListaTransicionesSub;
+ tiempoIteracion = posSub->tiempoIteracionSub;
+ variables = posSub->variablesSub;
+ funciones = posSub->funcionesSub;
+ imp = posSub->impSub;
+
+ }
+ else
+ {
+
+ posSub = ListaSubAutomatas.begin();
+
+ while (posSub->idSub != subautomata_mostrado and posSub != ListaSubAutomatas.end())
+ posSub++;
+
+ //Borramos el nodo que se había creado
+ ListaSubAutomatas.erase(posSub);
+
+ posSub = ListaSubAutomatas.begin();
+
+ while (posSub->idSub != idPadre and posSub != ListaSubAutomatas.end())
+ posSub++;
+
+ posNodo = posSub->ListaElementosSub.begin();
+
+ while (posNodo->idHijo != subautomata_mostrado and posNodo != posSub->ListaElementosSub.end())
+ posNodo++;
+
+ //Ponemos a 0 el hijo del estado que tenia como hijo al subautomata que se ha borrado.
+ posNodo->idHijo = 0;
+
+ change_item_color(posNodo->item, 3);
+
+ posSub = ListaSubAutomatas.begin();
+
+ while (posSub->idSub != sub_a_mostrar and posSub != ListaSubAutomatas.end())
+ posSub++;
+
+ mostrar_subautomata(sub_a_mostrar);
+
+ ListaElementos.clear();
+ ListaTransiciones.clear();
+
+ //Cargamos el nivel que vamos a mostrar
+ ListaElementos = posSub->ListaElementosSub;
+ ListaTransiciones = posSub->ListaTransicionesSub;
+ tiempoIteracion = posSub->tiempoIteracionSub;
+ variables = posSub->variablesSub;
+ funciones = posSub->funcionesSub;
+ imp = posSub->impSub;
+
+ }
+
+ actualizar_tree_view();
+
+ if (expandir){ //Solo hacemos la expansion si no hemos hecho doble click en el raiz
+
+ gtk_tree_view_expand_to_path(GTK_TREE_VIEW(tree_view), arbolPath);
+ }
+
+}
+
+static GtkWidget *
+create_view_and_model (void)
+{
+ GtkTreeViewColumn *col;
+ GtkCellRenderer *renderer;
+ GtkWidget *view;
+ GtkTreeModel *model;
+
+ view = gtk_tree_view_new();
+
+ col = gtk_tree_view_column_new();
+ //gtk_tree_view_column_set_title(col, (const gchar *)nombreEsquema);
+ gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
+
+ renderer = gtk_cell_renderer_text_new();
+ gtk_tree_view_column_pack_start(col, renderer, TRUE);
+ gtk_tree_view_column_add_attribute(col, renderer,
+ "text", COLUMN);
+
+ model = create_and_fill_model();
+ gtk_tree_view_set_model(GTK_TREE_VIEW(view), model);
+ g_object_unref(model);
+
+ g_signal_connect(view,"row-activated", (GCallback) treeview_onRowActivated, NULL);
+
+ return view;
+}
+
+void borrar_subautomata_recursivo(int sub_a_borrar){
+
+ list<tSubAut>::iterator posNodoSub;
+ list<tNodo>::iterator posEst;
+
+ posNodoSub = ListaSubAutomatas.begin();
+
+ while (posNodoSub->idSub != sub_a_borrar and posNodoSub != ListaSubAutomatas.end())
+ {
+ posNodoSub++;
+ }
+
+ posEst = posNodoSub->ListaElementosSub.begin();
+
+ while (posEst != posNodoSub->ListaElementosSub.end())
+ {
+
+ if (posEst->idHijo != 0){
+ borrar_subautomata_recursivo(posEst->idHijo);
+ }
+
+ posEst++;
+
+ }
+
+ ListaSubAutomatas.erase(posNodoSub);
+
+}
+
+
+
+int main( int argc, char *argv[])
+{
+
+ GtkWidget *boton;
+ //GtkWidget *botonLinea;
+ //GtkWidget *botonEstado;
+ GtkWidget *botonGuardar;
+ GtkWidget *botonCargar;
+ GtkWidget *caja1;
+ GtkWidget *scrolled;
+ GtkWidget *scrolled_tree;
+ GtkWidget *separator;
+
+ GtkWidget *frame_horz;
+ GtkWidget *vbox;
+ const char * text = "Spread (espacio 40)";
+
+ /*Inicializar parametros*/
+ gtk_init(&argc, &argv);
+
+ /*######################### Creacion de menus desplegables #############################*/
+
+ menu_estado = gtk_menu_new();
+
+ nombrar_estado = gtk_menu_item_new_with_label("Rename");
+ editar_estado = gtk_menu_item_new_with_label("Edit");
+ marcar_inicial_estado = gtk_menu_item_new_with_label("Mark as initial");
+ copiar_estado = gtk_menu_item_new_with_label("Copy");
+ eliminar_estado = gtk_menu_item_new_with_label("Delete");
+
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu_estado), nombrar_estado);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu_estado), editar_estado);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu_estado), marcar_inicial_estado);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu_estado), copiar_estado);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu_estado), eliminar_estado);
+
+ g_signal_connect_swapped (nombrar_estado, "activate", G_CALLBACK (on_menu_estado_nombrar), menu_estado);//Movido desde handler
+ g_signal_connect_swapped (editar_estado, "activate", G_CALLBACK (on_menu_estado_editar), menu_estado);
+ g_signal_connect_swapped (marcar_inicial_estado, "activate", G_CALLBACK (on_menu_estado_marcar_inicial), menu_estado);
+ g_signal_connect_swapped (copiar_estado, "activate", G_CALLBACK (on_menu_estado_copiar), menu_estado);
+ g_signal_connect_swapped (eliminar_estado, "activate", G_CALLBACK (on_menu_estado_eliminar), menu_estado);
+
+ gtk_widget_show (nombrar_estado);
+ gtk_widget_show (editar_estado);
+ gtk_widget_show (marcar_inicial_estado);
+ gtk_widget_show (copiar_estado);
+ gtk_widget_show (eliminar_estado);
+
+
+ menu_transicion = gtk_menu_new();
+
+ nombrar_transicion = gtk_menu_item_new_with_label("Rename");
+ editar_transicion = gtk_menu_item_new_with_label("Edit");
+ eliminar_transicion = gtk_menu_item_new_with_label("Delete");
+
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu_transicion), nombrar_transicion);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu_transicion), editar_transicion);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu_transicion), eliminar_transicion);
+
+ g_signal_connect_swapped (nombrar_transicion, "activate", G_CALLBACK (on_menu_transicion_nombrar), menu_transicion);//Movido desde handler
+ g_signal_connect_swapped (editar_transicion, "activate", G_CALLBACK (on_menu_transicion_editar), menu_transicion);
+ g_signal_connect_swapped (eliminar_transicion, "activate", G_CALLBACK (on_menu_transicion_eliminar), menu_transicion);
+
+ gtk_widget_show (nombrar_transicion);
+ gtk_widget_show (editar_transicion);
+ gtk_widget_show (eliminar_transicion);
+
+
+ menu_pegar = gtk_menu_new();
+
+ pegar_estado = gtk_menu_item_new_with_label("Paste");
+
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu_pegar), pegar_estado);
+
+ g_signal_connect_swapped (pegar_estado, "activate", G_CALLBACK (on_menu_pegar), menu_pegar);
+
+ gtk_widget_show (pegar_estado);
+
+ /*####################### FIN Creacion de menus desplegables ############################*/
+
+
+ /*Creamos Ventana*/
+ window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+
+ /*Situamos la ventana en el medio*/
+ gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_NONE);
+
+ /*Ponemos tamaño a la ventana*/
+ gtk_window_set_default_size(GTK_WINDOW(window), 1024, 768);
+ gtk_window_maximize (GTK_WINDOW(window));
+
+ /*Ponemos el titulo*/
+ gtk_window_set_title(GTK_WINDOW(window), "Default");
+
+ /* gtk_window_set_decorated(GTK_WINDOW (window), FALSE);*/
+ gtk_widget_add_events(window, GDK_BUTTON_PRESS_MASK);
+
+ /*Accion (motion_notify_event) asignada al pulsar el boton*/
+ gtk_signal_connect(GTK_OBJECT(window), "button_press_event", GTK_SIGNAL_FUNC(coordenadas), (gpointer)botonPulsado.c_str());
+ gtk_signal_connect(GTK_OBJECT(window), "button_release_event", GTK_SIGNAL_FUNC(pinta_nodo), (gpointer)botonPulsado.c_str());
+ //gtk_signal_connect(GTK_OBJECT(window), "2button_press_event", GTK_SIGNAL_FUNC(pegar), NULL);
+ gtk_signal_connect(GTK_OBJECT(window), "key-press-event", GTK_SIGNAL_FUNC(set_zoom), (gpointer)canvas);
+
+ /*Accion (gtk_main_quit) asignada al pulsar el boton X (salir)*/
+ gtk_signal_connect_object(GTK_OBJECT(window), "destroy", GTK_SIGNAL_FUNC(gtk_main_quit), GTK_OBJECT(window));
+
+ /*Creamos el boton*/
+ botonLinea = gtk_toggle_button_new_with_label ("Transition");
+ botonEstado = gtk_toggle_button_new_with_label ("Estate");
+ botonGuardar = gtk_button_new_with_label ("Save");
+ botonCargar = gtk_button_new_with_label ("Open");
+// botonGuardar = gtk_button_new_from_stock (GTK_STOCK_SAVE);
+// botonCargar = gtk_button_new_from_stock (GTK_STOCK_OPEN);
+
+ /*Al pulsar el boton, muestra las coordenadas x,y por pantalla*/
+
+ gtk_signal_connect(GTK_OBJECT(botonLinea), "button_release_event", GTK_SIGNAL_FUNC(transicion), (gpointer)botonPulsado.c_str());
+ gtk_signal_connect(GTK_OBJECT(botonEstado), "button_release_event", GTK_SIGNAL_FUNC(nodo), (gpointer)0);
+
+ gtk_signal_connect(GTK_OBJECT(botonGuardar), "released", GTK_SIGNAL_FUNC(guardar), (gpointer)0);
+ gtk_signal_connect(GTK_OBJECT(botonCargar), "button_release_event", GTK_SIGNAL_FUNC(cargar), NULL);
+
+
+ gtk_container_border_width (GTK_CONTAINER (window), 25);
+
+
+ /* ventana para tener barras de desplazamiento */
+ scrolled = gtk_scrolled_window_new(NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled), GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS);
+
+
+ /* canvas en modo RGB */
+ canvas = gnome_canvas_new_aa();
+
+ gtk_container_add(GTK_CONTAINER(scrolled), canvas);
+
+ gnome_canvas_set_scroll_region(GNOME_CANVAS(canvas),
+ 0, 0, CANVAS_SIZE, CANVAS_SIZE);
+
+ root = gnome_canvas_root(GNOME_CANVAS(canvas));
+
+ /*######################################################### AÑADIENDO TREE VIEW ##########################################################*/
+
+ /* ventana para tener barras de desplazamiento */
+ scrolled_tree = gtk_scrolled_window_new(NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_tree), GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS);
+
+ tree_view = create_view_and_model();
+
+ gtk_container_add(GTK_CONTAINER(scrolled_tree), tree_view);
+
+ arbolPath = gtk_tree_path_new_first();
+
+ printf("*********************************** Profundidad del path: %d \n", gtk_tree_path_get_depth (arbolPath));
+
+ //gtk_tree_view_expand_all(GTK_TREE_VIEW(tree_view));
+
+ /*######################################################FIN DE AÑADIENDO TREE VIEW#######################################################*/
+
+
+ /*Creamos una caja, contenemos el botons y la imagen en la caja y la caja en la ventana*/
+
+
+ caja1 = gtk_hbox_new(FALSE, 0);
+
+ separator = gtk_vseparator_new ();
+
+
+ /*Cambiar color canvas*/
+
+ GtkWidget *frame = gtk_frame_new (NULL);
+
+ gtk_widget_set_size_request (frame, 650, 300);//el 150 era 300
+
+ gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
+
+ gtk_container_add(GTK_CONTAINER(frame), scrolled);
+
+ GtkWidget *frame_tree = gtk_frame_new (NULL);
+
+ gtk_widget_set_size_request (frame_tree, 150, 300);
+
+ gtk_container_add(GTK_CONTAINER(frame_tree), scrolled_tree);
+
+
+ gtk_container_add(GTK_CONTAINER(caja1), frame_tree);
+
+ gtk_container_add(GTK_CONTAINER(caja1), frame);
+
+
+ frame_horz = gtk_frame_new ("Options");
+
+
+ /* Redimensionar Frame */
+ gtk_widget_set_size_request (frame_horz,300, -1);
+
+ gtk_box_pack_start (GTK_BOX (caja1), frame_horz, TRUE, TRUE, 10);
+
+
+ vbox = gtk_vbox_new (FALSE, 0);
+ gtk_container_set_border_width (GTK_CONTAINER (vbox), 10);
+ gtk_container_add (GTK_CONTAINER (frame_horz), vbox);
+
+
+ text = "Navigation";
+
+ string textAyuda = "Esto es una prueba";
+
+ /*boton = gtk_button_new_with_label ("Mover");
+ gtk_signal_connect(GTK_OBJECT(boton), "button_release_event", GTK_SIGNAL_FUNC(mover), 0);
+ ListaBotones.push_back(boton);
+
+ boton = gtk_button_new_from_stock (GTK_STOCK_DELETE);
+ gtk_signal_connect(GTK_OBJECT(boton), "button_release_event", GTK_SIGNAL_FUNC(eliminar), 0);
+ ListaBotones.push_back(boton);*/
+
+
+ //###################Añadido boton Arriba
+ boton = gtk_button_new_with_label ("UP");
+ gtk_signal_connect(GTK_OBJECT(boton), "button_release_event", GTK_SIGNAL_FUNC(arriba), NULL);
+ ListaBotones.push_back(boton);
+
+
+ gtk_box_pack_start (GTK_BOX (vbox),
+ create_bbox (TRUE, (char *)text, 40, 85, 20, GTK_BUTTONBOX_SPREAD,(gpointer)botonLinea , (gpointer)ayuda[0].c_str()), TRUE, TRUE, 0);
+
+ ListaBotones.erase( ListaBotones.begin(), ListaBotones.end());
+
+
+ text = "Figures";
+
+ ListaBotones.push_back(botonLinea);
+ ListaBotones.push_back(botonEstado);
+// boton = gtk_button_new_with_label ("Copy");
+// boton = gtk_button_new_from_stock (GTK_STOCK_COPY);
+// gtk_signal_connect(GTK_OBJECT(boton), "button_release_event", GTK_SIGNAL_FUNC(copiar), 0);
+// ListaBotones.push_back(boton);
+
+ textAyuda = "aa";
+ gtk_box_pack_start (GTK_BOX (vbox),
+ create_bbox (TRUE, (char *)text, 40, 85, 20, GTK_BUTTONBOX_SPREAD,(gpointer)botonLinea, (gpointer)ayuda[1].c_str()), TRUE, TRUE, 0);
+
+ ListaBotones.erase( ListaBotones.begin(), ListaBotones.end());
+
+ text = "Save/Open";
+
+ ListaBotones.push_back(botonGuardar);
+
+ boton = gtk_button_new_with_label ("Save as");
+// boton = gtk_button_new_from_stock (GTK_STOCK_SAVE_AS);
+ gtk_signal_connect(GTK_OBJECT(boton), "released", GTK_SIGNAL_FUNC(guardar), (gpointer)1);
+
+ ListaBotones.push_back(boton);
+
+ ListaBotones.push_back(botonCargar);
+
+ gtk_box_pack_start (GTK_BOX (vbox),
+ create_bbox (TRUE, (char *)text, 40, 85, 20, GTK_BUTTONBOX_SPREAD,(gpointer)botonLinea, (gpointer)ayuda[2].c_str()), TRUE, TRUE, 0);
+
+ ListaBotones.erase( ListaBotones.begin(), ListaBotones.end());
+
+/* text = "Edicion Estados";
+
+ //Creamos el boton
+
+ boton = gtk_button_new_with_label ("EstadoInicial");
+ gtk_signal_connect(GTK_OBJECT(boton), "button_release_event", GTK_SIGNAL_FUNC(nodo), (gpointer)1);
+ ListaBotones.push_back(boton);
+
+ boton = gtk_button_new_with_label ("Nombrar");
+ gtk_signal_connect(GTK_OBJECT(boton), "button_release_event", GTK_SIGNAL_FUNC(nombrar), NULL);
+ ListaBotones.push_back(boton);
+
+ boton = gtk_button_new_from_stock (GTK_STOCK_EDIT);
+ gtk_signal_connect(GTK_OBJECT(boton), "button_release_event", GTK_SIGNAL_FUNC(editar), NULL);
+ ListaBotones.push_back(boton);
+
+ gtk_box_pack_start (GTK_BOX (vbox),
+ create_bbox (TRUE, (char *)text, 40, 85, 20, GTK_BUTTONBOX_SPREAD,(gpointer)botonLinea, (gpointer)ayuda[3].c_str()), TRUE, TRUE, 0);
+
+ ListaBotones.erase( ListaBotones.begin(), ListaBotones.end());
+*/
+ text = "Subautomata data";
+
+ boton = gtk_button_new_with_label ("Intefaces");
+ ListaBotones.push_back(boton);
+ gtk_signal_connect(GTK_OBJECT(boton), "button_release_event", GTK_SIGNAL_FUNC(ventana_importar), NULL);
+
+ boton = gtk_button_new_with_label ("Timer");
+ ListaBotones.push_back(boton);
+ gtk_signal_connect(GTK_OBJECT(boton), "button_release_event", GTK_SIGNAL_FUNC(ventana_timer), NULL);
+
+ boton = gtk_button_new_with_label ("Variables");
+ ListaBotones.push_back(boton);
+ gtk_signal_connect(GTK_OBJECT(boton), "button_release_event", GTK_SIGNAL_FUNC(codigo_esquema), NULL);
+
+
+ gtk_box_pack_start (GTK_BOX (vbox),
+ create_bbox (TRUE, (char *)text, 40, 85, 20, GTK_BUTTONBOX_SPREAD,(gpointer)botonLinea, (gpointer)ayuda[4].c_str()), TRUE, TRUE, 0);
+
+ ListaBotones.erase( ListaBotones.begin(), ListaBotones.end());
+
+ text = "Code and Compile";
+
+ GtkWidget* img1= gtk_image_new_from_file("./imagenes/compilar.jpg");
+ boton = gtk_button_new_with_label ("Generate code");
+ gtk_button_set_image((GtkButton*)boton,img1);
+ ListaBotones.push_back(boton);
+ gtk_signal_connect(GTK_OBJECT(boton), "button_release_event", GTK_SIGNAL_FUNC(generar_c), NULL);
+
+ boton = gtk_button_new_with_label ("Compile"); // Compilar
+ ListaBotones.push_back(boton);
+ gtk_signal_connect(GTK_OBJECT(boton), "button_release_event", GTK_SIGNAL_FUNC(compilar), NULL);
+
+ gtk_box_pack_start (GTK_BOX (vbox),
+ create_bbox (TRUE, (char *)text, 40, 85, 20, GTK_BUTTONBOX_SPREAD,(gpointer)botonLinea, (gpointer)ayuda[4].c_str()), TRUE, TRUE, 0);
+
+ ListaBotones.erase( ListaBotones.begin(), ListaBotones.end());
+
+ gtk_container_add(GTK_CONTAINER(window), caja1);
+
+ gtk_widget_show_all(window);
+
+ //**********************************************************************Creamos el primer nodo en la lista de subautomatas
+ //**********************************************************************Habra que eliminarlo, hacer este guardado en cambios
+ //**********************************************************************de nivel o cuando se guarde el esquema.
+ reg_sub.ListaElementosSub = ListaElementos;
+ reg_sub.ListaTransicionesSub = ListaTransiciones;
+ reg_sub.idSub = idSubGlobal;
+ reg_sub.idPadre = 0;
+
+ ListaSubAutomatas.push_back(reg_sub);
+
+ idSubGlobal++;
+ //************************************************************************************************************************
+
+
+ /*Bucle*/
+ gtk_main();
+
+ return 0;
+}
+
+
+void desconectarLinea (GnomeCanvasItem *transicion, GnomeCanvasItem *estado)
+{
+ list<tNodo>::iterator pos;
+
+ list<GnomeCanvasItem *>::iterator pos2;
+
+
+
+ pos = ListaElementos.begin();
+
+ while(pos->item != estado)
+ {
+ pos++;
+ }
+
+ pos2 = pos->listaAdyacentes.begin();
+
+ while((*pos2) != transicion)
+ {
+ pos2++;
+ }
+ pos->listaAdyacentes.erase(pos2);
+
+}
+
+
+void eliminarLinea (GnomeCanvasItem *item, gpointer data)
+{
+ if ((botonPulsado == "Eliminar") || (botonPulsado == "Mover")) {
+ list<tTransicion>::iterator pos;
+
+ pos = ListaTransiciones.begin();
+
+
+
+ while(pos != ListaTransiciones.end())
+ {
+ pos++;
+ }
+
+ pos = ListaTransiciones.begin();
+
+ while(pos->item != item)
+ {
+ pos++;
+ }
+ GnomeCanvasItem * origen = pos->origen;
+
+ GnomeCanvasItem * destino = pos->destino;
+
+ desconectarLinea (item,origen);
+
+ desconectarLinea (item,destino);
+
+ ListaTransiciones.erase(pos);
+
+ gtk_object_destroy (GTK_OBJECT (item));
+
+ }
+}
+void
+change_item_width (gpointer data, gpointer user_data)
+{
+ gnome_canvas_item_set (GNOME_CANVAS_ITEM (data),
+ "width_units", (double)(int)user_data,
+ NULL);
+}
+
+static gint
+item_event_linea (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
+{
+ GList * list_items;
+
+ switch (event->type) {
+ case GDK_2BUTTON_PRESS:
+ if ((event->button.button == 1) & (botonPulsado == "Editar")){
+ /* Cambia el color del item */
+ cout << "Cambiar color: " << endl;
+ id = (int)item;
+ change_item_color (item,0);
+ new_text_windows (item,(gchar*)"transicion");
+ return TRUE;
+ }
+ break;
+ case GDK_BUTTON_PRESS:
+ if ((event->button.button == 3) & (botonPulsado == "Eliminar")){
+ eliminarLinea(item, NULL);
+ cout << "Eliminado: " << endl;
+ return TRUE;
+ }
+ break;
+ case GDK_ENTER_NOTIFY:
+ /* Establece la linea ancha */
+ if (botonPulsado != "Nombrar"){
+ list_items = GNOME_CANVAS_GROUP (item)->item_list;
+ g_list_foreach (list_items, change_item_width, (gpointer) 3);
+ }
+ return TRUE;
+
+ case GDK_LEAVE_NOTIFY:
+ /* Establece la linea estrecha */
+ if (botonPulsado != "Nombrar"){
+ list_items = GNOME_CANVAS_GROUP (item)->item_list;
+ g_list_foreach (list_items, change_item_width, (gpointer) 1);
+ }
+ return TRUE;
+
+ default:
+ break;
+ }
+
+ return FALSE;
+
+}
+
+
+
+gint
+highlight_box (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
+{
+ GdkCursor *fleur;
+ static double x, y; /* used to keep track of motion coordinates */
+ double new_x, new_y;
+ double x1,x2,y1,y2;
+ list<tTransicion>::iterator posLinea;
+ GnomeCanvasItem *origen, *destino, *arrow, *box;
+ GnomeCanvasGroup *group, *group_parent;
+ GList * list_items;
+ GtkWidget *ventana;
+ bool b;
+
+ switch (event->type) {
+ case GDK_ENTER_NOTIFY:
+ gnome_canvas_item_set (item,
+ "fill_color", "red",
+ NULL);
+
+ break;
+
+ case GDK_LEAVE_NOTIFY:
+ if (!(event->crossing.state & GDK_BUTTON1_MASK))
+ gnome_canvas_item_set (item,
+ "fill_color_rgba", NULL,
+ NULL);
+ break;
+
+ case GDK_BUTTON_PRESS:
+
+ if ((event->button.button == 1) && (botonPulsado == "Nombrar")) {
+
+ change_item_color (item,0);
+
+ ventana = comprobar_ventana_abierta (item->parent, NOMBRAR);
+
+ if (ventana != NULL)
+ gtk_window_present (GTK_WINDOW(ventana));
+ else{
+ ventana = new_name_windows (item->parent);
+ add_ventana (ventana, item->parent, NOMBRAR);
+ }
+
+ }else if (event->button.button == 1) {
+ /* Recuerda la posición inicial */
+ x = event->button.x;
+ y = event->button.y;
+
+ }else if (event->button.button == 3) { //*******************************añadido menu contextual con boton derecho.
+
+ printf("Entra con boton derecho transicion\n");
+
+ gtk_menu_popup(GTK_MENU(menu_transicion),NULL,NULL,NULL,NULL,event->button.button,event->button.time);
+
+ item_menu_transicion = item;
+
+ return TRUE;
+ }
+ break;
+
+ case GDK_MOTION_NOTIFY:
+ //if (botonPulsado == "Mover"){
+
+ if (event->motion.state & GDK_BUTTON1_MASK) { // Si está pulsado el botón 1
+
+ botonPulsado = "Nada";
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(botonEstado),FALSE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(botonLinea),FALSE);
+
+ fleur = gdk_cursor_new (GDK_FLEUR);
+ gnome_canvas_item_grab (item,
+ GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK,
+ fleur,
+ event->button.time);
+ gdk_cursor_unref (fleur);
+
+ new_x = event->motion.x;
+ new_y = event->motion.y;
+
+ group_parent = GNOME_CANVAS_GROUP(item->parent);
+
+ list_items = group_parent->item_list;
+
+ box = (GnomeCanvasItem *) g_list_nth_data (list_items, g_list_length (list_items)-1);
+
+ g_object_get (G_OBJECT (box), "x1", &x1, NULL);
+ g_object_get (G_OBJECT (box), "y1", &y1, NULL);
+ g_object_get (G_OBJECT (box), "x2", &x2, NULL);
+ g_object_get (G_OBJECT (box), "y2", &y2, NULL);
+
+ cout << "Puntos item: " << x1 << "," << y1 << "," << x2 << "," << y2 <<endl;
+
+ gnome_canvas_item_set (box,
+ "x1", x1 + (new_x - x),
+ "y1", y1 + (new_y - y),
+ "x2", x2 + (new_x - x),
+ "y2", y2 + (new_y - y),
+ NULL);
+
+
+
+ posLinea = ListaTransiciones.begin();
+
+ while((posLinea->item != GNOME_CANVAS_ITEM(group_parent) )) //cogemos el padre (grupo) del item (box)
+ {
+ posLinea++;
+ }
+
+ origen = posLinea->origen;
+ destino = posLinea->destino;
+
+ /* Mover Item_Nombre Estado */
+ if ( posLinea->item_nombre != NULL )
+ gnome_canvas_item_move ((posLinea->item_nombre), new_x - x, new_y - y);
+
+ /* Actualizar Posición */
+ x = new_x;
+ y = new_y;
+
+
+ /* Eliminamos Lineas de la Transicion Previa */
+
+ while (g_list_length (list_items) > 1){
+
+ arrow = (GnomeCanvasItem *) g_list_nth_data (list_items, 0);
+ list_items=g_list_next(list_items);
+ gtk_object_destroy (GTK_OBJECT (arrow));
+
+ }
+
+
+ group = repintar_transicion (GNOME_CANVAS_GROUP (item->canvas->root), origen, destino, (x1+x2)/2, (y1+y2)/2);
+
+ gnome_canvas_item_reparent (box, group);
+
+ b = cambiar_item_transicion (GNOME_CANVAS_ITEM (group_parent), GNOME_CANVAS_ITEM (group));
+
+ cambiar_item_adyacentes (origen, GNOME_CANVAS_ITEM (group_parent), GNOME_CANVAS_ITEM (group));
+
+ cambiar_item_adyacentes (destino, GNOME_CANVAS_ITEM (group_parent), GNOME_CANVAS_ITEM (group));
+ }
+
+ //}
+ break;
+ case GDK_BUTTON_RELEASE:
+ gnome_canvas_item_ungrab (item, event->button.time);
+
+ if ((event->button.button == 1) & (botonPulsado == "Eliminar"))
+ {
+ group_parent = GNOME_CANVAS_GROUP(item->parent);
+
+ eliminar_nombre(GNOME_CANVAS_ITEM(group_parent));
+
+ t_eliminar_transicion_lista (GNOME_CANVAS_ITEM(group_parent));
+
+ gtk_object_destroy (GTK_OBJECT (group_parent));
+
+ }
+ else if ((event->button.button == 1) & (botonPulsado == "Mover"))
+ gnome_canvas_item_ungrab (item, event->button.time);
+ break;
+ case GDK_2BUTTON_PRESS:
+ if ((event->button.button == 1) & (botonPulsado == "Editar")){
+
+ /* Cambia el color del item */
+ change_item_color (item,0);
+
+ ventana = comprobar_ventana_abierta (item->parent, EDITAR);
+
+ if (ventana != NULL)
+ gtk_window_present (GTK_WINDOW(ventana));
+ else{
+ ventana = new_text_windows (item->parent ,(gchar*)"transicion");
+ add_ventana (ventana, item->parent, EDITAR);
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ return FALSE;
+}
+
+gint
+highlight_box_edit (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
+{
+ static double x, y; /* used to keep track of motion coordinates */
+ list<tTransicion>::iterator posLinea;
+ GnomeCanvasGroup *group_parent;
+ GtkWidget *ventana;
+
+ switch (event->type) {
+ case GDK_ENTER_NOTIFY:
+ gnome_canvas_item_set (item,
+ "fill_color", "red",
+ NULL);
+
+ break;
+
+ case GDK_LEAVE_NOTIFY:
+ if (!(event->crossing.state & GDK_BUTTON1_MASK))
+ gnome_canvas_item_set (item,
+ "fill_color_rgba", NULL,
+ NULL);
+ break;
+
+ case GDK_BUTTON_PRESS:
+
+ if ((event->button.button == 1) && (botonPulsado == "Nombrar")) {
+
+ change_item_color (item,0);
+
+ ventana = comprobar_ventana_abierta (item->parent, NOMBRAR);
+
+ if (ventana != NULL)
+ gtk_window_present (GTK_WINDOW(ventana));
+ else{
+ ventana = new_name_windows (item->parent);
+ add_ventana (ventana, item->parent, NOMBRAR);
+ }
+
+ }else if (event->button.button == 1) {
+ /* Recuerda la posición inicial */
+ x = event->button.x;
+ y = event->button.y;
+
+ }else if (event->button.button == 3) { //*******************************añadido menu contextual con boton derecho.
+
+ printf("Entra con boton derecho autotransicion\n");
+
+ gtk_menu_popup(GTK_MENU(menu_transicion),NULL,NULL,NULL,NULL,event->button.button,event->button.time);
+
+ item_menu_transicion = item;
+
+ return TRUE;
+ }
+ break;
+ case GDK_MOTION_NOTIFY:
+
+ break;
+ case GDK_BUTTON_RELEASE:
+ gnome_canvas_item_ungrab (item, event->button.time);
+
+ if ((event->button.button == 1) & (botonPulsado == "Eliminar"))
+ {
+ group_parent = GNOME_CANVAS_GROUP(item->parent);
+
+ eliminar_nombre(GNOME_CANVAS_ITEM(group_parent));
+
+ t_eliminar_transicion_lista (GNOME_CANVAS_ITEM(group_parent));
+
+ gtk_object_destroy (GTK_OBJECT (group_parent));
+
+ }
+
+ break;
+ case GDK_2BUTTON_PRESS:
+ if ((event->button.button == 1) & (botonPulsado == "Editar")){
+
+ /* Cambia el color del item */
+ change_item_color (item,0);
+
+ ventana = comprobar_ventana_abierta (item->parent, EDITAR);
+
+ if (ventana != NULL)
+ gtk_window_present (GTK_WINDOW(ventana));
+ else{
+ ventana = new_text_windows (item->parent ,(gchar*)"transicion");
+ add_ventana (ventana, item->parent, EDITAR);
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ return FALSE;
+}
+
+static gint
+box_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
+{
+
+ if ((event->type != GDK_MOTION_NOTIFY) || !(event->motion.state & GDK_BUTTON1_MASK))
+ return FALSE;
+
+ return FALSE;
+}
+
+void
+create_drag_box (GnomeCanvasGroup *group, char *box_name, double x1, double y1, GCallback callback)
+{
+ GnomeCanvasItem *box;
+
+ box = gnome_canvas_item_new (group,
+ gnome_canvas_rect_get_type (),
+ "fill_color", NULL,
+ "outline_color", "black",
+ "width_pixels", 0,
+ NULL);
+
+ gnome_canvas_item_set (box,
+ "x1", x1 - 3,
+ "y1", y1 - 3,
+ "x2", x1 + 3,
+ "y2", y1 + 3,
+ NULL);
+
+ g_signal_connect (box, "event",
+ callback,
+ NULL);
+
+ g_object_set_data (G_OBJECT (group), box_name, box);
+}
+
+/***** Pintar Transicion *****/
+/* modo indica si la transición existe y se repinta la transicion o no existe y se pinta una transición nueva */
+GnomeCanvasItem *
+pinta_transicion (GnomeCanvasItem *origen, GnomeCanvasItem *destino)
+{
+
+ GnomeCanvasPoints *pointsPoligono = gnome_canvas_points_new (2);
+ GnomeCanvasGroup *group;
+ GnomeCanvasItem *item1, *item2;
+
+
+ // Puntos del orgien
+ double I1x1;
+ double I1x2;
+ double I1y1;
+ double I1y2;
+
+// gnome_canvas_item_get_bounds (origen,&I1x1,&I1y1,&I1x2,&I1y2);
+ g_object_get (G_OBJECT (origen), "x1", &I1x1, NULL);
+ g_object_get (G_OBJECT (origen), "y1", &I1y1, NULL);
+ g_object_get (G_OBJECT (origen), "x2", &I1x2, NULL);
+ g_object_get (G_OBJECT (origen), "y2", &I1y2, NULL);
+
+ printf("origen, x1: %f, y1: %f, x2: %f, y2: %f \n", I1x1, I1y1, I1x2, I1y2);
+
+ // Resolver desequilibrio //
+
+ I1x1 += 1.5;
+ I1y1 += 1.5;
+ I1x2 -= 1.5;
+ I1y2 -= 1.5;
+
+ // Puntos del destino
+ double I2x1;
+ double I2x2;
+ double I2y1;
+ double I2y2;
+
+// gnome_canvas_item_get_bounds (destino,&I2x1,&I2y1,&I2x2,&I2y2);
+ g_object_get (G_OBJECT (destino), "x1", &I2x1, NULL);
+ g_object_get (G_OBJECT (destino), "y1", &I2y1, NULL);
+ g_object_get (G_OBJECT (destino), "x2", &I2x2, NULL);
+ g_object_get (G_OBJECT (destino), "y2", &I2y2, NULL);
+ printf("destino, x1: %f, y1: %f, x2: %f, y2: %f \n", I2x1, I2y1, I2x2, I2y2);
+
+ // Resolver desequilibrio //
+
+ I2x1 += 1.5;
+ I2y1 += 1.5;
+ I2x2 -= 1.5;
+ I2y2 -= 1.5;
+
+ //Punto medio circulo origen
+ double Xm1 = ((I1x2 + I1x1) / 2);
+ double Ym1 = ((I1y2 + I1y1) / 2);
+ punto pCirculoOrigen = crear_punto (Xm1, Ym1);
+
+ //Punto medio circulo destino
+ double Xm2 = ((I2x2 + I2x1) / 2);
+ double Ym2 = ((I2y2 + I2y1) / 2);
+ punto pCirculoDestino = crear_punto (Xm2, Ym2);
+
+ // Ecuacion Recta Ax + By + C =0
+ recta recta_origen_destino = crear_recta (pCirculoOrigen, pCirculoDestino);
+
+ // Ecuacion Recta Perpendicular que pasa por el punto medio del circulo origen
+ recta recta_perpendicular_circulo_origen = recta_perpendicular (recta_origen_destino, pCirculoOrigen);
+
+
+ // Ecuacion Recta Paralela1 d=(ax+by+c)/(a^2 + b^2)^1/2
+ recta recta_paralela1 = recta_paralela (recta_perpendicular_circulo_origen, pCirculoOrigen, -20);
+
+ // Intersecciones 1 entre recta perpendicular y paralela
+ double YI1;
+ double XI1;
+
+ punto pInterseccion = interseccion_rectas (recta_origen_destino, recta_paralela1);
+ punto_get_values (pInterseccion, &XI1, &YI1);
+
+ // Ecuacion Recta Perpendicular que pasa por el punto medio del circulo destino
+ recta recta_perpendicular_circulo_destino = recta_perpendicular (recta_origen_destino, pCirculoDestino);
+
+ // Ecuacion Recta Paralela2
+ recta_paralela1 = recta_paralela (recta_perpendicular_circulo_origen, pCirculoDestino, 20);
+
+ // Intersecciones 2
+ double YI2;
+ double XI2;
+ pInterseccion = interseccion_rectas (recta_origen_destino, recta_paralela1);
+ punto_get_values (pInterseccion, &XI2, &YI2);
+
+ GnomeCanvas *canvas = origen->canvas;
+
+ group = GNOME_CANVAS_GROUP (gnome_canvas_item_new (GNOME_CANVAS_GROUP(canvas->root),
+ gnome_canvas_group_get_type (),
+ "x", 0,
+ "y", 0,
+ NULL));
+ double pMedioX, pMedioY;
+ // Punto medio de la recta que uno los estados
+ punto pMedioRecta = punto_medio (pCirculoOrigen, pCirculoDestino);
+ punto_get_values (pMedioRecta, &pMedioX, &pMedioY);
+
+ pointsPoligono->coords[0] = XI1;
+ pointsPoligono->coords[1] = YI1;
+ pointsPoligono->coords[2] = pMedioX;
+ pointsPoligono->coords[3] = pMedioY;
+
+ item1 = gnome_canvas_item_new(group, gnome_canvas_line_get_type (),
+ "points", pointsPoligono,
+ "fill_color", "orange",
+ "width_units", 1.0,
+ NULL);
+
+ pointsPoligono->coords[0] = pMedioX;
+ pointsPoligono->coords[1] = pMedioY;
+ pointsPoligono->coords[2] = XI2;
+ pointsPoligono->coords[3] = YI2;
+
+
+ item2 = gnome_canvas_item_new(group, gnome_canvas_line_get_type (),
+ "points", pointsPoligono,
+ "fill_color", "orange",
+ "width_units", 1.0,
+ "last_arrowhead", TRUE,
+ "arrow_shape_a", 8.0,
+ "arrow_shape_b", 8.0,
+ "arrow_shape_c", 8.0,
+ NULL);
+
+ gnome_canvas_points_free (pointsPoligono);
+
+ printf("pMedioX: %f, pMedioY: %f \n", pMedioX, pMedioY);
+
+ create_drag_box (group, (char *)"box", pMedioX, pMedioY, G_CALLBACK (highlight_box));
+
+ return GNOME_CANVAS_ITEM(group);
+
+
+}
+
+
+/* Llamada para la señales de eventos de los items del canvas. Si el
+ * usuario arrastra el item con el botón 1, esté se moverá en consecuencia.
+ * Si el usuario hace doble click sobre el item, su color cambiará
+ * aleatoriamente. Si el usuario pulsa el botón 3 sobre un item, entoces
+ * el item será destruido.
+ * Cuando el puntero del ratón entra en un item, su ancho de linea se
+ * establece a 3 unidades.
+ * Cuando el puntero del ratón abandona un item, su ancho de linea se
+ * reestablece a 1 unidad.
+ */
+
+
+gint
+item_event (GnomeCanvasItem *item_group, GdkEvent *event, gpointer data)
+{
+ //static double x, y; /* used to keep track of motion coordinates */
+ //double new_x, new_y;
+
+ GdkCursor *fleur; /* Usado para cambiar el dibujo del cursor */
+
+ GnomeCanvasItem *item, *item2, *item_transicion;
+ GnomeCanvasGroup *group;
+ GtkWidget *ventana;
+
+ list<tTransicion>::iterator posLinea;
+ list<tNodo>::iterator posNodo;
+ list<tSubAut>::iterator posNodoSub;
+ list<GnomeCanvasItem *>::iterator posAdy;
+ list<GnomeCanvasItem *>::iterator posAux;
+
+ int idHijo_aux;
+
+ static gboolean dragging = FALSE;
+ double event_x = event->button.x;
+ double event_y = event->button.y;
+ static double previous_x, previous_y;
+
+ int idPath=0;
+
+ aux ln;
+
+ list <aux> ListaAux;
+
+ list<aux>::iterator posRec;
+
+ item = (GnomeCanvasItem *)g_list_nth_data (GNOME_CANVAS_GROUP(item_group)->item_list, 0);
+
+ switch (event->type) {
+
+ case GDK_2BUTTON_PRESS:
+ /*if ((event->button.button == 1) & (botonPulsado == "Editar")){
+
+ // Cambia el color del item
+ change_item_color (item,0);
+
+ ventana = comprobar_ventana_abierta (item, EDITAR);
+
+ if (ventana != NULL)
+ gtk_window_present (GTK_WINDOW(ventana));
+ else{
+ ventana = new_text_windows (item ,(gchar*)"estado");
+ add_ventana (ventana, item, EDITAR);
+ }
+
+ return TRUE;
+ }*/
+ printf("Doble click en item.\n");
+
+ posNodo = ListaElementos.begin();
+
+ while (posNodo->item != item and posNodo != ListaElementos.end())
+ {
+ posNodo++;
+ idPath++;
+ }
+
+ idHijo_aux = posNodo->idHijo;
+
+
+ posNodoSub = ListaSubAutomatas.begin();
+
+ while (posNodoSub->idSub != subautomata_mostrado and posNodoSub != ListaSubAutomatas.end())
+ posNodoSub++;
+
+ /* Gestion para navegacion en el tree view */
+
+ if (posNodoSub->idPadre == 0){
+ printf("idPath: %d \n", idPath);
+ gtk_tree_path_free (arbolPath);
+ arbolPath = gtk_tree_path_new_from_string ((const char*)int2string(idPath).c_str());
+ printf("Path con padre = 0 -- %s \n", gtk_tree_path_to_string (arbolPath));
+ }
+ else{
+ gtk_tree_path_append_index (arbolPath, idPath);
+ printf("Path con padre <> 0 -- %s \n", gtk_tree_path_to_string (arbolPath));
+ }
+
+ /* FIN Gestion para navegacion en el tree view */
+
+ if (idHijo_aux != 0){
+
+ gnome_canvas_item_set (item,
+ "fill_color", "green", // 0x00ff66ff,
+ NULL);
+ gnome_canvas_update_now (GNOME_CANVAS(canvas));
+
+ posNodoSub = ListaSubAutomatas.begin();
+
+ while (posNodoSub->idSub != subautomata_mostrado and posNodoSub != ListaSubAutomatas.end())
+ posNodoSub++;
+
+ //Guardamos el nivel actual
+ posNodoSub->ListaElementosSub = ListaElementos;
+ posNodoSub->ListaTransicionesSub = ListaTransiciones;
+ posNodoSub->tiempoIteracionSub = tiempoIteracion;
+ posNodoSub->variablesSub = variables;
+ posNodoSub->funcionesSub = funciones;
+ posNodoSub->impSub = imp;
+
+ ocultar_subautomata(subautomata_mostrado);
+
+ posNodoSub = ListaSubAutomatas.begin();
+
+ while (posNodoSub->idSub != idHijo_aux and posNodoSub != ListaSubAutomatas.end())
+ posNodoSub++;
+
+ mostrar_subautomata(posNodo->idHijo);
+
+ ListaElementos.clear();
+ ListaTransiciones.clear();
+
+ //Cargamos el nivel que vamos a mostrar
+ ListaElementos = posNodoSub->ListaElementosSub;
+ ListaTransiciones = posNodoSub->ListaTransicionesSub;
+ tiempoIteracion = posNodoSub->tiempoIteracionSub;
+ variables = posNodoSub->variablesSub;
+ funciones = posNodoSub->funcionesSub;
+ imp = posNodoSub->impSub;
+
+ }
+ else{
+
+ posNodo->idHijo = idSubGlobal;
+ printf("id del hijo creado : %d \n", posNodo->idHijo);
+
+ gnome_canvas_item_set (item,
+ "fill_color", "green", // 0x00ff66ff,
+ NULL);
+ gnome_canvas_update_now (GNOME_CANVAS(canvas));
+
+ posNodoSub = ListaSubAutomatas.begin();
+
+ while (posNodoSub->idSub != subautomata_mostrado and posNodoSub != ListaSubAutomatas.end())
+ posNodoSub++;
+
+ //Guardamos el nivel actual
+ posNodoSub->ListaElementosSub = ListaElementos;
+ posNodoSub->ListaTransicionesSub = ListaTransiciones;
+ posNodoSub->tiempoIteracionSub = tiempoIteracion;
+ posNodoSub->variablesSub = variables;
+ posNodoSub->funcionesSub = funciones;
+ posNodoSub->impSub = imp;
+ ocultar_subautomata(subautomata_mostrado);
+
+ ListaElementos.clear();
+ ListaTransiciones.clear();
+
+ tSubAut sub_aux;
+
+ sub_aux.ListaElementosSub = ListaElementos;
+ sub_aux.ListaTransicionesSub = ListaTransiciones;
+ sub_aux.tiempoIteracionSub = 100;
+ sub_aux.variablesSub = "";
+ sub_aux.funcionesSub = "";
+ sub_aux.impSub.laser= FALSE;
+ sub_aux.impSub.motor= FALSE;
+ sub_aux.impSub.radar= FALSE;
+ sub_aux.impSub.encoders= FALSE;
+ sub_aux.impSub.lat_lon= FALSE;
+ sub_aux.impSub.camara= FALSE;
+ sub_aux.impSub.ptencoders= FALSE;
+ sub_aux.idSub = idSubGlobal;
+ sub_aux.idPadre = subautomata_mostrado;
+
+ ListaSubAutomatas.push_back(sub_aux);
+
+ posNodoSub = ListaSubAutomatas.begin();
+
+ while (posNodoSub->idSub != idSubGlobal and posNodoSub != ListaSubAutomatas.end())
+ posNodoSub++;
+
+ //Cargamos el nivel que vamos a mostrar
+ ListaElementos = posNodoSub->ListaElementosSub;
+ ListaTransiciones = posNodoSub->ListaTransicionesSub;
+ tiempoIteracion = posNodoSub->tiempoIteracionSub;
+ variables = posNodoSub->variablesSub;
+ funciones = posNodoSub->funcionesSub;
+ imp = posNodoSub->impSub;
+ //mostrar_subautomata(idSubGlobal);
+ subautomata_mostrado = idSubGlobal;
+
+ idSubGlobal++;
+ }
+
+ actualizar_tree_view();
+ gtk_tree_view_expand_to_path(GTK_TREE_VIEW(tree_view), arbolPath);
+
+ break;
+
+ case GDK_BUTTON_RELEASE:
+
+ //if ((event->button.button == 1) && dragging /*&& (botonPulsado == "Mover")*/)
+ gnome_canvas_item_ungrab (item, event->button.time);
+ dragging = FALSE;
+
+ break;
+
+ case GDK_BUTTON_PRESS:
+
+ dragging = TRUE;
+ previous_x = event_x;
+ previous_y = event_y;
+
+ if ((event->button.button == 1) && (botonPulsado == "EstadoInicial")) {
+
+ marcar_estado_inicial (item);
+ }
+ /*Pintamos Linea*/
+ else if ((event->button.button == 1) && (botonPulsado == "Linea")) {
+
+ if (item_transicion_saved == NULL){
+
+ item_transicion_saved=item; //Si es en el primer item que pulsamos lo guardamos
+
+ break;
+ }
+ else if(item != item_transicion_saved) //Si es en el segundo item que pulsamos y es distinto que el primero
+ {
+ /* Cogemos los dos item pulsados, congemos sus puntos (coordenadas)
+ miranos que puntos tienen menor distancia.
+ pintamos una recta con esos puntos
+ */
+
+ item2 = pinta_transicion (item_transicion_saved, item);
+
+ }else if(item == item_transicion_saved){
+
+ item2 = pinta_autotransicion (item);
+
+ }
+ gnome_canvas_update_now (GNOME_CANVAS(canvas));
+
+ g_object_set_data (G_OBJECT (item2), "id", (void*)(int)item2);
+
+ // Guardamos que elementos conecta la linea
+ tTransicion l;
+ l.item = item2;
+ l.origen = item_transicion_saved;
+ l.destino = item;
+ l.codigo = codigo;
+ l.tiempo = tiempo;
+ l.item_nombre = NULL;
+ l.nombre = "";
+ ListaTransiciones.push_back(l);
+
+
+ // Guardamos en los elementos, las lineas que tienen conectadas.
+ list<tNodo>::iterator pos;
+
+ pos = ListaElementos.begin();
+
+ while(pos->item != item_transicion_saved)
+ pos++;
+ pos->listaAdyacentes.push_back(item2);
+
+ if(item != item_transicion_saved){
+ pos = ListaElementos.begin();
+
+ while(pos->item != item)
+ pos++;
+
+ pos->listaAdyacentes.push_back(item2);
+ }
+
+ item_transicion_saved = NULL;
+
+ }
+ else if ((event->button.button == 1) && (botonPulsado == "Nombrar")) {
+
+
+ change_item_color (item,0);
+
+ ventana = comprobar_ventana_abierta (item, NOMBRAR);
+
+ if (ventana != NULL)
+ gtk_window_present (GTK_WINDOW(ventana));
+ else{
+ ventana = new_name_windows (item);
+ add_ventana (ventana, item, NOMBRAR);
+ }
+
+ return TRUE;
+
+ }else if ((event->button.button == 1) && (botonPulsado == "Copiar")) {
+
+
+ cout << "Copiando: " << endl;
+
+ double x1,x2,y1,y2;
+
+ g_object_get (G_OBJECT (item), "x1", &x1, NULL);
+ g_object_get (G_OBJECT (item), "y1", &y1, NULL);
+ g_object_get (G_OBJECT (item), "x2", &x2, NULL);
+ g_object_get (G_OBJECT (item), "y2", &y2, NULL);
+
+ group = GNOME_CANVAS_GROUP (gnome_canvas_item_new (root,
+ gnome_canvas_group_get_type (),
+ "x", 0,
+ "y", 0,
+ NULL));
+
+ item2 = gnome_canvas_item_new(group,
+ gnome_canvas_ellipse_get_type(),
+ "x1", x1+50,
+ "x2", x2+50,
+ "y1", y1,
+ "y2", y2,
+ "fill_color_rgba", 0x00ffffff,
+ "outline_color", "black",
+ "width_units", 1.0,
+ NULL);
+
+ copiar_nodo (item, item2);
+
+ g_signal_connect (group, "event",
+ (GtkSignalFunc) item_event,
+ NULL);
+
+
+ return TRUE;
+
+ } else if ((event->button.button == 3) & (botonPulsado == "Eliminar")){
+
+ /* Destruye el item */
+
+ // Eliminar Transiciones
+ posNodo = ListaElementos.begin();
+
+ while((posNodo->item != item) & ( posNodo != ListaElementos.end() ))
+ posNodo++;
+
+
+ if (posNodo != ListaElementos.end()) {
+
+ posAdy = posNodo->listaAdyacentes.begin();
+
+ while(posAdy != (posNodo->listaAdyacentes.end()))
+ {
+
+ posAux = posAdy;
+
+ posAdy++;
+
+ eliminar_nombre(*posAux);
+ t_eliminar_transicion_lista (*posAux);
+
+ gtk_object_destroy (GTK_OBJECT (*posAux));
+
+ }
+
+ ListaElementos.erase(posNodo);
+
+ cout << (int)*(posNodo->listaAdyacentes.begin()) << endl;
+
+ gtk_object_destroy (GTK_OBJECT (item_group));
+ }
+
+
+
+ cout << "Eliminado: " << endl;
+ return TRUE;
+ }
+
+ else if ((event->button.button == 1) & (botonPulsado == "Editar")){//********************añadido evento editar con click simple
+
+ // Cambia el color del item
+ change_item_color (item,0);
+
+ ventana = comprobar_ventana_abierta (item, EDITAR);
+
+ if (ventana != NULL)
+ gtk_window_present (GTK_WINDOW(ventana));
+ else{
+ ventana = new_text_windows (item ,(gchar*)"estado");
+ add_ventana (ventana, item, EDITAR);
+ }
+
+ return TRUE;
+ }
+
+ else if (event->button.button == 3) { //*******************************añadido menu contextual con boton derecho.
+
+ printf("Entra con boton derecho estado\n");
+
+ gtk_menu_popup(GTK_MENU(menu_estado),NULL,NULL,NULL,NULL,event->button.button,event->button.time);
+
+ item_menu_estado = item;
+ item_group_menu_estado = item_group;
+
+ return TRUE;
+ }
+ break;
+
+
+ case GDK_MOTION_NOTIFY:
+
+ //if (botonPulsado == "Mover"){
+ if (estado_nombrado){
+
+ actualizar_tree_view();
+
+ if (subautomata_mostrado != 1)
+ gtk_tree_view_expand_to_path(GTK_TREE_VIEW(tree_view), arbolPath);
+
+ estado_nombrado=FALSE;
+ }
+
+ if ((event->motion.state & GDK_BUTTON1_MASK) && dragging) { // Si está pulsado el botón 1
+ //Para eliminar el efecto de cualquier posible boton puslado
+
+ botonPulsado = "Nada";
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(botonEstado),FALSE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(botonLinea),FALSE);
+
+ /* cambiar la imagen del cursor*/
+ fleur = gdk_cursor_new (GDK_FLEUR);
+ /*gnome_canvas_item_grab (item,
+ GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK,
+ fleur,
+ event->button.time);*/
+ gnome_canvas_item_grab(item,GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK, fleur, event->button.time);
+ gdk_cursor_unref (fleur);
+
+
+
+ /*gnome_canvas_item_move(item, event_x - previous_x,
+ event_y - previous_y);*/
+
+ /* Obten la nueva posición y muevete por la
+ * diferencia */
+
+ /*new_x = event->motion.x;
+ new_y = event->motion.y;*/
+
+ double x1,x2,y1,y2;
+ g_object_get (G_OBJECT (item), "x1", &x1, NULL);
+ g_object_get (G_OBJECT (item), "y1", &y1, NULL);
+ g_object_get (G_OBJECT (item), "x2", &x2, NULL);
+ g_object_get (G_OBJECT (item), "y2", &y2, NULL);
+
+ /*cout << "Puntos item: " << x1 << "," << y1 << "," << x2 << "," << y2 <<endl;
+
+ gnome_canvas_item_set (item,
+ "x1", x1 + (new_x - x),
+ "y1", y1 + (new_y - y),
+ "x2", x2 + (new_x - x),
+ "y2", y2 + (new_y - y),
+ NULL);*/
+
+ gnome_canvas_item_set (item,
+ "x1", x1 + (event_x - previous_x),
+ "y1", y1 + (event_y - previous_y),
+ "x2", x2 + (event_x- previous_x),
+ "y2", y2 + (event_y- previous_y),
+ NULL);
+
+
+ /* Mover Item_Nombre Estado */
+ posNodo = ListaElementos.begin();
+
+ while((posNodo->item != item))
+ {
+ posNodo++;
+ }
+
+ if ( posNodo->item_nombre != NULL )
+ gnome_canvas_item_move ((posNodo->item_nombre), event_x - previous_x, event_y - previous_y);
+
+ if ( posNodo->estado_inicial != NULL )
+ gnome_canvas_item_move ((posNodo->estado_inicial), event_x - previous_x, event_y - previous_y);
+
+
+ /* Repintar Transiciones */
+ posAdy = posNodo->listaAdyacentes.begin();
+
+
+ while(posAdy != (posNodo->listaAdyacentes.end()))
+ {
+
+ posLinea = ListaTransiciones.begin();
+
+ while(posLinea->item != (*posAdy))
+ posLinea++;
+
+
+ posAdy++;
+
+ GnomeCanvasItem * origen;
+
+ GnomeCanvasItem * destino;
+
+ if ( posLinea->origen == posLinea->destino ){
+ gnome_canvas_item_move ((posLinea->item), event_x - previous_x, event_y - previous_y);
+ if (posLinea->nombre.compare("") != 0)
+ gnome_canvas_item_move ((posLinea->item_nombre), event_x - previous_x, event_y - previous_y);
+ }
+ else if ( posLinea->origen == item)
+ {
+
+ origen = item;
+ destino = posLinea->destino;
+
+ item_transicion = (GnomeCanvasItem *) repintar_transicion_nodo (root, posLinea->item, item, (char *)"origen");
+
+ }
+ else
+ {
+ origen = posLinea->origen;
+ destino = item;
+ item_transicion = (GnomeCanvasItem *) repintar_transicion_nodo (root, posLinea->item, item, (char *)"destino");
+ }
+
+ }
+
+ /* Actualizar Posición */
+ //x = new_x;
+ //y = new_y;
+
+ previous_x = event_x;
+ previous_y = event_y;
+
+ return TRUE;
+ }
+
+ //}
+ break;
+
+ case GDK_ENTER_NOTIFY:
+ /* Establece la linea ancha */
+ gnome_canvas_item_set (item,
+ "width_units", 3.0,
+ NULL);
+ return TRUE;
+
+ case GDK_LEAVE_NOTIFY:
+ /* Establece la linea estrecha */
+ gnome_canvas_item_set (item,
+ "width_units", 1.0,
+ NULL);
+ return TRUE;
+
+ default:
+ break;
+ }
+
+ return FALSE;
+}
+
+
+void on_menu_estado_nombrar(){
+
+ GtkWidget *ventana;
+
+ change_item_color (item_menu_estado,0);
+
+ ventana = comprobar_ventana_abierta (item_menu_estado, NOMBRAR);
+
+ if (ventana != NULL)
+ {
+ gtk_window_present (GTK_WINDOW(ventana));
+ }
+ else{
+ ventana = new_name_windows (item_menu_estado);
+ add_ventana (ventana, item_menu_estado, NOMBRAR);
+ }
+
+ estado_nombrado = TRUE;
+
+}
+
+void
+on_menu_estado_editar(){
+
+ GtkWidget *ventana;
+
+ change_item_color (item_menu_estado,0);
+
+ ventana = comprobar_ventana_abierta (item_menu_estado, EDITAR);
+
+ if (ventana != NULL)
+ gtk_window_present (GTK_WINDOW(ventana));
+ else{
+ ventana = new_text_windows (item_menu_estado ,(gchar*)"estado");
+ add_ventana (ventana, item_menu_estado, EDITAR);
+ }
+
+}
+
+void
+on_menu_estado_marcar_inicial(){
+
+ marcar_estado_inicial (item_menu_estado);
+
+}
+
+void
+on_menu_estado_copiar(){
+
+ list<tNodo>::iterator posNodo;
+
+ posNodo = ListaElementos.begin();
+
+ while((posNodo->item != item_menu_estado) & ( posNodo != ListaElementos.end() ))
+ posNodo++;
+
+ estado_clipboard = TRUE;
+ estado_clipboard_codigo = posNodo->codigo;
+ estado_clipboard_idHijo = posNodo->idHijo;
+
+}
+
+void
+on_menu_estado_eliminar(){
+
+ list<tNodo>::iterator posNodo;
+ list<GnomeCanvasItem *>::iterator posAdy;
+ list<GnomeCanvasItem *>::iterator posAux;
+
+
+ /* Destruye el item */
+
+ // Eliminar Transiciones
+ posNodo = ListaElementos.begin();
+
+ while((posNodo->item != item_menu_estado) & ( posNodo != ListaElementos.end() ))
+ posNodo++;
+
+
+ if (posNodo != ListaElementos.end()) {
+
+ posAdy = posNodo->listaAdyacentes.begin();
+
+ while(posAdy != (posNodo->listaAdyacentes.end()))
+ {
+
+ posAux = posAdy;
+
+ posAdy++;
+
+ eliminar_nombre(*posAux);
+ t_eliminar_transicion_lista (*posAux);
+
+ gtk_object_destroy (GTK_OBJECT (*posAux));
+
+ }
+
+ if (posNodo->idHijo != 0){
+ borrar_subautomata_recursivo(posNodo->idHijo);
+ }
+
+ ListaElementos.erase(posNodo);
+
+ cout << (int)*(posNodo->listaAdyacentes.begin()) << endl;
+
+ gtk_object_destroy (GTK_OBJECT (item_group_menu_estado));
+ }
+
+
+
+ cout << "Eliminado: " << endl;
+
+ actualizar_tree_view();
+
+ gtk_tree_view_expand_to_path(GTK_TREE_VIEW(tree_view), arbolPath);
+
+}
+
+
+void
+on_menu_transicion_nombrar(){
+
+ GtkWidget *ventana;
+
+ change_item_color (item_menu_transicion,0);
+
+ ventana = comprobar_ventana_abierta (item_menu_transicion->parent, NOMBRAR);
+
+ if (ventana != NULL)
+ gtk_window_present (GTK_WINDOW(ventana));
+ else{
+ ventana = new_name_windows (item_menu_transicion->parent);
+ add_ventana (ventana, item_menu_transicion->parent, NOMBRAR);
+ }
+
+}
+
+
+void
+on_menu_transicion_editar(){
+
+ GtkWidget *ventana;
+
+ change_item_color (item_menu_transicion,0);
+
+ ventana = comprobar_ventana_abierta (item_menu_transicion->parent, EDITAR);
+
+ if (ventana != NULL)
+ gtk_window_present (GTK_WINDOW(ventana));
+ else{
+ ventana = new_text_windows (item_menu_transicion->parent ,(gchar*)"transicion");
+ add_ventana (ventana, item_menu_transicion->parent, EDITAR);
+ }
+
+}
+
+
+void
+on_menu_transicion_eliminar(){
+
+ GnomeCanvasGroup *group_parent;
+
+ group_parent = GNOME_CANVAS_GROUP(item_menu_transicion->parent);
+
+ eliminar_nombre(GNOME_CANVAS_ITEM(group_parent));
+
+ t_eliminar_transicion_lista (GNOME_CANVAS_ITEM(group_parent));
+
+ gtk_object_destroy (GTK_OBJECT (group_parent));
+
+}
+
+
+void
+reemplazar_nodo_subautomata(int idSub, GnomeCanvasItem *item_buscar, GnomeCanvasItem* item_nuevo){
+
+ list<tSubAut>::iterator posNodoSub;
+ list<tNodo>::iterator posNodo;
+ list<tTransicion>::iterator posTrans;
+
+
+ posNodoSub = ListaSubAutomatas.begin();
+
+ //Nos posicionamos en el subautomata en el que queremos hacer el cambio
+ while(posNodoSub->idSub != idSub)
+ {
+ posNodoSub++;
+ }
+
+ posNodo = posNodoSub->ListaElementosSub.begin();
+
+ while(posNodo!= posNodoSub->ListaElementosSub.end())
+ {
+ if(posNodo->item == item_buscar){
+ posNodo->item = item_nuevo;
+ }
+
+ posNodo++;
+
+ }
+
+ posTrans = posNodoSub->ListaTransicionesSub.begin();
+
+ while(posTrans!= posNodoSub->ListaTransicionesSub.end())
+ {
+ if(posTrans->origen == item_buscar){
+ posTrans->origen = item_nuevo;
+ }
+
+ if(posTrans->destino == item_buscar){
+ posTrans->destino = item_nuevo;
+ }
+
+ posTrans++;
+ }
+}
+
+
+void
+reemplazar_nombre_nodo_subautomata(int idSub, GnomeCanvasItem* nombre_buscar, GnomeCanvasItem* nombre_nuevo){
+
+ list<tSubAut>::iterator posNodoSub;
+ list<tNodo>::iterator posNodo;
+
+ posNodoSub = ListaSubAutomatas.begin();
+
+ //Nos posicionamos en el subautomata en el que queremos hacer el cambio
+ while(posNodoSub->idSub != idSub)
+ {
+ posNodoSub++;
+ }
+
+ posNodo = posNodoSub->ListaElementosSub.begin();
+
+ while(posNodo!= posNodoSub->ListaElementosSub.end())
+ {
+ if(posNodo->item_nombre == nombre_buscar){
+ posNodo->item_nombre = nombre_nuevo;
+ }
+ posNodo++;
+ }
+}
+
+
+void
+reemplazar_estado_inicial_subautomata(int idSub, GnomeCanvasItem* inicial_buscar, GnomeCanvasItem* inicial_nuevo){
+
+ list<tSubAut>::iterator posNodoSub;
+ list<tNodo>::iterator posNodo;
+
+ posNodoSub = ListaSubAutomatas.begin();
+
+ //Nos posicionamos en el subautomata en el que queremos hacer el cambio
+ while(posNodoSub->idSub != idSub)
+ {
+ posNodoSub++;
+ }
+
+ posNodo = posNodoSub->ListaElementosSub.begin();
+
+ while(posNodo!= posNodoSub->ListaElementosSub.end())
+ {
+ if(posNodo->estado_inicial == inicial_buscar){
+ posNodo->estado_inicial = inicial_nuevo;
+ }
+ posNodo++;
+ }
+}
+
+
+void
+reemplazar_transicion_subautomata(int idSub, GnomeCanvasItem* trans_buscar, GnomeCanvasItem* trans_nueva){
+
+ list<tSubAut>::iterator posNodoSub;
+ list<tNodo>::iterator posNodo;
+ list<tTransicion>::iterator posTrans;
+ list<GnomeCanvasItem*>::iterator posAdy;
+
+ posNodoSub = ListaSubAutomatas.begin();
+
+ //Nos posicionamos en el subautomata en el que queremos hacer el cambio
+ while(posNodoSub->idSub != idSub)
+ {
+ posNodoSub++;
+ }
+
+ //Sustituimos la transicion en las listas de adyacentes de los estados
+ posNodo = posNodoSub->ListaElementosSub.begin();
+
+ while(posNodo != posNodoSub->ListaElementosSub.end()){
+
+ posAdy = posNodo->listaAdyacentes.begin();
+ while(posAdy != posNodo->listaAdyacentes.end()){
+
+ if(*posAdy == trans_buscar){
+ *posAdy = trans_nueva;
+ }
+ posAdy++;
+ }
+
+ posNodo++;
+ }
+
+ //Sustituimos la transicion en la lista de transiciones del subautomata
+ posTrans = posNodoSub->ListaTransicionesSub.begin();
+
+ while(posTrans != posNodoSub->ListaTransicionesSub.end()){
+
+ if(posTrans->item == trans_buscar){
+ posTrans->item = trans_nueva;
+ }
+ posTrans++;
+ }
+}
+
+
+void
+reemplazar_nombre_trans_subautomata(int idSub, GnomeCanvasItem* nombre_buscar, GnomeCanvasItem* nombre_nuevo){
+
+ list<tSubAut>::iterator posNodoSub;
+ list<tTransicion>::iterator posTrans;
+
+ posNodoSub = ListaSubAutomatas.begin();
+
+ //Nos posicionamos en el subautomata en el que queremos hacer el cambio
+ while(posNodoSub->idSub != idSub)
+ {
+ posNodoSub++;
+ }
+
+ posTrans = posNodoSub->ListaTransicionesSub.begin();
+
+ while(posTrans != posNodoSub->ListaTransicionesSub.end()){
+
+ if(posTrans->item_nombre == nombre_buscar){
+ posTrans->item_nombre = nombre_nuevo;
+ }
+
+ posTrans++;
+
+ }
+
+}
+
+
+void pegado_recursivo(int sub_a_copiar, int sub_padre){
+
+ tSubAut nuevo_sub;
+ list<tSubAut>::iterator posNodoSub;
+ list<tNodo>::iterator posNodo;
+ list<tTransicion>::iterator posTrans;
+
+ GnomeCanvasItem *item, *item_nombre, *inicial;
+ GnomeCanvasGroup *group;
+
+ //Para obtener el box de una transicion y poder copiar el nombre en caso de haberlo
+ GnomeCanvasItem *box;
+ GList * list_items;
+
+ //estas variables son necesarias si tenemos que llamar a pegado_recursivo mas veces
+ int padre = 0;
+ int hijo = 0;
+
+ double x1, y1, x2, y2;
+
+ posNodoSub = ListaSubAutomatas.begin();
+
+ while(posNodoSub->idSub != sub_a_copiar)
+ {
+ posNodoSub++;
+ }
+
+ //Asi copiamos las listas
+ list <tNodo> listE (posNodoSub->ListaElementosSub);
+ list <tTransicion> listT( posNodoSub->ListaTransicionesSub);
+
+ nuevo_sub.ListaElementosSub = listE;
+ nuevo_sub.ListaTransicionesSub = listT;
+ nuevo_sub.tiempoIteracionSub = posNodoSub->tiempoIteracionSub;
+ nuevo_sub.variablesSub = posNodoSub->variablesSub;
+ nuevo_sub.funcionesSub = posNodoSub->funcionesSub;
+ nuevo_sub.impSub = posNodoSub->impSub;
+ nuevo_sub.idSub = idSubGlobal;
+ nuevo_sub.idPadre = sub_padre;
+
+ ListaSubAutomatas.push_back(nuevo_sub);
+
+ posNodoSub = ListaSubAutomatas.begin();
+
+ while(posNodoSub->idSub != idSubGlobal)
+ {
+ posNodoSub++;
+ }
+
+ posNodo = posNodoSub->ListaElementosSub.begin();
+
+ //Recorremos la lista de elementos para duplicar todos los nodos y asi tener la copia
+ //hacemos lo mismo con el item de estado inicial y con el item del nombre si fuera necesario
+ while(posNodo != posNodoSub->ListaElementosSub.end())
+ {
+ get_bounds (posNodo->item, &x1, &y1, &x2, &y2);
+
+ group = GNOME_CANVAS_GROUP (gnome_canvas_item_new (root,
+ gnome_canvas_group_get_type (),
+ "x", 0,
+ "y", 0,
+ NULL));
+
+ if (posNodo->idHijo == 0){
+
+ item = gnome_canvas_item_new(group,
+ gnome_canvas_ellipse_get_type(),
+ "x1", x1,
+ "y1", y1,
+ "x2", x2,
+ "y2", y2,
+ "fill_color_rgba", 0x00ffffff,
+ "outline_color", "black",
+ "width_units", 1.0,
+ NULL);
+ }else{
+
+ item = gnome_canvas_item_new(group,
+ gnome_canvas_ellipse_get_type(),
+ "x1", x1,
+ "y1", y1,
+ "x2", x2,
+ "y2", y2,
+ "fill_color_rgba", 0x00ff66ff,
+ "outline_color", "black",
+ "width_units", 1.0,
+ NULL);
+ }
+
+ /*Añadimos control (señal) al item creado*/
+ g_signal_connect (group, "event",
+ (GtkSignalFunc) item_event,
+ NULL);
+
+ //Lo ocultamos
+ gnome_canvas_item_hide(item);
+
+ //Sustituimos el item copiado por el recien creado en todas las referencias que haya
+ //dentro de su subautomata
+ reemplazar_nodo_subautomata(posNodoSub->idSub, posNodo->item, item);
+
+ //Repetimos el proceso para el item_nombre y para el estado_inicial
+ if (posNodo->item_nombre != NULL){
+ item_nombre = gnome_canvas_item_new (group,
+ gnome_canvas_text_get_type (),
+ "text", posNodo->nombre.c_str(),
+ "x", (x2+x1)/2,
+ "y", (y2+y1)/2,
+ "font", "Sans 28",
+ "anchor", GTK_ANCHOR_CENTER,
+ "fill_color", "black",
+ NULL);
+
+ gnome_canvas_item_raise_to_top (item_nombre);
+
+ gnome_canvas_item_hide(item_nombre);
+
+ reemplazar_nombre_nodo_subautomata(posNodoSub->idSub, posNodo->item_nombre, item_nombre);
+ }
+
+ if (posNodo->estado_inicial != NULL){
+ inicial = gnome_canvas_item_new(group,
+ gnome_canvas_ellipse_get_type(),
+ "x1", x1 + 5,
+ "y1", y1 + 5,
+ "x2", x2 - 5,
+ "y2", y2 - 5,
+ "fill_color_rgba", NULL,
+ "outline_color", "black",
+ "width_units", 1.0,
+ NULL);
+
+ gnome_canvas_item_hide(inicial);
+
+ reemplazar_estado_inicial_subautomata(posNodoSub->idSub, posNodo->estado_inicial, inicial);
+ }
+
+ posNodo++;
+ }//Terminamos de recorrer la lista de elementos
+
+
+ posNodoSub = ListaSubAutomatas.begin();
+
+ while(posNodoSub->idSub != idSubGlobal)
+ {
+ posNodoSub++;
+ }
+
+ //Ahora tenemos que hacer un proceso de sustitucion equivalente para las transiciones
+ posTrans = posNodoSub->ListaTransicionesSub.begin();
+
+ while(posTrans != posNodoSub->ListaTransicionesSub.end())
+ {
+ if(posTrans->origen == posTrans->destino){
+
+ item = pinta_autotransicion(posTrans->destino);
+ //La ocultamos
+ gnome_canvas_item_hide(item);
+
+ }else{
+
+ item = pinta_transicion(posTrans->origen,posTrans->destino);
+ //La ocultamos
+ gnome_canvas_item_hide(item);
+
+ }
+
+ reemplazar_transicion_subautomata(posNodoSub->idSub, posTrans->item, item);
+
+ //Repetimos el proceso para el item_nombre
+ if (posTrans->item_nombre != NULL){
+
+ list_items = GNOME_CANVAS_GROUP(item)->item_list;
+ box = (GnomeCanvasItem *) g_list_nth_data (list_items, g_list_length (list_items)-1);
+
+ get_bounds (box, &x1, &y1, &x2, &y2);
+
+ item_nombre = gnome_canvas_item_new (root,
+ gnome_canvas_text_get_type (),
+ "text", posTrans->nombre.c_str(),
+ "x", (x2+x1)/2,
+ "y", (y2+y1)/2 + 5 ,
+ "font", "Sans 28",
+ "anchor", GTK_ANCHOR_N,
+ "fill_color", "black",
+ NULL);
+
+ gnome_canvas_item_raise_to_top (item_nombre);
+ gnome_canvas_item_hide(item_nombre);
+
+ reemplazar_nombre_trans_subautomata(posNodoSub->idSub, posTrans->item_nombre, item_nombre);
+ }
+
+ posTrans++;
+ }//Terminamos de recorrer la lista de transiciones
+
+ //Terminadas las gestiones en el nivel hay que comprobar si hay más subautómatas hijos que se
+ //desplieguen a partir de este nivel
+ posNodo = posNodoSub->ListaElementosSub.begin();
+
+ while(posNodo != posNodoSub->ListaElementosSub.end()){
+
+ if (posNodo->idHijo != 0){
+
+ padre = idSubGlobal;
+
+ hijo = posNodo->idHijo;
+
+ idSubGlobal++;
+
+ printf("Entra por pegado recursivo, idsubglobal: %d\n",idSubGlobal);
+
+ //El hijo es este porque ahora llamaremos al proceso de pegado recursivo que creará un
+ //subautomata con esta ID
+ posNodo->idHijo = idSubGlobal;
+
+ pegado_recursivo(hijo, padre);
+
+ //posNodo->idHijo = padre;
+ printf("Entra por pegado recursivo, posNodo->idHijo: %d\n",posNodo->idHijo);
+
+ }
+
+ posNodo++;
+ }
+
+ //Aumentamos la variable idSubGlobal por si no se desplegaron hijos en la llamada
+ //para que quede con un valor válido
+ idSubGlobal++;
+
+ printf("termina un pegado recursivo, idsubglobal: %d\n",idSubGlobal);
+
+}
+
+void
+on_menu_pegar(){
+
+ GnomeCanvasItem *item;
+ GnomeCanvasGroup *group;
+
+ tNodo reg;
+
+ list<tSubAut>::iterator posSub; //Añadido para poder iterar en la lista de subautomatas y actulizar el treeview con cada nuevo estado
+
+ points = gnome_canvas_points_new(2); /* 2 puntos */
+
+
+ printf("menu pegar\n");
+ printf("codigo: %s \n", estado_clipboard_codigo.c_str());
+ printf("idHijo: %d \n", estado_clipboard_idHijo);
+
+
+ points->coords[0] = origenX;
+ points->coords[1] = origenY;
+ points->coords[2] = origenX;
+ points->coords[3] = origenY;
+
+ printf("Click %d, %d\n", origenX, origenY);
+ //printf("Pintamos Nodo \n");
+
+ if (estado_clipboard)
+ {
+
+ printf("Antes de group\n");
+ group = GNOME_CANVAS_GROUP (gnome_canvas_item_new (root,
+ gnome_canvas_group_get_type (),
+ "x", 0,
+ "y", 0,
+ NULL));
+ printf("despues de group\n");
+ if (estado_clipboard_idHijo == 0){
+
+ printf("entra por el if\n");
+
+ item = gnome_canvas_item_new(group,
+ gnome_canvas_ellipse_get_type(),
+ "x1", (double) origenX-20,
+ "y1", (double) origenY-20,
+ "x2", (double) (origenX + 20),
+ "y2", (double) (origenY + 20),
+ "fill_color_rgba", 0x00ffffff,
+ "outline_color", "black",
+ "width_units", 1.0,
+ NULL);
+ printf("despues de crear item\n");
+
+ reg.idHijo = estado_clipboard_idHijo;
+ printf("despues de reg.idHijo\n");
+
+ }else{
+
+ printf("entra por el else\n");
+
+ item = gnome_canvas_item_new(group,
+ gnome_canvas_ellipse_get_type(),
+ "x1", (double) origenX-20,
+ "y1", (double) origenY-20,
+ "x2", (double) (origenX + 20),
+ "y2", (double) (origenY + 20),
+ "fill_color_rgba", 0x00ff66ff,
+ "outline_color", "black",
+ "width_units", 1.0,
+ NULL);
+
+ //Si el estado que habiamos copiado tenia hijos hay que hacer copia de toda la estructura que enlazase por debajo
+ //Asignamos como hijo al nodo copiado la variable idSubGlobal porque ahora llamaremos a una funcion recursiva que empezará
+ //creando un nuevo nodo en la lista de subautomatas y lo hará con esa idSubGlobal
+ reg.idHijo = idSubGlobal;
+
+
+ printf("Antes de llamar a pegado recursivo\n");
+ //Las dos variables que el procedimiento necesita son el subautomata a buscar en la lista para poder copiartlo y cual será su padre
+ pegado_recursivo(estado_clipboard_idHijo, subautomata_mostrado);
+ printf("Despues de llamar a pegado recursivo\n");
+
+ }
+
+
+
+ reg.item = item;
+ reg.item_nombre = NULL;
+ reg.estado_inicial = NULL;
+ reg.nombre = "";
+ reg.codigo = estado_clipboard_codigo;
+ id ++;
+
+ ListaElementos.push_back(reg);
+
+ printf("Despues de añadir nuevo nodo en el nivel \n");
+
+ /*Añadimos control (señal) al item creado*/
+ g_signal_connect (group, "event",
+ (GtkSignalFunc) item_event,
+ NULL);
+
+ estado_clipboard = FALSE;
+ estado_clipboard_codigo = "";
+ estado_clipboard_idHijo = 0;
+
+
+ //Actualizamos datos necesarios para mostrar cambios en el tree view
+ posSub = ListaSubAutomatas.begin();
+
+ while(posSub->idSub != subautomata_mostrado)
+ {
+ posSub++;
+ }
+
+ //guardamos el estado de la lista de elementos en el nodo del subautomata para poder recargar bien el tree view
+ posSub->ListaElementosSub = ListaElementos;
+
+ actualizar_tree_view();
+
+ gtk_tree_view_expand_to_path(GTK_TREE_VIEW(tree_view), arbolPath);
+
+ }
+
+ printf("Pasa del if\n");
+
+ estado_clipboard = FALSE;
+ estado_clipboard_codigo = "";
+ estado_clipboard_idHijo = 0;
+
+}
+
Property changes on: trunk/src/components/visualHFSM-3.1/interfaz.cpp
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/src/components/visualHFSM-3.1/interfaz.h
===================================================================
--- trunk/src/components/visualHFSM-3.1/interfaz.h (rev 0)
+++ trunk/src/components/visualHFSM-3.1/interfaz.h 2013-03-10 13:05:56 UTC (rev 882)
@@ -0,0 +1,99 @@
+#ifndef INTERFAZ_H
+#define INTERFAZ_H
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <string.h>
+
+#include <sstream>
+#include <iostream>
+#include <string>
+#include <fstream>
+#include <list>
+
+#include <gdk/gdkkeysyms.h> //NOMBRES TECLAS
+
+#include <gtk/gtk.h>
+#include <gtksourceview/gtksourceview.h>
+#include <gtksourceview/gtksourcebuffer.h>
+#include <gtksourceview/gtksourcelanguage.h>
+#include <gtksourceview/gtksourcelanguagemanager.h>
+
+#include <libgnomecanvas/libgnomecanvas.h>
+#include <libglade-2.0/glade/glade.h>
+#include <libxml/tree.h>
+
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "transicion.h"
+#include "xml.h"
+#include "int2string.h"
+
+#include "tipos.h"
+#include "ventanas.h"
+#include "recta.h"
+
+//#include <gtk/gtk.h>
+
+using namespace std;
+
+
+
+void
+create_drag_box (GnomeCanvasGroup *group, char *box_name, double x1, double y1, GCallback callback);
+
+gint
+item_event (GnomeCanvasItem *item_group, GdkEvent *event, gpointer data);
+
+gint
+highlight_box (GnomeCanvasItem *item, GdkEvent *event, gpointer data);
+
+gint
+highlight_box_edit (GnomeCanvasItem *item, GdkEvent *event, gpointer data);
+
+void
+mostrar_subautomata(int pidSub);
+
+void
+ocultar_subautomata(int pidSub);
+
+void
+on_menu_estado_nombrar();
+
+void
+on_menu_estado_editar();
+
+void
+on_menu_estado_marcar_inicial();
+
+void
+on_menu_estado_copiar();
+
+void
+on_menu_estado_eliminar();
+
+void
+on_menu_transicion_nombrar();
+
+void
+on_menu_transicion_editar();
+
+void
+on_menu_transicion_eliminar();
+
+void
+on_menu_pegar();
+
+
+static GtkTreeModel *
+create_and_fill_model ();
+
+void
+actualizar_tree_view();
+/*
+static GtkWidget *
+create_view_and_model();*/
+
+#endif
Property changes on: trunk/src/components/visualHFSM-3.1/interfaz.h
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/src/components/visualHFSM-3.1/nodo.cpp
===================================================================
--- trunk/src/components/visualHFSM-3.1/nodo.cpp (rev 0)
+++ trunk/src/components/visualHFSM-3.1/nodo.cpp 2013-03-10 13:05:56 UTC (rev 882)
@@ -0,0 +1,138 @@
+#include "nodo.h"
+//int cont_nodos = 0;
+
+
+extern list <tNodo> ListaElementos;
+extern GnomeCanvasGroup *root;
+
+void copiar_nodo (GnomeCanvasItem * item, GnomeCanvasItem * item_cp)
+{
+ tNodo nodo;
+ list<tNodo>::iterator posNodos;
+ //GnomeCanvasItem * item_nombre;
+ //double x2,x1,y2,y1;
+
+ posNodos = ListaElementos.begin();
+
+ while( (posNodos != ListaElementos.end()) && (posNodos->item != item) )
+ posNodos++;
+
+ nodo.item = item_cp;
+ nodo.nombre = "";
+ nodo.codigo = posNodos->codigo;
+ nodo.estado_inicial = NULL;
+
+// g_object_get (G_OBJECT (item_cp), "x1", &x1, NULL);
+// g_object_get (G_OBJECT (item_cp), "y1", &y1, NULL);
+// g_object_get (G_OBJECT (item_cp), "x2", &x2, NULL);
+// g_object_get (G_OBJECT (item_cp), "y2", &y2, NULL);
+
+ /*item_nombre = gnome_canvas_item_new (root,
+ gnome_canvas_text_get_type (),
+ "text", posNodos->nombre.c_str(),
+ "x", (x2+x1)/2,
+ "y", (y2+y1)/2,
+ "font", "Sans 12",
+ "size", 32000,
+ "size_set", (gboolean)TRUE,
+ "scale", (gdouble) 3,
+ "scale_set", (gboolean)TRUE,
+ "anchor", GTK_ANCHOR_N,
+ "fill_color", "black",
+ NULL); */
+
+ nodo.item_nombre = NULL;
+
+ ListaElementos.push_back(nodo);
+}
+
+bool cambiar_item_adyacentes (GnomeCanvasItem * id_item, GnomeCanvasItem * old_item, GnomeCanvasItem * new_item)
+{
+
+ list<tNodo>::iterator posNodos;
+ list<GnomeCanvasItem *>::iterator posAdy;
+ bool b = false;
+
+ posNodos = ListaElementos.begin();
+
+ while( (posNodos != ListaElementos.end()) && (posNodos->item != id_item) )
+
+ posNodos++;
+
+
+ posAdy = posNodos->listaAdyacentes.begin();
+
+ while( (posAdy != posNodos->listaAdyacentes.end()) && (*posAdy != old_item) )
+
+ posAdy++;
+
+ if (*posAdy == old_item){
+
+ *posAdy = new_item;
+ b = true;
+ }
+
+
+ return b;
+}
+
+
+void n_borrar_transicion_lista (GnomeCanvasItem * nodo, GnomeCanvasItem * transicion)
+{
+ list<tNodo>::iterator posNodo;
+ list<GnomeCanvasItem *>::iterator posAdy;
+
+ posNodo = ListaElementos.begin();
+
+ while(posNodo->item != nodo)
+ posNodo++;
+
+ posAdy = posNodo->listaAdyacentes.begin();
+
+ while((*posAdy) != transicion)
+ posAdy++;
+
+ posNodo->listaAdyacentes.erase(posAdy);
+
+}
+
+GnomeCanvasItem * pinta_estado_inicial (GnomeCanvasGroup *group, GnomeCanvasItem *item) {
+
+ double x1,x2,y1,y2;
+ GnomeCanvasItem * estado_inicial;
+
+ g_object_get (G_OBJECT (item), "x1", &x1, NULL);
+ g_object_get (G_OBJECT (item), "y1", &y1, NULL);
+ g_object_get (G_OBJECT (item), "x2", &x2, NULL);
+ g_object_get (G_OBJECT (item), "y2", &y2, NULL);
+
+ estado_inicial = gnome_canvas_item_new(group,
+ gnome_canvas_ellipse_get_type(),
+ "x1", (double) x1 + 5,
+ "y1", (double) y1 + 5,
+ "x2", (double) x2 - 5,
+ "y2", (double) y2 - 5,
+ "fill_color_rgba", NULL,
+ "outline_color", "black",
+ "width_units", 1.0,
+ NULL);
+
+ return estado_inicial;
+}
+
+void get_bounds (GnomeCanvasItem *nodo, double *x1, double *y1, double *x2, double *y2) {
+
+ g_object_get (G_OBJECT (nodo), "x1", x1, NULL);
+ g_object_get (G_OBJECT (nodo), "y1", y1, NULL);
+ g_object_get (G_OBJECT (nodo), "x2", x2, NULL);
+ g_object_get (G_OBJECT (nodo), "y2", y2, NULL);
+
+
+}
+
+gint item_event2 (GnomeCanvasItem *item_group, GdkEvent *event, gpointer data)
+{
+ cout << ""<< endl;
+ return true;
+}
+
Property changes on: trunk/src/components/visualHFSM-3.1/nodo.cpp
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/src/components/visualHFSM-3.1/nodo.h
===================================================================
--- trunk/src/components/visualHFSM-3.1/nodo.h (rev 0)
+++ trunk/src/components/visualHFSM-3.1/nodo.h 2013-03-10 13:05:56 UTC (rev 882)
@@ -0,0 +1,34 @@
+#ifndef NODO_H
+#define NODO_H
+
+#include <iostream>
+#include <list>
+
+#include <gtk/gtk.h>
+#include <libgnomecanvas/libgnomecanvas.h>
+
+#include "tipos.h"
+
+using namespace std;
+
+
+/* Copia y añade un nodo a la lista */
+void copiar_nodo (GnomeCanvasItem * item, GnomeCanvasItem * item_cp);
+
+/* cambia la transicion asociada */
+void cambiar_transicion (int id, GnomeCanvasItem * old_item, GnomeCanvasItem * new_item);
+
+/* Cambia la transicion adyacente al nodo "id_item" */
+bool cambiar_item_adyacentes (GnomeCanvasItem * id_item, GnomeCanvasItem * old_item, GnomeCanvasItem * new_item);
+
+/* borrar transicion de la lista */
+void n_borrar_transicion_lista (GnomeCanvasItem * nodo, GnomeCanvasItem * transicion);
+
+/* */
+GnomeCanvasItem * pinta_estado_inicial (GnomeCanvasGroup *group, GnomeCanvasItem *item);
+
+void get_bounds (GnomeCanvasItem *nodo, double *x1, double *y1, double *x2, double *y2);
+
+gint item_event2 (GnomeCanvasItem *item_group, GdkEvent *event, gpointer data);
+
+#endif
Property changes on: trunk/src/components/visualHFSM-3.1/nodo.h
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/src/components/visualHFSM-3.1/recta.cpp
===================================================================
--- trunk/src/components/visualHFSM-3.1/recta.cpp (rev 0)
+++ trunk/src/components/visualHFSM-3.1/recta.cpp 2013-03-10 13:05:56 UTC (rev 882)
@@ -0,0 +1,94 @@
+#include <stdlib.h>
+#include "recta.h"
+#include <math.h>
+
+punto
+crear_punto (double x, double y)
+{
+ punto p;
+ p.x = x;
+ p.y = y;
+
+ return p;
+}
+
+punto punto_medio (punto p1, punto p2)
+{
+ punto p;
+ p.x = (p1.x + p2.x)/2;
+ p.y = (p1.y + p2.y)/2;
+
+ return p;
+}
+
+void
+punto_get_values (punto p, double *x, double *y)
+{
+
+ *x = p.x;
+ *y = p.y;
+
+}
+
+recta crear_recta (punto p1, punto p2)
+{
+ recta r;
+
+ r.A = p2.y - p1.y;
+ r.B = -(p2.x - p1.x);
+ r.C = -(r.A * p1.x) - (r.B * p1.y);
+
+ return r;
+}
+recta recta_perpendicular (recta r1, punto p1)
+{
+ recta r;
+
+ r.A = -r1.B;
+ r.B = r1.A;
+ r.C = -((r.A * p1.x)+(r.B * p1.y));
+
+ return r;
+
+}
+recta recta_paralela (recta r1, punto p, double distancia)
+{
+ recta r;
+
+ r.A = r1.A;
+ r.B = r1.B;
+ r.C = (distancia*(sqrt((r1.A*r1.A)+(r1.B*r1.B))))-((r1.A*p.x)+ (r1.B * p.y));
+ if (r1.A == 0)
+ {
+ r.B = 1;
+ r.C = r1.C/r1.B + 10;
+ }else if (r1.B == 0)
+ {
+ r.A = 1;
+ r.C = r1.C/r1.A + 10;
+ }
+
+ return r;
+}
+punto interseccion_rectas (recta r1, recta r2)
+{
+ punto p;
+
+ if (r1.A == 0)
+ {
+ p.y = -r1.C/r1.B;
+ p.x = -r2.C;
+ }
+ else if (r1.B == 0)
+ {
+ p.y = -r2.C;
+ p.x = -r1.C/r1.A;
+ }
+ else
+ {
+ p.y = (-(r2.A * r1.C - r1.A * r2.C))/ (r2.A * r1.B - r1.A * r2.B);
+ p.x = ((-r2.B * p.y)-r2.C)/r2.A;
+ }
+
+ return p;
+}
Property changes on: trunk/src/components/visualHFSM-3.1/recta.cpp
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/src/components/visualHFSM-3.1/recta.h
===================================================================
--- trunk/src/components/visualHFSM-3.1/recta.h (rev 0)
+++ trunk/src/components/visualHFSM-3.1/recta.h 2013-03-10 13:05:56 UTC (rev 882)
@@ -0,0 +1,27 @@
+#ifndef RECTA_H
+#define RECTA_H
+
+#include "tipos.h"
+#include <math.h>
+
+
+punto crear_punto (double x, double y);
+punto punto_medio (punto p1, punto p2);
+void punto_get_values (punto p, double *x, double *y);
+
+/*Ax + By + C = 0
+A=y2-y1 B=x2-x1 C=((y2-y1)*x1)+((x2-x1)*y1) */
+recta crear_recta (punto p1, punto p2);
+
+/* Recta perpendicular a otra y que pase por un punto
+ A'=-B B=A C=-((A*x)+(B*y));*/
+recta recta_perpendicular (recta r1, punto p1);
+
+/* Recta paralela a otra a una distancia
+ d(p,R)=|Ax+By+C|/((A^2)+(B^2))^1/2 // A'=A B'=B*/
+recta recta_paralela (recta r1, punto p1, double distancia);
+
+punto interseccion_rectas (recta r1, recta r2);
+
+
+#endif
Property changes on: trunk/src/components/visualHFSM-3.1/recta.h
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/src/components/visualHFSM-3.1/reemplazar.cpp
===================================================================
--- trunk/src/components/visualHFSM-3.1/reemplazar.cpp (rev 0)
+++ trunk/src/components/visualHFSM-3.1/reemplazar.cpp 2013-03-10 13:05:56 UTC (rev 882)
@@ -0,0 +1,96 @@
+
+
+#include "reemplazar.h"
+
+
+
+/* Halla la longitud de una cadena, hace las veces de strlen */
+int longitud(char *cadena)
+{
+ int i;
+ for(i=0; ;i++)
+ if(cadena[i]=='\0')
+ break;
+ return i;
+}
+
+/* Halla la posicion de aparicion de una subcadena en una cadena */
+int posicion(char *cadena, char *subcadena)
+{
+ int i, j;
+
+ for(i=0; i<longitud(cadena); i++)
+ {
+ if(cadena[i]==subcadena[0])
+ {
+ //if(longitud(cadena)-i < longitud(subcadena))
+ // return -1;
+
+ for(j=0; j<longitud(subcadena); j++)
+ {
+ if(cadena[i+j]!=subcadena[j])
+ break;
+ }
+ if(j==longitud(subcadena))
+ return i;
+ }
+ }
+
+ return -1;
+}
+
+/*
+ Busca una subcadena en una cadena, y la reemplaza por otra;
+ retorna el numero de veces que se hizo el reemplazo
+*/
+int reemplazar2(char *cadena, char *subcadena, char *reemplazo)
+{
+ int ocurrencias = 0;
+ int i, indice, posiciones, temp, l_cadena, l_subcadena, l_reemplazo;
+ int tam;
+ char * cadena_aux;
+
+ l_cadena = longitud(cadena);
+ l_reemplazo = longitud(reemplazo);
+ l_subcadena = longitud(subcadena);
+
+ for(;;)
+ {
+ indice = posicion(cadena, subcadena);
+ if(indice==-1)
+ break;
+ else
+ {
+ printf("NO -1");
+ tam = l_subcadena-l_reemplazo;
+ if (tam < 0)
+ {
+ printf("0");
+ for(i=indice; i<indice+l_subcadena; i++)
+ cadena_aux[i-indice] = cadena[i];
+ cadena_aux[i] = '\0';
+ printf("1");
+ for(i=indice; i<indice+l_reemplazo; i++)
+ cadena[i]=reemplazo[i-indice];
+ printf("2");
+ for(i=indice+l_reemplazo; i<longitud(cadena_aux); i++)
+ cadena[i]=cadena_aux[i-indice-l_reemplazo];
+ }else
+ {
+ for(i=indice; i<indice+l_reemplazo; i++)
+ cadena[i]=reemplazo[i-indice];
+
+ /* Si la longitud del reemplazo es menor que la de la subcadena,
+ recorre caracteres siguientes, posiciones a la izquierda */
+ posiciones=l_subcadena-l_reemplazo;
+ if(posiciones>0)
+ for(temp=i; temp<=l_cadena; temp++)
+ cadena[temp]=cadena[temp+posiciones];
+ }
+ ocurrencias++;
+ }
+ }
+
+ return ocurrencias;
+}
+
Property changes on: trunk/src/components/visualHFSM-3.1/reemplazar.cpp
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/src/components/visualHFSM-3.1/reemplazar.h
===================================================================
--- trunk/src/components/visualHFSM-3.1/reemplazar.h (rev 0)
+++ trunk/src/components/visualHFSM-3.1/reemplazar.h 2013-03-10 13:05:56 UTC (rev 882)
@@ -0,0 +1,32 @@
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if !defined __REEMPLAZAR_H
+#define __REEMPLAZAR_H
+
+
+#include <stdio.h>
+
+
+
+/* Halla la longitud de una cadena, hace las veces de strlen */
+int longitud(char *cadena);
+
+/* Halla la posicion de aparicion de una subcadena en una cadena */
+int posicion(char *cadena, char *subcadena);
+
+/*
+ Busca una subcadena en una cadena, y la reemplaza por otra;
+ retorna el numero de veces que se hizo el reemplazo
+*/
+int reemplazar(char *cadena, char *subcadena, char *reemplazo);
+
+
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
Property changes on: trunk/src/components/visualHFSM-3.1/reemplazar.h
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/src/components/visualHFSM-3.1/tipos.h
===================================================================
--- trunk/src/components/visualHFSM-3.1/tipos.h (rev 0)
+++ trunk/src/components/visualHFSM-3.1/tipos.h 2013-03-10 13:05:56 UTC (rev 882)
@@ -0,0 +1,100 @@
+#ifndef TIPOS_H
+#define TIPOS_H
+
+#include <libgnomecanvas/libgnomecanvas.h>
+#include <list>
+#include <string>
+using namespace std;
+
+typedef struct punto {
+ double x;
+ double y;
+} punto;
+
+typedef struct recta {
+ double A;
+ double B;
+ double C;
+} recta;
+
+
+typedef struct tipoNodo {
+
+ GnomeCanvasItem * item;
+ GnomeCanvasItem * estado_inicial;
+// int origenX, origenY; // Punto (x,y) donde se dibujara en el canvas
+// int destinoX, destinoY; // Punto (x,y) donde se dibujara en el canvas
+ string nombre; // Nombre del nodo. "" por defecto
+ string codigo; // Codigo del estado
+ GnomeCanvasItem * item_nombre; // item que muestra el nombre del estado
+ list <GnomeCanvasItem *> listaAdyacentes; // Para estados -- Lista de lineas adyacentes
+ int idHijo; //Id. que indica el subautomata dentro de la lista de subautomatas que se corresponde con el hijo de este estado
+} tNodo;
+
+typedef struct tipoTransicion {
+ //int id;
+ GnomeCanvasItem * item; // Item que representa la transición. Está formado a su vez por 3 item: 2 líneas y un punto de acción en la unión de ambas (box).
+ // Posicion 0 inicio recta, posicion 1 final recta, posicion 2 box.
+ //int origenX, origenY;
+ //int destinoX, destinoY;
+ //double pMedioX, pMedioY; // Posición del punto de acción de la transición.
+ GnomeCanvasItem * origen; // Nodo origen
+ GnomeCanvasItem * destino; // Nodo destino
+ string nombre; // Nombre de la transicion. "" por defecto
+ GnomeCanvasItem * item_nombre; // Item del nombre de la transición.
+ //GnomeCanvasItem * orientacion; // Triangulo flecha
+ string codigo;
+ int tiempo;
+} tTransicion;
+
+extern list <tNodo> ListaElementos;
+extern list <tTransicion> ListaTransiciones;
+
+typedef struct transicion_aux { // Transiciones temporales. Usadas para pintar las transiciones despues de cargar un fichero.
+ GnomeCanvasItem *origen;
+ GnomeCanvasItem *destino;
+ int origen_xml;
+ int destino_id;
+ int tiempo;
+ string codigo;
+ string nombre;
+ GnomeCanvasItem *item;
+} transicion_aux;
+
+typedef struct importar {
+ bool laser;
+ bool motor;
+ bool radar;
+ bool encoders;
+ bool lat_lon;
+ bool camara;
+ bool ptencoders;
+} importar;
+
+
+typedef enum TYPE_VENTANA {
+ NOMBRAR,
+ EDITAR,
+ CODIGO,
+ LIBRERIAS,
+ TIMER
+}tVentana;
+
+typedef struct nodoVentana {
+ GnomeCanvasItem * item; // item correspondiente a la ventana
+ tVentana tipo; // Nombre del nodo. "" por defecto
+ GtkWidget *ventana; // Ventana
+} nVentana;
+
+typedef struct tSubAut {
+ list <tNodo> ListaElementosSub;
+ list <tTransicion> ListaTransicionesSub;
+ int tiempoIteracionSub;
+ string variablesSub;
+ string funcionesSub;
+ importar impSub;
+ int idSub;
+ int idPadre;
+} tSubAut;
+
+#endif
Added: trunk/src/components/visualHFSM-3.1/transicion.cpp
===================================================================
--- trunk/src/components/visualHFSM-3.1/transicion.cpp (rev 0)
+++ trunk/src/components/visualHFSM-3.1/transicion.cpp 2013-03-10 13:05:56 UTC (rev 882)
@@ -0,0 +1,493 @@
+#include "transicion.h"
+int cont_transiciones = 0;
+
+
+
+//extern list <transicion_aux> ListaTransicionesTemporales;
+//extern list <GtkWidget *> ListaBotones;
+//extern GnomeCanvasGroup *root;
+
+GnomeCanvasItem * get_box (GnomeCanvasItem * item)
+{
+ GList * list_items;
+
+ list_items = GNOME_CANVAS_GROUP (item)->item_list;
+
+ return (GnomeCanvasItem *) g_list_nth_data (list_items, g_list_length(list_items)-1);
+}
+
+/* Cambia el id dela transicion */
+bool cambiar_item_transicion (GnomeCanvasItem * item, GnomeCanvasItem * new_item)
+{
+ list<tTransicion>::iterator posLinea;
+ bool b = false;
+
+ posLinea = ListaTransiciones.begin();
+
+ while( (posLinea != ListaTransiciones.end()) && (posLinea->item != item) )
+ {
+
+ posLinea++;
+
+ }
+
+ if (posLinea->item == item){
+
+ posLinea->item = new_item;
+ b = true;
+
+ }
+
+ return b;
+}
+
+/***** Pintar AutoTransicion *****/
+/* */
+
+int num_autotransiciones (GnomeCanvasItem *nodo)
+{
+ list<tTransicion>::iterator posLinea;
+ int n = 0;
+
+ posLinea = ListaTransiciones.begin();
+
+ while( posLinea != ListaTransiciones.end() )
+
+ {
+ if ((posLinea->origen == nodo) && (posLinea->destino == nodo))
+ n++;
+
+ posLinea++;
+
+ }
+
+ return n;
+}
+
+GnomeCanvasItem *
+pinta_autotransicion (GnomeCanvasItem *nodo)
+{
+ double I1x1, I1x2, I1y1, I1y2; // Puntos del orgien
+ double x1,y1;
+ int n;
+ GnomeCanvasPoints *points = gnome_canvas_points_new (4);
+ GnomeCanvasItem * item;
+ GnomeCanvasGroup * group;
+ GnomeCanvas *canvas;
+
+ g_object_get (G_OBJECT (nodo), "x1", &I1x1, NULL);
+ g_object_get (G_OBJECT (nodo), "y1", &I1y1, NULL);
+ g_object_get (G_OBJECT (nodo), "x2", &I1x2, NULL);
+ g_object_get (G_OBJECT (nodo), "y2", &I1y2, NULL);
+
+ x1 = (I1x1 + I1x2)/2;
+ y1 = (I1y1 + I1y2)/2 + abs(I1y1 - I1y2)/2;
+
+ canvas = nodo->canvas;
+
+ group = GNOME_CANVAS_GROUP (gnome_canvas_item_new (GNOME_CANVAS_GROUP(canvas->root),
+ gnome_canvas_group_get_type (),
+ "x", 0,
+ "y", 0,
+ NULL));
+
+ /*item = gnome_canvas_item_new(group,
+ gnome_canvas_ellipse_get_type(),
+ "x1", x1-7,
+ "y1", y1,
+ "x2", x1+7,
+ "y2", y1+14,
+ //"fill_color_rgba", 0x00ffffff,
+ "outline_color", "black",
+ "width_units", 1.0,
+ NULL);
+
+ points->coords[0] = x1-0.5;
+ points->coords[1] = y1+14;
+ points->coords[2] = x1+0.5;
+ points->coords[3] = y1+14 + 0.75;
+
+ gnome_canvas_item_new(group, gnome_canvas_line_get_type (),
+ "points", points,
+ "fill_color", NULL,
+ "width_units", 1.0,
+ //"smooth", TRUE,
+ //"first_arrowhead", TRUE,
+ "last_arrowhead", TRUE,
+ "arrow_shape_a", 3.0,
+ "arrow_shape_b", 8.0,
+ "arrow_shape_c", 3.0,
+ NULL);*/
+ n = num_autotransiciones (nodo);
+
+ points->coords[0] = x1-8;
+ points->coords[1] = y1-1;
+ points->coords[2] = x1-8;
+ points->coords[3] = y1+20 + (n*20);
+ points->coords[4] = x1+8;
+ points->coords[5] = y1+20 + (n*20);
+ points->coords[6] = x1+8;
+ points->coords[7] = y1-1;
+ item = gnome_canvas_item_new(group, gnome_canvas_line_get_type (),
+ "points", points,
+ "fill_color", "orange",
+ "width_units", 1.0,
+ "smooth", TRUE,
+ "join-style", GDK_JOIN_BEVEL,
+ //"first_arrowhead", TRUE,
+ "last_arrowhead", TRUE,
+ "arrow_shape_a", 3.0,
+ "arrow_shape_b", 8.0,
+ "arrow_shape_c", 3.0,
+ NULL);
+ create_drag_box (group, (char *)"box", x1+1, y1+20+(n*20), G_CALLBACK (highlight_box_edit));
+
+ return GNOME_CANVAS_ITEM(group);
+}
+
+
+GnomeCanvasGroup * repintar_transicion (GnomeCanvasGroup *root, GnomeCanvasItem *origen, GnomeCanvasItem *destino, double x, double y)
+{
+
+ GnomeCanvasItem *item1,*item2;
+ GnomeCanvasGroup *group;
+
+ double I1x1, I1x2, I1y1, I1y2; // Puntos del orgien
+ double I2x1, I2x2, I2y1, I2y2; // Puntos del destino
+
+
+ g_object_get (G_OBJECT (origen), "x1", &I1x1, NULL);
+ g_object_get (G_OBJECT (origen), "y1", &I1y1, NULL);
+ g_object_get (G_OBJECT (origen), "x2", &I1x2, NULL);
+ g_object_get (G_OBJECT (origen), "y2", &I1y2, NULL);
+
+ g_object_get (G_OBJECT (destino), "x1", &I2x1, NULL);
+ g_object_get (G_OBJECT (destino), "y1", &I2y1, NULL);
+ g_object_get (G_OBJECT (destino), "x2", &I2x2, NULL);
+ g_object_get (G_OBJECT (destino), "y2", &I2y2, NULL);
+
+ //Punto medio circulo origen
+ double Xm1 = ((I1x2 + I1x1) / 2);
+ double Ym1 = ((I1y2 + I1y1) / 2);
+ punto pCirculoOrigen = crear_punto (Xm1, Ym1);
+
+ //Punto medio circulo destino
+ double Xm2 = ((I2x2 + I2x1) / 2);
+ double Ym2 = ((I2y2 + I2y1) / 2);
+ punto pCirculoDestino = crear_punto (Xm2, Ym2);
+
+ // Punto Medio Transicion
+ punto pMedioTransicion = crear_punto (x, y);
+
+ recta recta_origen_pm = crear_recta (pCirculoOrigen, pMedioTransicion);
+
+ recta recta_destino_pm = crear_recta (pCirculoDestino, pMedioTransicion);
+
+ // Ecuacion Recta Perpendicular que pasa por el punto medio del circulo origen
+ recta recta_perpendicular_circulo_origen = recta_perpendicular (recta_origen_pm, pCirculoOrigen);
+
+ // Ecuacion Recta Paralela d=(ax+by+c)/(a^2 + b^2)^1/2
+ recta recta_paralela1 = recta_paralela (recta_perpendicular_circulo_origen, pCirculoOrigen, -20);
+
+
+ // Ecuacion Recta Perpendicular que pasa por el punto medio del circulo destino
+ recta recta_perpendicular_circulo_destino = recta_perpendicular (recta_destino_pm, pCirculoDestino);
+
+ // Ecuacion Recta Paralela d=(ax+by+c)/(a^2 + b^2)^1/2
+ recta recta_paralela2 = recta_paralela (recta_perpendicular_circulo_destino, pCirculoDestino, -20);
+
+ double YI1, XI1;
+ punto pInterseccion = interseccion_rectas (recta_origen_pm, recta_paralela1);
+ punto_get_values (pInterseccion, &XI1, &YI1);
+
+ double YI2, XI2;
+ pInterseccion = interseccion_rectas (recta_destino_pm, recta_paralela2);
+ punto_get_values (pInterseccion, &XI2, &YI2);
+
+ group = GNOME_CANVAS_GROUP (gnome_canvas_item_new (root,
+ gnome_canvas_group_get_type (),
+ "x", 0,
+ "y", 0,
+ NULL));
+
+ GnomeCanvasPoints *points = gnome_canvas_points_new (2);
+
+
+
+ points->coords[0] = XI1;
+ points->coords[1] = YI1;
+ points->coords[2] = x;
+ points->coords[3] = y;
+
+ item1 = gnome_canvas_item_new(group, gnome_canvas_line_get_type (),
+ "points", points,
+ "fill_color", "orange",
+ "width_units", 1.0,
+ //"first_arrowhead", TRUE,
+ //"last_arrowhead", TRUE,
+ //"arrow_shape_a", 8.0,
+ //"arrow_shape_b", 8.0,
+ //"arrow_shape_c", 8.0,
+ NULL);
+
+ points->coords[0] = x;
+ points->coords[1] = y;
+ points->coords[2] = XI2;
+ points->coords[3] = YI2;
+
+ item2 = gnome_canvas_item_new(group, gnome_canvas_line_get_type (),
+ "points", points,
+ "fill_color", "orange",
+ "width_units", 1.0,
+ //"first_arrowhead", TRUE,
+ "last_arrowhead", TRUE,
+ "arrow_shape_a", 8.0,
+ "arrow_shape_b", 8.0,
+ "arrow_shape_c", 8.0,
+ NULL);
+
+ gnome_canvas_points_free (points);
+
+
+ return group;
+
+
+}
+
+GnomeCanvasGroup * repintar_transicion_nodo (GnomeCanvasGroup *root, GnomeCanvasItem *transicion, GnomeCanvasItem *nodo, char * direccion)
+{
+
+ GList * list_items, *list_aux;
+ GnomeCanvasItem *item, *box, *arrow;
+ GnomeCanvasGroup *group;
+ GnomeCanvasPoints *points;
+ double x1,y1,x2,y2, x, y;
+
+ group = GNOME_CANVAS_GROUP (transicion);
+ list_items = group->item_list;
+
+ box = GNOME_CANVAS_ITEM(g_list_nth_data (list_items, 2));
+
+
+ g_object_get (G_OBJECT (box), "x1", &x1, NULL);
+ g_object_get (G_OBJECT (box), "y1", &y1, NULL);
+ g_object_get (G_OBJECT (box), "x2", &x2, NULL);
+ g_object_get (G_OBJECT (box), "y2", &y2, NULL);
+
+ x = (x1+x2)/2;
+ y = (y1+y2)/2;
+
+
+ double I1x1, I1x2, I1y1, I1y2; // Puntos del nodo
+
+ g_object_get (G_OBJECT (nodo), "x1", &I1x1, NULL);
+ g_object_get (G_OBJECT (nodo), "y1", &I1y1, NULL);
+ g_object_get (G_OBJECT (nodo), "x2", &I1x2, NULL);
+ g_object_get (G_OBJECT (nodo), "y2", &I1y2, NULL);
+
+ //Punto medio nodo
+ double Xm1 = ((I1x2 + I1x1) / 2);
+ double Ym1 = ((I1y2 + I1y1) / 2);
+ punto pNodo = crear_punto (Xm1, Ym1);
+
+ // Punto Medio Transicion
+ punto pMedioTransicion = crear_punto (x, y);
+
+ recta recta_nodo_pm = crear_recta (pNodo, pMedioTransicion);
+
+ // Ecuacion Recta Perpendicular que pasa por el punto medio del circulo origen
+ recta recta_perpendicular_nodo = recta_perpendicular (recta_nodo_pm, pNodo);
+
+ // Ecuacion Recta Paralela d=(ax+by+c)/(a^2 + b^2)^1/2
+ recta recta_paralela_nodo = recta_paralela (recta_perpendicular_nodo, pNodo, -20);
+
+ double YI1, XI1;
+ punto pInterseccion = interseccion_rectas (recta_nodo_pm, recta_paralela_nodo);
+ punto_get_values (pInterseccion, &XI1, &YI1);
+
+ points = gnome_canvas_points_new (2);
+
+ if (strcmp ( direccion, (char *) "origen" ) == 0)
+ {
+ arrow = (GnomeCanvasItem *) g_list_nth_data (list_items, 0);
+ list_items=g_list_next(list_items);
+ gtk_object_destroy (GTK_OBJECT (arrow));
+
+
+ points->coords[0] = XI1;
+ points->coords[1] = YI1;
+ points->coords[2] = x;
+ points->coords[3] = y;
+
+ item = gnome_canvas_item_new(group, gnome_canvas_line_get_type (), // Si se define el "parent" del item como root da fallo de segmentacion
+ "points", points,
+ "fill_color", "orange",
+ "width_units", 1.0,
+ NULL);
+
+ //list_items = g_list_insert (list_items, (gpointer)item, 0);
+ list_aux = g_list_nth (list_items, 2); // Reordenar los elementos dentro del grupo
+ list_items = g_list_remove_link (list_items, list_aux);
+ list_items = g_list_insert (list_items, (gpointer)item, 0);
+ }
+ else if (strcmp ( direccion, (char *) "destino" ) == 0)
+ {
+ arrow = (GnomeCanvasItem *) g_list_nth_data (list_items, 1);
+ //list_aux = g_list_nth (list_items, 2);
+ gtk_object_destroy (GTK_OBJECT (arrow));
+ //list_items = g_list_concat (list_items, list_aux);
+
+
+ points->coords[0] = x;
+ points->coords[1] = y;
+ points->coords[2] = XI1;
+ points->coords[3] = YI1;
+
+ item = gnome_canvas_item_new(group, gnome_canvas_line_get_type (),
+ "points", points,
+ "fill_color", "orange",
+ "width_units", 1.0,
+ "last_arrowhead", TRUE,
+ "arrow_shape_a", 8.0,
+ "arrow_shape_b", 8.0,
+ "arrow_shape_c", 8.0,
+ NULL);
+
+ //list_items = g_list_insert (list_items, (gpointer)item, 1);
+ list_aux = g_list_nth (list_items, 2);
+ list_items = g_list_remove_link (list_items, list_aux);
+ list_items = g_list_insert (list_items, (gpointer)item, 1);
+ }
+
+ group->item_list = list_items;
+
+ //gnome_canvas_item_reparent (box, transicion);
+
+ return GNOME_CANVAS_GROUP (group);
+
+}
+
+
+void borrar_transicion (GnomeCanvasItem *origen, GnomeCanvasItem *destino, char * type)
+{
+ list<tTransicion>::iterator posLinea;
+ list<tNodo>::iterator pos2;
+ list<GnomeCanvasItem *>::iterator pos3;
+ list<GnomeCanvasItem *>::iterator posAux;
+
+ posLinea = ListaTransiciones.begin();
+
+ while( (posLinea != ListaTransiciones.end()) && (posLinea->origen != origen) && (posLinea->destino != destino))
+ {
+
+ posLinea++;
+
+ }
+
+
+ if (strcmp ( type, (char *) "total" ) == 0){
+
+ gtk_object_destroy (GTK_OBJECT (origen));
+ gtk_object_destroy (GTK_OBJECT (destino));
+
+ }
+ else if (strcmp ( type, (char *) "origen" ) == 0){
+
+ gtk_object_destroy (GTK_OBJECT (origen));
+
+ }
+ else if (strcmp ( type, (char *) "destino" ) == 0){
+
+ gtk_object_destroy (GTK_OBJECT (destino));
+
+ }else
+ cout << "tipo incorrecto" << endl;
+
+
+
+
+}
+void add_transicion_lista (GnomeCanvasItem *transicion, GnomeCanvasItem *origen, GnomeCanvasItem *destino, GnomeCanvasItem * nombre, string codigo, int tiempo)
+{
+
+ tTransicion l;
+ gchararray name;
+ //char *name;
+
+ l.item = transicion;
+ l.origen = origen;
+ l.destino = destino;
+ l.codigo = codigo;
+ l.tiempo = tiempo;
+ l.item_nombre = nombre;
+ if (nombre != NULL){
+ g_object_get (G_OBJECT (nombre), "text", &name, NULL);
+ l.nombre = name;
+ }else
+ l.nombre = "";
+
+ ListaTransiciones.push_back(l);
+
+
+
+
+
+
+
+}
+
+/*** Eliminar la transicion de la lista ***/
+void t_eliminar_transicion_lista (GnomeCanvasItem *transicion)
+{
+ list<tTransicion>::iterator posLinea;
+
+ posLinea = ListaTransiciones.begin();
+
+ while( (posLinea != ListaTransiciones.end()) && (posLinea->item != transicion) )
+ posLinea++;
+
+ n_borrar_transicion_lista (posLinea->origen,transicion);
+
+ if (posLinea->destino != posLinea->origen)
+ n_borrar_transicion_lista (posLinea->destino,transicion);
+
+ ListaTransiciones.erase(posLinea);
+
+
+}
+
+
+int
+numero_transiciones (GnomeCanvasItem *estado1, GnomeCanvasItem *estado2)
+{
+ list<tTransicion>::iterator pos;
+ int contador = 0;
+
+ pos = ListaTransiciones.begin();
+
+ while ( pos != ListaTransiciones.end() )
+ {
+ if (((pos->origen == estado1) && (pos->destino == estado2)) || ((pos->origen == estado2) && (pos->destino == estado1)))
+ contador++;
+ pos++;
+ }
+ return contador;
+
+}
+
+void eliminar_nombre (GnomeCanvasItem *transicion)
+{
+ list<tTransicion>::iterator posLinea;
+
+ posLinea = ListaTransiciones.begin();
+
+ while( (posLinea != ListaTransiciones.end()) && (posLinea->item != transicion) )
+ posLinea++;
+
+ posLinea->nombre="";
+
+ gtk_object_destroy (GTK_OBJECT (posLinea->item_nombre));
+
+
+}
+
Property changes on: trunk/src/components/visualHFSM-3.1/transicion.cpp
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/src/components/visualHFSM-3.1/transicion.h
===================================================================
--- trunk/src/components/visualHFSM-3.1/transicion.h (rev 0)
+++ trunk/src/components/visualHFSM-3.1/transicion.h 2013-03-10 13:05:56 UTC (rev 882)
@@ -0,0 +1,59 @@
+#ifndef TRANSICION_H
+#define TRANSICION_H
+
+#include <iostream>
+
+#include <gtk/gtk.h>
+#include <libgnomecanvas/libgnomecanvas.h>
+
+#include <list>
+#include <cstring>
+
+
+#include "recta.h"
+#include "nodo.h"
+#include "interfaz.h"
+using namespace std;
+
+/* Devuelve el identificador de la transición */
+int id_transicion ();
+
+/* */
+GnomeCanvasItem * get_box (GnomeCanvasItem * item);
+
+/* Cambia el id dela transicion */
+bool cambiar_item_transicion (GnomeCanvasItem * item, GnomeCanvasItem * new_item);
+
+/***** Pintar Transiciones *****/
+
+/*** Pintar AutoTransicion ***/
+GnomeCanvasItem *pinta_autotransicion (GnomeCanvasItem *item);
+
+/*** Repintar transicion al mover elementos ***/
+// origen_ref hace referencia al nodo que se está moviendo. Si se está moviendo el centro de la transicion poner origen_ref a NULL.
+// Devuelve el grupo que hace referencia a los elementos de la transicion. Si origen_ref es NULL sólo se devuelven las lineas que componen la transicion.
+GnomeCanvasGroup * repintar_transicion (GnomeCanvasGroup *root, GnomeCanvasItem *origen, GnomeCanvasItem *destino, double x, double y);
+
+// Al mover nodos
+// Devuelve el grupo completo de la transicion
+GnomeCanvasGroup * repintar_transicion_nodo (GnomeCanvasGroup *root, GnomeCanvasItem *transicion, GnomeCanvasItem *nodo, char * direccion);
+
+/*** Borra la transicion ***/
+
+// type puede ser "origen", "destino" o "total". Depnde de si se quiere borrar toda la transcicion o la mitad de ella
+void borrar_transicion (GnomeCanvasItem *origen, GnomeCanvasItem *destino, char * type);
+
+//void borrar_transicion (GnomeCanvasItem *transicion, char * type);
+
+/*** Lista Transiciones ***/
+void add_transicion_lista (GnomeCanvasItem *transicion, GnomeCanvasItem *origen, GnomeCanvasItem *destino, GnomeCanvasItem * nombre, string codigo, int tiempo);
+
+// Eliminar transicion lista //
+void t_eliminar_transicion_lista (GnomeCanvasItem *transicion);
+
+/*** Otros ***/
+int numero_transiciones (GnomeCanvasItem *estado1, GnomeCanvasItem *estado2);
+
+void eliminar_nombre (GnomeCanvasItem *transicion);
+
+#endif
Property changes on: trunk/src/components/visualHFSM-3.1/transicion.h
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/src/components/visualHFSM-3.1/ventanas.cpp
===================================================================
--- trunk/src/components/visualHFSM-3.1/ventanas.cpp (rev 0)
+++ trunk/src/components/visualHFSM-3.1/ventanas.cpp 2013-03-10 13:05:56 UTC (rev 882)
@@ -0,0 +1,991 @@
+#include "ventanas.h"
+
+list <nVentana> ListaVentanas;
+
+extern list <tNodo> ListaElementos;
+extern list <tTransicion> ListaTransiciones;
+extern int color;
+
+extern string variables;
+extern string funciones;
+extern importar imp;
+extern int tiempoIteracion;
+
+extern GnomeCanvasGroup *root;
+
+extern GladeXML *prog;
+
+void destroy (GtkWidget *widget, gpointer data)
+{
+
+ gtk_widget_destroy (gtk_widget_get_toplevel(widget));
+
+}
+
+void restaurar_color (GtkWidget *widget, gpointer data)
+{
+ GnomeCanvasItem *item, *box;
+ list<tNodo>::iterator posNodo;
+
+ item = GNOME_CANVAS_ITEM (g_object_get_data (G_OBJECT (gtk_widget_get_toplevel(widget)), "item"));
+
+ if (GNOME_IS_CANVAS_GROUP (item)){
+ box = get_box (item);
+ //gnome_canvas_item_set (box,
+ // "fill_color", NULL,
+ // NULL);
+ change_item_color (box,7);
+
+ }else{
+
+ posNodo = ListaElementos.begin();
+
+ while( (posNodo != ListaElementos.end()) && (posNodo->item != item))
+ posNodo++;
+
+ if (posNodo->idHijo !=0){
+
+ change_item_color (item,2);
+
+ }else{
+
+ change_item_color (item,3);
+
+ }
+
+ }
+
+}
+
+
+void aplicar (GtkButton *button, gpointer data)
+{
+ double x1, x2, y1, y2;
+ double x,y;
+
+ list<tNodo>::iterator posNodo;
+ list<tTransicion>::iterator posTransicion;
+
+ GnomeCanvasItem *item, *box;
+ GnomeCanvasItem *item_nombre;
+
+ GList * list_items;
+
+ GtkWidget *entry = GTK_WIDGET (g_object_get_data (G_OBJECT (button), "entry"));
+
+ const char *texto = gtk_entry_get_text(GTK_ENTRY(entry));
+
+ item = GNOME_CANVAS_ITEM (g_object_get_data (G_OBJECT (button), "item"));
+
+
+
+ //cout << "Centro: " << x << " " << y << endl;
+
+ posNodo = ListaElementos.begin();
+
+ while( (posNodo != ListaElementos.end()) && (posNodo->item != item))
+ posNodo++;
+
+ if (posNodo == ListaElementos.end()){
+
+ posTransicion = ListaTransiciones.begin();
+
+ while( (posTransicion != ListaTransiciones.end()) && (posTransicion->item != item) )
+ posTransicion++;
+
+ if (posTransicion->nombre != "")
+ gtk_object_destroy (GTK_OBJECT (posTransicion->item_nombre));
+
+ list_items = GNOME_CANVAS_GROUP(item)->item_list;
+
+ box = (GnomeCanvasItem *) g_list_nth_data (list_items, g_list_length (list_items)-1);
+
+ g_object_get (G_OBJECT (box), "x1", &x1, NULL);
+ g_object_get (G_OBJECT (box), "y1", &y1, NULL);
+ g_object_get (G_OBJECT (box), "x2", &x2, NULL);
+ g_object_get (G_OBJECT (box), "y2", &y2, NULL);
+
+ x = (x2+x1)/2;
+ y = (y2+y1)/2;
+
+ item_nombre = gnome_canvas_item_new (root,
+ gnome_canvas_text_get_type (),
+ "text", texto,
+ "x", (x2+x1)/2,
+ "y", (y2+y1)/2 + 5 ,
+ "font", "Sans 28",
+ "anchor", GTK_ANCHOR_N,
+ "fill_color", "black",
+ NULL);
+
+ posTransicion->nombre = texto;
+
+ posTransicion->item_nombre = item_nombre;
+
+ }
+ else {
+ if (posNodo->nombre != "")
+ gtk_object_destroy (GTK_OBJECT (posNodo->item_nombre));
+
+ g_object_get (G_OBJECT (item), "x1", &x1, NULL);
+ g_object_get (G_OBJECT (item), "y1", &y1, NULL);
+ g_object_get (G_OBJECT (item), "x2", &x2, NULL);
+ g_object_get (G_OBJECT (item), "y2", &y2, NULL);
+
+
+ x = (x2+x1)/2;
+ y = (y2+y1)/2;
+
+ item_nombre = gnome_canvas_item_new (GNOME_CANVAS_GROUP(item->parent),
+ gnome_canvas_text_get_type (),
+ "text", texto,
+ "x", (x2+x1)/2,
+ "y", (y2+y1)/2,
+ "font", "Sans 28",
+ "anchor", GTK_ANCHOR_CENTER,
+ "fill_color", "black",
+ NULL);
+
+
+ posNodo->nombre = texto;
+
+ posNodo->item_nombre = item_nombre;
+
+ }
+
+ gnome_canvas_item_raise_to_top (item_nombre);
+
+ gtk_widget_destroy (gtk_widget_get_toplevel(GTK_WIDGET(button)));
+
+
+
+}
+
+
+GtkWidget * new_name_windows (GnomeCanvasItem *item)
+{
+ GladeXML *xml;
+ GtkWidget *win; /*Main window*/
+ GtkWidget *botonAplicar, *botonCancelar;
+
+ //GladeInterface *inter;
+
+ /*Inicializamos Glade*/
+ glade_init();
+
+ /*Cargamos fichero .Glade donde esta guardada la estructura de la nueva ventana*/
+ xml = glade_xml_new("gui/nombre.glade", NULL, NULL);
+
+ if (xml == NULL)
+ {
+ printf ("NO");
+ return 0;
+ }
+
+ /*Cargamos la nueva ventana*/
+ win = glade_xml_get_widget(xml, "nombre");
+
+ /*Conectamos Señales*/
+ //glade_xml_signal_autoconnect(xml);
+
+ /*Ponemos Titulo a la ventana*/
+ gtk_window_set_title(GTK_WINDOW(win), "Nombrar elemento");
+
+
+ //xml = glade_get_widget_tree (win);
+
+ /*Cargamos el boton*/
+ botonCancelar = glade_xml_get_widget(xml, "BotonCancelar");
+ botonAplicar = glade_xml_get_widget(xml, "BotonAplicar");
+
+ /*Asignamos item*/
+ g_object_set_data (G_OBJECT (botonAplicar), "item", item);
+ g_object_set_data (G_OBJECT (win), "item", item);
+
+ /*Asignamos Señal al boton*/
+ //g_signal_connect (G_OBJECT (botonAplicar), "clicked", G_CALLBACK (on_button_clicked), NULL);
+ g_signal_connect (G_OBJECT (botonAplicar), "clicked", G_CALLBACK (aplicar), 0);
+
+ //g_signal_connect (G_OBJECT (botonCancelar), "clicked", G_CALLBACK (restaurar_color), 0);
+
+ g_signal_connect (G_OBJECT (botonCancelar), "clicked", G_CALLBACK (destroy), 0);
+
+ g_signal_connect (G_OBJECT (win), "destroy", G_CALLBACK (restaurar_color),0);
+
+ g_signal_connect (G_OBJECT (win), "destroy", G_CALLBACK (eliminar_ventana),0);
+
+
+ GtkWidget *entry = glade_xml_get_widget(xml, "entry1");
+
+ g_object_set_data (G_OBJECT (botonAplicar), "entry", entry);
+
+
+ /* */
+ list<tNodo>::iterator posNodo;
+ list<tTransicion>::iterator posTransicion;
+
+ posNodo = ListaElementos.begin();
+
+ color = 3;
+
+ while( (posNodo != ListaElementos.end()) && (posNodo->item != item) )
+ posNodo++;
+
+ if (posNodo == ListaElementos.end()){
+
+ posTransicion = ListaTransiciones.begin();
+
+ while( (posTransicion != ListaTransiciones.end()) && (posTransicion->item != item) )
+ posTransicion++;
+
+ gtk_entry_set_text(GTK_ENTRY(entry), posTransicion->nombre.c_str());
+
+ color = 7;
+ }else
+ gtk_entry_set_text(GTK_ENTRY(entry), posNodo->nombre.c_str());
+
+
+
+ gtk_widget_show_all(win);
+
+
+ return win;
+
+}
+
+
+
+
+void cambiar_a (GtkWidget *widget, gpointer data){
+
+ GtkWidget *tiempo = GTK_WIDGET (g_object_get_data (G_OBJECT (widget), "frameN"));
+ GtkWidget *texto = GTK_WIDGET (g_object_get_data (G_OBJECT (widget), "frameT"));
+ //gint width, height;
+
+ if (strcmp((gchar *)data, "texto")==0){
+
+ gtk_widget_show (GTK_WIDGET (texto));
+
+ gtk_widget_hide (GTK_WIDGET (tiempo));
+
+ //width = (gint) (g_object_get_data (G_OBJECT (gtk_widget_get_toplevel(widget)), "width"));
+ //height = (gint) (g_object_get_data (G_OBJECT (gtk_widget_get_toplevel(widget)), "height"));
+
+ //gtk_window_resize (GTK_WINDOW(gtk_widget_get_toplevel(widget)),width,height);
+
+ // //GtkWidget *windowAux = gtk_window_new(GTK_WINDOW_POPUP);
+
+ // //gtk_widget_set_tooltip_window (GTK_WIDGET (tiempo), GTK_WINDOW(windowAux));
+ // //window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ }
+ else{
+ gtk_widget_show (GTK_WIDGET (tiempo));
+
+ gtk_widget_hide (GTK_WIDGET (texto));
+
+ //gtk_window_get_size (GTK_WINDOW(gtk_widget_get_toplevel(widget)),&width, &height);
+
+ //g_object_set_data (G_OBJECT (gtk_widget_get_toplevel(widget)), "width", (gpointer)width);
+ //g_object_set_data (G_OBJECT (gtk_widget_get_toplevel(widget)), "height", (gpointer)height);
+
+ //gtk_window_resize (GTK_WINDOW(gtk_widget_get_toplevel(widget)),250,1);
+ }
+
+}
+
+void aceptar (GtkWidget *widget, gpointer data)
+{
+ GtkTextIter start, end;
+ GtkSourceBuffer *sBuf;
+ GnomeCanvasItem *item;
+ const char * texto;
+
+
+ if (strcmp((gchar*)data, "variables")==0) {
+
+
+ sBuf = GTK_SOURCE_BUFFER (g_object_get_data (G_OBJECT (widget), "bufferVar"));
+ gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER(sBuf), &start);
+ gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER(sBuf), &end);
+ texto = gtk_text_buffer_get_text (GTK_TEXT_BUFFER(sBuf), &start, &end, true);
+ variables = texto;
+
+ sBuf = GTK_SOURCE_BUFFER (g_object_get_data (G_OBJECT (widget), "bufferFun"));
+ gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER(sBuf), &start);
+ gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER(sBuf), &end);
+ texto = gtk_text_buffer_get_text (GTK_TEXT_BUFFER(sBuf), &start, &end, true);
+ funciones = texto;
+
+
+
+ }else{
+ item = GNOME_CANVAS_ITEM (g_object_get_data (G_OBJECT (widget), "item"));
+
+ if (strcmp((gchar*)data, "estado")==0) {
+ sBuf = GTK_SOURCE_BUFFER (g_object_get_data (G_OBJECT (widget), "buffer"));
+ //gtk_text_buffer_get_selection_bounds (textbuffer, &start, &end);
+
+ gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER(sBuf), &start);
+
+ gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER(sBuf), &end);
+
+ texto = gtk_text_buffer_get_text (GTK_TEXT_BUFFER(sBuf), &start, &end, true);
+
+
+
+ list<tNodo>::iterator pos;
+
+ pos = ListaElementos.begin();
+
+ while( (pos != ListaElementos.end()) & (pos->item != item) )
+ {
+ pos++;
+ }
+ pos->codigo = texto;
+
+ //change_item_color (item, 3);
+ }else if (strcmp((gchar*)data, "transicion")==0) {
+ list<tTransicion>::iterator pos;
+
+ pos = ListaTransiciones.begin();
+
+ while( (pos != ListaTransiciones.end()) & (pos->item != item) )
+ {
+ pos++;
+ }
+
+ GtkWidget *toggle_button = GTK_WIDGET (g_object_get_data (G_OBJECT (widget), "rbTiempo"));
+
+ if (GTK_TOGGLE_BUTTON (toggle_button)->active){
+ GtkWidget *entry = GTK_WIDGET (g_object_get_data (G_OBJECT (widget), "entryTemp"));
+
+ texto = gtk_entry_get_text(GTK_ENTRY(entry));
+
+ pos->tiempo = atoi(texto);
+ pos->codigo = "";
+
+ }else{
+ GtkWidget *entry = GTK_WIDGET (g_object_get_data (G_OBJECT (widget), "entryCond"));
+
+ texto = gtk_entry_get_text(GTK_ENTRY(entry));
+
+ pos->codigo = texto;
+ pos->tiempo = -1;
+ }
+
+ //change_item_color (get_box (item), 7);
+ }
+ }
+
+ gtk_widget_destroy (gtk_widget_get_toplevel(GTK_WIDGET(widget)));
+ //g_signal_emit_by_name (GTK_OBJECT (window), "delete_event");
+
+}
+
+GtkWidget * new_text_windows (GnomeCanvasItem *item, gchar *type)
+{
+ GladeXML *xml;
+ GtkWidget *win; /*Main window*/
+ GtkWidget *botonAceptar, *botonCancelar, *toggle_button_texto, *toggle_button_tiempo, *entry;
+
+ /*SourveView variables*/
+ GtkWidget *pScrollWin, *sView;
+ PangoFontDescription *font_desc;
+ GtkSourceLanguageManager *lm;
+ GtkSourceBuffer *sBuf;
+ GtkSourceLanguage *language = NULL;
+
+ //GladeInterface *inter;
+
+ /*Inicializamos Glade*/
+ glade_init();
+
+ /*Cargamos fichero .Glade donde esta guardada la estructura de la nueva ventana*/
+ if (strcmp((const char *)type, "transicion") == 0){
+ xml=glade_xml_new("gui/EdicionTransicion.glade", NULL, NULL);
+
+ if (xml == NULL)
+ {
+ printf ("NO");
+ return 0;
+ }
+ /*Conectamos Señales*/
+
+ win = glade_xml_get_widget(xml, "window1");
+
+ /*Ponemos Titulo a la ventana*/
+ gtk_window_set_title(GTK_WINDOW(win), "Código Transicion ");
+
+ g_signal_connect (G_OBJECT (glade_xml_get_widget(xml,"rbTexto")), "released", G_CALLBACK (cambiar_a), (gpointer)"texto");
+
+ g_object_set_data (G_OBJECT (glade_xml_get_widget(xml,"rbTexto")), "frameN", glade_xml_get_widget(xml, "frameN"));
+ g_object_set_data (G_OBJECT (glade_xml_get_widget(xml,"rbTexto")), "frameT", glade_xml_get_widget(xml, "frameT"));
+
+ g_signal_connect (G_OBJECT (glade_xml_get_widget(xml,"rbTiempo")), "released", G_CALLBACK (cambiar_a), (gpointer)"tiempo");
+
+ g_object_set_data (G_OBJECT (glade_xml_get_widget(xml,"rbTiempo")), "frameN", glade_xml_get_widget(xml, "frameN"));
+ g_object_set_data (G_OBJECT (glade_xml_get_widget(xml,"rbTiempo")), "frameT", glade_xml_get_widget(xml, "frameT"));
+
+ }else {
+ xml=glade_xml_new("gui/EdicionNodo.glade", NULL, NULL);
+
+ if (xml == NULL)
+ {
+ printf ("NO");
+ return 0;
+ }
+
+ /*Cargamos la nueva ventana*/
+ win = glade_xml_get_widget(xml, "dialog1");
+
+ /*Ponemos Titulo a la ventana*/
+ gtk_window_set_title(GTK_WINDOW(win), "Código Estado");
+
+ /*Cargamos el boton*/
+ //GtkWidget *numero = glade_xml_get_widget(xml, "button1");
+
+
+
+
+ /*Conectamos Señales*/
+ glade_xml_signal_autoconnect(xml);
+
+ /*Situamos la ventana en el medio*/
+ //gtk_window_set_position(GTK_WINDOW(win), GTK_WIN_POS_CENTER);
+
+ /*** Incorporar GtkSourceView ***/
+
+ pScrollWin = glade_xml_get_widget(xml, "scrolledwindow");
+
+ /* Now create a GtkSourceLanguagesManager */
+ lm = gtk_source_language_manager_new();
+
+ /* and a GtkSourceBuffer to hold text (similar to GtkTextBuffer) */
+ sBuf = GTK_SOURCE_BUFFER (gtk_source_buffer_new (NULL));
+
+ /* Create the GtkSourceView and associate it with the buffer */
+ sView = gtk_source_view_new_with_buffer(sBuf);
+ gtk_source_view_set_show_line_numbers ((GtkSourceView*)sView, TRUE);
+
+ /* Set default Font name,size */
+ font_desc = pango_font_description_from_string ("mono 10");
+ gtk_widget_modify_font (sView, font_desc);
+ pango_font_description_free (font_desc);
+
+ /* get the Language for C source mimetype */
+// language = gtk_source_languages_manager_get_language_from_mime_type (lm,"text/x-c++src");
+ language = gtk_source_language_manager_get_language(lm, "text/x-c++src");
+ if (language == NULL)
+ {
+ g_print ("No language found for mime type `%s'\n", "text/x-c++src");
+ g_object_set (G_OBJECT (sBuf), "highlight", FALSE, NULL);
+ }
+ else
+ {
+ gtk_source_buffer_set_language (sBuf, language);
+ g_object_set (G_OBJECT (sBuf), "highlight", TRUE, NULL);
+ }
+
+ /* Attach the GtkSourceView to the scrolled Window */
+ gtk_container_add (GTK_CONTAINER (glade_xml_get_widget(xml, "scrolledwindow")), sView);
+
+
+ }
+ /* Attach the GtkSourceView to the scrolled Window */
+ //if (strcmp((const char *)type, "transicion") == 0)
+ // gtk_container_add (GTK_CONTAINER (glade_xml_get_widget(xml, "frameT")), sView);
+ //else
+ // gtk_container_add (GTK_CONTAINER (glade_xml_get_widget(xml, "scrolledwindow")), sView);
+
+ /*Cargamos el boton*/
+ botonCancelar = glade_xml_get_widget(xml, "cancelar");
+ botonAceptar = glade_xml_get_widget(xml,"aceptar");
+
+ /*Asignamos elementos*/
+ g_object_set_data (G_OBJECT (botonAceptar), "item", item);
+ g_object_set_data (G_OBJECT (win), "item", item);
+
+ /*Asignamos Señal al boton*/
+ g_signal_connect (G_OBJECT (botonAceptar), "clicked", G_CALLBACK (aceptar), type);
+ //g_signal_connect (G_OBJECT (botonCancelar), "clicked", G_CALLBACK (restaurar_color), 0);
+ g_signal_connect (G_OBJECT (botonCancelar), "clicked", G_CALLBACK (destroy), 0);
+ g_signal_connect (G_OBJECT (win), "destroy", G_CALLBACK (restaurar_color),0);
+ g_signal_connect (G_OBJECT (win), "destroy", G_CALLBACK (eliminar_ventana),0);
+
+ /* Visualizamo la ventana y establecemos el tamaño de la ventana*/
+ //gtk_window_set_position(GTK_WINDOW(win),GTK_WIN_POS_CENTER);
+ gtk_widget_show_all(win);
+ //gtk_window_resize (GTK_WINDOW(win),640,480);
+ //g_object_set_data (G_OBJECT (win), "width", (gpointer)640);
+ //g_object_set_data (G_OBJECT (win), "height", (gpointer)480);
+
+ //gtk_window_move (GTK_WINDOW(win), (gdk_screen_width ()/2) - (640/2), (gdk_screen_height ()/2) - (480/2));
+ /* Cargamos Texto */
+
+ if (strcmp(type, "estado")==0){
+
+
+ list<tNodo>::iterator pos;
+
+ pos = ListaElementos.begin();
+
+ while(pos->item != item)
+ pos++;
+
+ color = 3;
+
+ if (pos->codigo != ""){
+ gtk_source_buffer_begin_not_undoable_action (sBuf);
+ gtk_text_buffer_set_text (GTK_TEXT_BUFFER(sBuf), pos->codigo.c_str(), (int)pos->codigo.length());
+ gtk_source_buffer_end_not_undoable_action (sBuf);
+ }
+
+ /*Asignamos elementos*/
+ g_object_set_data (G_OBJECT (botonAceptar), "buffer", sBuf);
+ }
+ else if (strcmp(type, "transicion")==0){
+ list<tTransicion>::iterator pos;
+
+ pos = ListaTransiciones.begin();
+
+ while(pos->item != item)
+ pos++;
+
+ color = 7;
+
+ GtkWidget *numero = glade_xml_get_widget(xml, "frameN");
+ GtkWidget *texto = glade_xml_get_widget(xml, "frameT");
+
+ gtk_widget_show (GTK_WIDGET (texto));
+ gtk_widget_hide (GTK_WIDGET (numero));
+
+
+ toggle_button_tiempo = glade_xml_get_widget(xml, "rbTiempo");
+ g_object_set_data (G_OBJECT (botonAceptar), "rbTiempo", toggle_button_tiempo);
+
+ toggle_button_texto = glade_xml_get_widget(xml, "rbTexto");
+ g_object_set_data (G_OBJECT (botonAceptar), "rbTexto", toggle_button_texto);
+
+ entry = glade_xml_get_widget(xml, "entry1");
+ g_object_set_data (G_OBJECT (botonAceptar), "entryTemp", entry);
+
+ entry = glade_xml_get_widget(xml, "entryCond");
+ g_object_set_data (G_OBJECT (botonAceptar), "entryCond", entry);
+
+ if (pos->codigo != "")
+ gtk_entry_set_text(GTK_ENTRY(glade_xml_get_widget(xml, "entryCond")), pos->codigo.c_str());
+
+ if (pos->tiempo != -1){
+
+ gtk_widget_show (GTK_WIDGET (numero));
+ gtk_widget_hide (GTK_WIDGET (texto));
+
+ GTK_TOGGLE_BUTTON (toggle_button_tiempo)->active = true;
+
+ GTK_TOGGLE_BUTTON (toggle_button_texto)->active = false;
+
+ gtk_entry_set_text(GTK_ENTRY(glade_xml_get_widget(xml, "entry1")), int2string(pos->tiempo).c_str());
+
+ gtk_window_resize (GTK_WINDOW(win),250,1);
+
+ }
+
+ }else{
+ return false;
+ }
+
+ //gtk_widget_show_all(win);
+
+ //glade_xml_signal_autoconnect(xml);
+
+ return win;
+}
+
+GtkSourceBuffer *crear_source_view (GtkWidget * scroll)
+{
+ /*SourveView variables*/
+ GtkWidget *sView;
+ PangoFontDescription *font_desc;
+ GtkSourceLanguageManager *lm;
+ GtkSourceBuffer *sBuf;
+ GtkSourceLanguage *language = NULL;
+
+ /*** GtkSourceView ***/
+
+ /* Now create a GtkSourceLanguagesManager */
+ lm = gtk_source_language_manager_new();
+
+ /* and a GtkSourceBuffer to hold text (similar to GtkTextBuffer) */
+ sBuf = GTK_SOURCE_BUFFER (gtk_source_buffer_new (NULL));
+
+ /* Create the GtkSourceView and associate it with the buffer */
+ sView = gtk_source_view_new_with_buffer(sBuf);
+ gtk_source_view_set_show_line_numbers ((GtkSourceView*)sView, TRUE);
+
+ /* Set default Font name,size */
+ font_desc = pango_font_description_from_string ("mono 10");
+ gtk_widget_modify_font (sView, font_desc);
+ pango_font_description_free (font_desc);
+
+ /* get the Language for C source mimetype */
+ //language = gtk_source_languages_manager_get_language_from_mime_type (lm,"text/x-c++src");
+ language = gtk_source_language_manager_get_language(lm, "text/x-c++src");
+ if (language == NULL)
+ {
+ g_print ("No language found for mime type `%s'\n", "text/x-c++src");
+ g_object_set (G_OBJECT (sBuf), "highlight", FALSE, NULL);
+ }
+ else
+ {
+ gtk_source_buffer_set_language (sBuf, language);
+ g_object_set (G_OBJECT (sBuf), "highlight", TRUE, NULL);
+ }
+
+ /* Attach the GtkSourceView to the scrolled Window */
+ gtk_container_add (GTK_CONTAINER (scroll), sView);
+
+ return sBuf;
+
+}
+
+GtkWidget * new_code_windows ()
+{
+ GladeXML *xml;
+ GtkWidget *win; /*Main window*/
+ GtkWidget *pScrollWinVar, *pScrollWinFun;
+ GtkSourceBuffer *sBufVar, *sBufFun;
+ GtkWidget *botonAceptar, *botonCancelar;
+
+ xml = glade_xml_new("gui/variables.glade", NULL, NULL);
+
+ if (xml == NULL)
+ {
+ printf ("NO");
+ return 0;
+ }
+
+ /*Cargamos la nueva ventana*/
+ win = glade_xml_get_widget(xml, "dialog1");
+
+ /*Conectamos Señales*/
+ glade_xml_signal_autoconnect(xml);
+
+ /*Ponemos Titulo a la ventana*/
+ gtk_window_set_title(GTK_WINDOW(win), "Código Componente");
+
+ /*Situamos la ventana en el medio*/
+ gtk_window_set_position(GTK_WINDOW(win), GTK_WIN_POS_CENTER);
+
+ /* scrolled Window */
+
+ pScrollWinVar = glade_xml_get_widget(xml, "scrolledwindowV");
+ pScrollWinFun = glade_xml_get_widget(xml, "scrolledwindowF");
+
+ sBufVar = crear_source_view (pScrollWinVar);
+ sBufFun = crear_source_view (pScrollWinFun);
+
+ /*Añadimos texto variables a la ventana*/
+ gtk_text_buffer_set_text (GTK_TEXT_BUFFER(sBufVar), variables.c_str(), (int)variables.length());
+ gtk_text_buffer_set_text (GTK_TEXT_BUFFER(sBufFun), funciones.c_str(), (int)funciones.length());
+
+ /*Cargamos el boton*/
+ botonCancelar = glade_xml_get_widget(xml, "cancelar");
+ botonAceptar = glade_xml_get_widget(xml,"aceptar");
+
+ /*Asignamos elementos*/
+ g_object_set_data (G_OBJECT (botonAceptar), "bufferVar", sBufVar);
+ g_object_set_data (G_OBJECT (botonAceptar), "bufferFun", sBufFun);
+
+ /*Asignamos Señal al boton*/
+ g_signal_connect (G_OBJECT (botonCancelar), "clicked", G_CALLBACK (aceptar), (gchar *)"variables");
+ g_signal_connect (G_OBJECT (botonAceptar), "clicked", G_CALLBACK (aceptar), (gchar *)"variables");
+ //NO hace falta asignar esta señal. Ya esta la señal asignada al crear la ventana con glade*/
+ //g_signal_connect (G_OBJECT (botonCancelar), "clicked", G_CALLBACK (destroy), 0);
+
+ g_signal_connect (G_OBJECT (win), "destroy", G_CALLBACK (eliminar_ventana),0);
+
+
+ /*Asignamos Señal al boton*/
+// g_signal_connect (G_OBJECT (glade_xml_get_widget(prog,"aceptar")), "clicked", G_CALLBACK (aceptar), (gchar *)"variables");
+
+ /*NO hace falta asignar esta señal. Ya esta la señal asignada al crear la ventana con glade*/
+ //g_signal_connect (G_OBJECT (glade_xml_get_widget(prog,"aceptar")), "destroy", G_CALLBACK (cancelar), (gpointer)win);
+
+ gtk_widget_show_all(win);
+
+ return win;
+}
+
+void
+set_importar(GtkButton *button, gpointer data){
+
+ GladeXML *xml = GLADE_XML (g_object_get_data (G_OBJECT (button), "xml"));
+ // Actualizamos
+ GtkWidget *toggle_button = glade_xml_get_widget(xml, "cbLaser");
+
+ imp.laser = GTK_TOGGLE_BUTTON (toggle_button)->active;
+
+ toggle_button = glade_xml_get_widget(xml, "cbMotor");
+
+ imp.motor = GTK_TOGGLE_BUTTON (toggle_button)->active;
+
+ toggle_button = glade_xml_get_widget(xml, "cbRadar");
+
+ imp.radar = GTK_TOGGLE_BUTTON (toggle_button)->active;
+
+ toggle_button = glade_xml_get_widget(xml, "cbEncoders");
+
+ imp.encoders = GTK_TOGGLE_BUTTON (toggle_button)->active;
+
+ toggle_button = glade_xml_get_widget(xml, "cbLat_lon");
+
+ imp.lat_lon = GTK_TOGGLE_BUTTON (toggle_button)->active;
+
+ toggle_button = glade_xml_get_widget(xml, "cbCamara");
+
+ imp.camara = GTK_TOGGLE_BUTTON (toggle_button)->active;
+
+ toggle_button = glade_xml_get_widget(xml, "cbPtencoders");
+
+ imp.ptencoders = GTK_TOGGLE_BUTTON (toggle_button)->active;
+
+
+ gtk_widget_destroy (gtk_widget_get_toplevel(GTK_WIDGET(button)));
+ //gtk_widget_destroy(GTK_WIDGET(data));
+}
+
+GtkWidget *
+importar_librerias(){
+
+ GladeXML *xml;
+ GtkWidget *win; /*Main window*/
+
+ //GladeInterface *inter;
+
+ /*Inicializamos Glade*/
+ glade_init();
+
+ /*Cargamos fichero .Glade donde esta guardada la estructura de la nueva ventana*/
+ xml=glade_xml_new("gui/Importar.glade", NULL, NULL);
+
+ if (xml == NULL)
+ {
+ printf ("NO");
+ return NULL;
+ }
+
+ /*Cargamos la nueva ventana*/
+ win = glade_xml_get_widget(xml, "window1");
+
+ /*Conectamos Señales*/
+ glade_xml_signal_autoconnect(xml);
+
+// g_signal_connect (G_OBJECT (glade_xml_get_widget(prog,"button1")),
+ // "clicked", G_CALLBACK (gtk_main_quit), NULL);
+
+ /*Ponemos Titulo a la ventana*/
+ gtk_window_set_title(GTK_WINDOW(win), "Actuadores y Sensores");
+
+ /*Situamos la ventana en el medio*/
+ gtk_window_set_position(GTK_WINDOW(win), GTK_WIN_POS_CENTER);
+
+
+ /*Cargamos el boton*/
+ GtkWidget *botonAceptar = glade_xml_get_widget(xml, "aceptar");
+ GtkWidget *botonCancelar = glade_xml_get_widget(xml, "cancelar");
+
+ g_signal_connect (G_OBJECT (botonAceptar), "clicked", G_CALLBACK (set_importar),(gpointer)win);
+ g_signal_connect (G_OBJECT (botonCancelar), "clicked", G_CALLBACK (destroy), 0);
+ g_signal_connect (G_OBJECT (win), "destroy", G_CALLBACK (eliminar_ventana),0);
+
+ /*Asignamos elementos*/
+ g_object_set_data (G_OBJECT (botonAceptar), "xml", xml);
+
+
+ // Actualizamos
+ GtkWidget *toggle_button = glade_xml_get_widget(xml, "cbLaser");
+
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_button), imp.laser);
+
+ toggle_button = glade_xml_get_widget(xml, "cbMotor");
+
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_button), imp.motor);
+
+ toggle_button = glade_xml_get_widget(xml, "cbRadar");
+
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_button), imp.radar);
+
+ toggle_button = glade_xml_get_widget(xml, "cbEncoders");
+
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_button), imp.encoders);
+
+ toggle_button = glade_xml_get_widget(xml, "cbLat_lon");
+
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_button), imp.lat_lon);
+
+ toggle_button = glade_xml_get_widget(xml, "cbCamara");
+
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_button), imp.camara);
+
+ toggle_button = glade_xml_get_widget(xml, "cbPtencoders");
+
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle_button), imp.ptencoders);
+
+ gtk_widget_show_all(win);
+
+ return win;
+}
+
+
+void set_timer (GtkWindow *button, gpointer data){
+
+ GtkWidget *entry = GTK_WIDGET (g_object_get_data (G_OBJECT (button), "entry"));
+
+ const char *texto = gtk_entry_get_text(GTK_ENTRY(entry));
+
+ tiempoIteracion = atoi(texto);
+
+ /* Nombre asignado
+ * Para cerrar la ventana, y dejar el estado del canvas como estaba, llamamos a la funcion cancelar con la ventana como parámetro,
+ * o emitimos una señal "clicked" por el boton cancelar. */
+
+
+ //cancelar (window, data2);
+
+ //gtk_signal_emit (GTK_OBJECT (data2), "clicked");
+ gtk_widget_destroy (gtk_widget_get_toplevel(GTK_WIDGET(button)));
+ //g_signal_emit_by_name (GTK_OBJECT ((GtkWidget *)data), "clicked");
+}
+
+GtkWidget *
+tiempo_iteracion(){
+
+ GladeXML *xml;
+ GtkWidget *win; /*Main window*/
+
+ //GladeInterface *inter;
+
+ /*Inicializamos Glade*/
+ glade_init();
+
+ /*Cargamos fichero .Glade donde esta guardada la estructura de la nueva ventana*/
+ xml=glade_xml_new("gui/timer.glade", NULL, NULL);
+
+ if (xml == NULL)
+ {
+ printf ("NO");
+ return NULL;
+ }
+
+ /*Cargamos la nueva ventana*/
+ win = glade_xml_get_widget(xml, "timer");
+
+ /*Conectamos Señales*/
+ glade_xml_signal_autoconnect(xml);
+
+ /*Ponemos Titulo a la ventana*/
+ gtk_window_set_title(GTK_WINDOW(win), "Tiempo iteracion componente");
+
+ prog = glade_get_widget_tree (win);
+
+ /*Cargamos el boton*/
+ GtkWidget *botonAceptar = glade_xml_get_widget(xml, "BotonAplicar");
+ GtkWidget *botonCancelar = glade_xml_get_widget(xml, "BotonCancelar");
+ //GtkWidget *button = glade_xml_get_widget(xml, "BotonCancelar");
+
+ /*Asignamos Señal al boton*/
+ g_signal_connect (G_OBJECT (botonAceptar), "clicked", G_CALLBACK (set_timer), (gpointer)botonCancelar);
+ g_signal_connect (G_OBJECT (botonCancelar), "clicked", G_CALLBACK (destroy), 0);
+ g_signal_connect (G_OBJECT (win), "destroy", G_CALLBACK (eliminar_ventana),0);
+
+// g_signal_connect (G_OBJECT (glade_xml_get_widget(xml,"BotonCancelar")), "clicked", G_CALLBACK (cancelar), (gpointer)win);
+
+ GtkWidget *entry = glade_xml_get_widget(xml, "entry1");
+
+ /*Asignamos elementos*/
+ g_object_set_data (G_OBJECT (botonAceptar), "entry", entry);
+
+ gtk_entry_set_text(GTK_ENTRY(entry), int2string(tiempoIteracion).c_str());
+
+ gtk_widget_show_all(win);
+
+
+ return win;
+
+
+}
+
+void eliminar_ventana (GtkWidget *ventana, gpointer data)
+{
+ list<nVentana>::iterator posVentana;
+
+ posVentana = ListaVentanas.begin();
+ printf ("VENTANA: %d \n", (int)posVentana->ventana);
+ while( (posVentana != ListaVentanas.end()) && (posVentana->ventana != ventana) )
+ posVentana++;
+
+ if (posVentana != ListaVentanas.end())
+ ListaVentanas.erase(posVentana);
+
+}
+
+void add_ventana (GtkWidget *ventana, GnomeCanvasItem * item, tVentana tipo)
+{
+
+ nVentana nodo;
+
+ nodo.ventana = ventana;
+ nodo.item = item;
+ nodo.tipo = tipo;
+
+ ListaVentanas.push_back (nodo);
+}
+
+
+GtkWidget * comprobar_ventana_abierta (GnomeCanvasItem * item, tVentana tipo)
+{
+ list<nVentana>::iterator posVentana;
+
+ posVentana = ListaVentanas.begin();
+
+ while( posVentana != ListaVentanas.end() ){
+ if ((posVentana->tipo == tipo) && (posVentana->item == item))
+ return posVentana->ventana;
+ else
+ posVentana++;
+ }
+
+ return NULL;
+
+
+}
+
+
+/* Función útil a la hora de cambiar el color de relleno de un item
+ * del canvas aleatoriamente
+ */
+void change_item_color (GnomeCanvasItem *item, int color)
+{
+ static const char *color_specs[] = {
+ "red",
+ "yellow",
+ "green",
+ "cyan",
+ "blue",
+ "magenta",
+ "orange",
+ NULL
+ };
+
+ //int n;
+
+ //item_guardado = item;
+
+ /* Coge un color aleatoriamente de la lista */
+
+ //n = rand () % (sizeof (color_specs) / sizeof (color_specs[0]));
+
+ gnome_canvas_item_set (item,
+ "fill_color", color_specs[color],
+ NULL);
+}
Property changes on: trunk/src/components/visualHFSM-3.1/ventanas.cpp
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/src/components/visualHFSM-3.1/ventanas.h
===================================================================
--- trunk/src/components/visualHFSM-3.1/ventanas.h (rev 0)
+++ trunk/src/components/visualHFSM-3.1/ventanas.h 2013-03-10 13:05:56 UTC (rev 882)
@@ -0,0 +1,56 @@
+#ifndef VENTANAS_H
+#define VENTANAS_H
+
+#include <iostream>
+#include <list>
+#include <string.h>
+
+#include "transicion.h"
+#include "int2string.h"
+
+#include <gtk/gtk.h>
+#include <libgnomecanvas/libgnomecanvas.h>
+#include <libglade-2.0/glade/glade.h>
+
+#include <gtksourceview/gtksourceview.h>
+#include <gtksourceview/gtksourcebuffer.h>
+#include <gtksourceview/gtksourcelanguage.h>
+#include <gtksourceview/gtksourcelanguagemanager.h>
+
+#include "tipos.h"
+
+/****EDICION DE ESTADOS****/
+
+void cancelar (GtkWidget *widget, gpointer data);
+
+void aplicar (GtkButton *button, gpointer data);
+
+/* Cambiar nombre */
+GtkWidget * new_name_windows (GnomeCanvasItem *item);
+
+/* Edicion de elementos */
+GtkWidget * new_text_windows (GnomeCanvasItem *item, gchar *type);
+
+/****EDICION DEL ESQUEMA****/
+GtkWidget * new_code_windows ();
+
+void set_importar(GtkButton *Button, gpointer data);
+GtkWidget * importar_librerias();
+
+void set_timer (GtkWindow *window, gpointer data);
+GtkWidget * tiempo_iteracion();
+
+/****LISTA VENTANAS****/
+
+void add_ventana (GtkWidget *ventana, GnomeCanvasItem * item, tVentana tipo);
+void eliminar_ventana (GtkWidget *ventana, gpointer data);
+
+/* Comprueba si la ventana correspondiente esta abierta */
+GtkWidget * comprobar_ventana_abierta (GnomeCanvasItem * item, tVentana tipo);
+
+
+/* Función útil a la hora de cambiar el color de relleno de un item
+ * del canvas aleatoriamente
+ */
+void change_item_color (GnomeCanvasItem *item, int color);
+#endif
Property changes on: trunk/src/components/visualHFSM-3.1/ventanas.h
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/src/components/visualHFSM-3.1/xml.cpp
===================================================================
--- trunk/src/components/visualHFSM-3.1/xml.cpp (rev 0)
+++ trunk/src/components/visualHFSM-3.1/xml.cpp 2013-03-10 13:05:56 UTC (rev 882)
@@ -0,0 +1,460 @@
+#include "xml.h"
+
+int cont_nodos = 0;
+//************************Añadida lista de subautomatas
+extern list <tSubAut> ListaSubAutomatas;
+//*****************************************************
+
+extern list <tNodo> ListaElementos;
+extern list <tTransicion> ListaTransiciones;
+extern list <transicion_aux> ListaTransicionesTemporales;
+
+extern string variables;
+extern string funciones;
+extern importar imp;
+extern int tiempoIteracion;
+
+extern string directorio;
+extern string nombreEsquema;
+
+extern GnomeCanvasGroup *root;
+
+extern GnomeCanvasItem *item_guardado; // item guardado para operaciones
+
+void actualizar_array_id (tId *array)
+{
+ list<tNodo>::iterator posNodo;
+
+ posNodo = ListaElementos.begin();
+
+ while(posNodo != ListaElementos.end()){
+ array[cont_nodos].id = cont_nodos;
+ array[cont_nodos].item = posNodo->item;
+ cont_nodos++;
+ posNodo++;
+ }
+
+
+}
+
+int posicion (GnomeCanvasItem *nodo)
+{
+ int cont = 1;
+ list<tNodo>::iterator posNodos;
+
+ posNodos = ListaElementos.begin();
+
+ while(posNodos->item != nodo){
+ cont++;
+ posNodos++;
+ }
+ return cont;
+}
+
+
+xmlDocPtr xml_new_doc (const gchar *name) {
+
+ xmlNodePtr root;
+ xmlDocPtr doc;
+
+ doc = xmlNewDoc ((const xmlChar*)"1.0");
+
+ root = xmlNewDocNode (doc, NULL, (const xmlChar*)name, NULL);
+
+ xmlDocSetRootElement (doc, root);
+
+ return doc;
+}
+
+void xml_new_entry (xmlDocPtr doc) {//****************Creado xml_new_entry_sub, trasladando el xml_new_entry original para cada uno de los subautomatas
+ //****************de ListaSubAutomatas
+
+ xmlNodePtr root;
+ xmlNodePtr nodeSub;
+ string cadena;
+ list<tSubAut>::iterator posNodoSub;
+
+ root = xmlDocGetRootElement (doc);
+
+
+ if (!ListaSubAutomatas.empty())
+ {
+ posNodoSub = ListaSubAutomatas.begin();
+
+ while( posNodoSub != ListaSubAutomatas.end())
+ {
+ /* nodo raiz */
+ nodeSub = xmlNewChild (root, NULL, (const xmlChar*)"SubAutomata", NULL);
+
+ cadena = int2string(posNodoSub->idSub);
+
+ xmlNewChild (nodeSub, NULL, (const xmlChar*)"idSub", (const xmlChar*)cadena.c_str());
+
+ cadena = int2string(posNodoSub->idPadre);
+
+ xmlNewChild (nodeSub, NULL, (const xmlChar*)"idPadre", (const xmlChar*)cadena.c_str());
+
+
+ //cargamos en las "listas globales" las listas del subautomata que estamos tratando, de este modo el procedimiento
+ //que habia antes para generar el xml a partir de esas listas puede seguir funcionando igual
+ ListaElementos = posNodoSub->ListaElementosSub;
+ ListaTransiciones = posNodoSub->ListaTransicionesSub;
+ tiempoIteracion = posNodoSub->tiempoIteracionSub;
+ variables = posNodoSub->variablesSub;
+ funciones = posNodoSub->funcionesSub;
+ imp = posNodoSub->impSub;
+
+
+ //Llamamos al procedimiento que habia antes para componer la estructura del xml
+ xml_new_entry_sub (doc, nodeSub);
+
+ posNodoSub++;
+
+ }
+
+ //cont_nodos = 0;//***************************************************************Comentado por mi rsb
+ }
+
+ xmlNewChild (root, NULL, (const xmlChar*)"nombreEsquema", (const xmlChar*)(directorio + nombreEsquema).c_str());
+
+}
+
+//Para componer cada subautomata
+void xml_new_entry_sub (xmlDocPtr doc, xmlNodePtr ptrSub) {
+
+ xmlNodePtr node, nodeTransicion, nodeTransiciones, nodeBox;
+ string cadena;
+ double x1, x2, y1, y2;
+ list<tNodo>::iterator posNodos;
+ list<GnomeCanvasItem *>::iterator posAdy;
+ list<tTransicion>::iterator posTransiciones;
+ GnomeCanvasItem *box;
+
+ if (!ListaElementos.empty())
+ {
+ posNodos = ListaElementos.begin();
+
+ while( posNodos != ListaElementos.end())
+ {
+ /* nodo raiz */
+ node = xmlNewChild (ptrSub, NULL, (const xmlChar*)"Estado", NULL);
+
+ if (posNodos->estado_inicial != NULL)
+ xmlSetProp (node, (const xmlChar*)"estado_inicial", (const xmlChar*)"true");
+ else
+ xmlSetProp (node, (const xmlChar*)"estado_inicial", (const xmlChar*)"false");
+
+ cadena = int2string(++cont_nodos);
+
+ xmlNewChild (node, NULL, (const xmlChar*)"id", (const xmlChar*)cadena.c_str());
+
+ /* Guardamos las coordenadas */
+ get_bounds (posNodos->item, &x1,&y1,&x2,&y2);
+
+ cadena = int2string(x1);
+
+ xmlNewChild (node, NULL, (const xmlChar*)"origenX", (const xmlChar*)cadena.c_str());
+
+ cadena = int2string(y1);
+
+ xmlNewChild (node, NULL, (const xmlChar*)"origenY", (const xmlChar*)cadena.c_str());
+
+ cadena = int2string(x2);
+
+ xmlNewChild (node, NULL, (const xmlChar*)"destinoX", (const xmlChar*)cadena.c_str());
+
+ cadena = int2string(y2);
+
+ xmlNewChild (node, NULL, (const xmlChar*)"destinoY", (const xmlChar*)cadena.c_str());
+
+ /* Guardamos el nombre */
+ xmlNewChild (node, NULL, (const xmlChar*)"nombre", (const xmlChar*)(char *)posNodos->nombre.c_str());
+
+ /*Guardamos el ID del hijo*/
+ //if (posNodos->idHijo != 0 )
+ cadena = int2string(posNodos->idHijo);
+ xmlNewChild (node, NULL, (const xmlChar*)"hijo", (const xmlChar*)(char *)cadena.c_str());
+
+ /* Guardamos el codigo del estado */
+ const xmlChar * code = xmlEncodeSpecialChars (doc, (const xmlChar*)posNodos->codigo.c_str()); // Parseamos el código por caracteres especiales.
+
+ xmlNewChild (node, NULL, (const xmlChar*)"codigo", code);
+
+ /* Guardamos las transiciones */
+ nodeTransiciones = xmlNewChild (node, NULL, (const xmlChar*)"transiciones", NULL);
+
+ posAdy = posNodos->listaAdyacentes.begin();
+
+ while( posAdy != posNodos->listaAdyacentes.end())
+ {
+ posTransiciones = ListaTransiciones.begin();
+
+ while( posTransiciones != ListaTransiciones.end())
+ {
+ if ((*posAdy == posTransiciones->item) & (posNodos->item == posTransiciones->origen))
+ {
+ nodeTransicion = xmlNewChild (nodeTransiciones, NULL, (const xmlChar*)"transicion", NULL);
+
+ /* Guardamos puntos Box */
+ box = get_box (posTransiciones->item);
+
+ get_bounds (box, &x1,&y1,&x2,&y2);
+
+ nodeBox = xmlNewChild (nodeTransicion, NULL, (const xmlChar*)"box", NULL);
+ xmlSetProp (nodeBox, (const xmlChar*)"x1", (const xmlChar*)int2string(x1).c_str());
+ xmlSetProp (nodeBox, (const xmlChar*)"y1", (const xmlChar*)int2string(y1).c_str());
+ xmlSetProp (nodeBox, (const xmlChar*)"x2", (const xmlChar*)int2string(x2).c_str());
+ xmlSetProp (nodeBox, (const xmlChar*)"y2", (const xmlChar*)int2string(y2).c_str());
+
+ xmlNewChild (nodeTransicion , NULL, (const xmlChar*)"nombre", (const xmlChar*)posTransiciones->nombre.c_str());
+
+ cadena = int2string(posicion(posTransiciones->destino));
+
+ xmlNewChild (nodeTransicion , NULL, (const xmlChar*)"destino", (const xmlChar*)cadena.c_str());
+
+ if (posTransiciones->codigo != ""){
+ code = xmlEncodeSpecialChars (doc, (const xmlChar*)posTransiciones->codigo.c_str()); // Parseamos el código por caracteres especiales.
+ xmlNewChild (nodeTransicion , NULL, (const xmlChar*)"codigo", code);
+ }else if (posTransiciones->tiempo != -1){
+ cadena = int2string(posTransiciones->tiempo);
+ xmlNewChild (nodeTransicion , NULL, (const xmlChar*)"tiempo", (const xmlChar*)cadena.c_str());
+ }
+ }
+ posTransiciones++;
+ }
+ posAdy++;
+ }
+ posNodos++;
+
+ }
+ cont_nodos = 0;
+ }
+
+ /* Guardamos datos del Subautomata */
+
+ cadena = int2string(tiempoIteracion);
+
+ xmlNewChild (ptrSub, NULL, (const xmlChar*)"tiempoIteracion", (const xmlChar*)cadena.c_str());
+
+ node = xmlNewChild (ptrSub, NULL, (const xmlChar*)"Librerias", NULL);
+
+ if (imp.laser)
+ xmlNewChild (node, NULL, (const xmlChar*)"lib", (const xmlChar*)"laser");
+ if (imp.motor)
+ xmlNewChild (node, NULL, (const xmlChar*)"lib", (const xmlChar*)"motor");
+ if (imp.radar)
+ xmlNewChild (node, NULL, (const xmlChar*)"lib", (const xmlChar*)"radar");
+ if (imp.encoders)
+ xmlNewChild (node, NULL, (const xmlChar*)"lib", (const xmlChar*)"encoders");
+ if (imp.lat_lon)
+ xmlNewChild (node, NULL, (const xmlChar*)"lib", (const xmlChar*)"lat_lon");
+ if (imp.camara)
+ xmlNewChild (node, NULL, (const xmlChar*)"lib", (const xmlChar*)"camara");
+ if (imp.ptencoders)
+ xmlNewChild (node, NULL, (const xmlChar*)"lib", (const xmlChar*)"ptencoders");
+
+ xmlNewChild (ptrSub, NULL, (const xmlChar*)"variables_aux", (const xmlChar*)variables.c_str());
+
+ xmlNewChild (ptrSub, NULL, (const xmlChar*)"funciones_aux", (const xmlChar*)funciones.c_str());
+
+}
+
+
+void xml_get_entry (xmlNodePtr child) {
+
+ tNodo figura;
+
+ GnomeCanvasItem *item, *item2;
+ GnomeCanvasGroup *group, *groupT;
+
+ double x1,x2,y1,y2;
+ //const xmlChar* str;
+ //const char* c_str;
+
+ xmlNodePtr node; //nodo pincipal
+ xmlNodePtr nodeT; //nodo transiciones
+
+ transicion_aux t;
+
+ list<transicion_aux>::iterator pos;
+
+ node = child->xmlChildrenNode;
+
+ int id= atoi((const char*)xmlNodeGetContent (node));
+
+ node = node->next;
+
+// str = xmlNodeGetContent (node);
+// c_str = (const char*)str;
+//
+// cout << "FIGURA: " << c_str << endl;
+// figura.figura = c_str;
+// node = node->next;
+
+ /* Cargamos Puntos Nodo */
+ x1= atoi((const char*)xmlNodeGetContent (node));
+ node = node->next;
+ y1 = atoi((const char*)xmlNodeGetContent (node));
+ node = node->next;
+ x2 = atoi((const char*)xmlNodeGetContent (node));
+ node = node->next;
+ y2 = atoi((const char*)xmlNodeGetContent (node));
+ node = node->next;
+
+ /* Cargamos Nombre y Código */
+ figura.nombre = (const char*)xmlNodeGetContent (node);
+ node = node->next;
+ figura.idHijo = atoi((const char*)xmlNodeGetContent (node));
+ node = node->next;
+ figura.codigo = (const char*)xmlNodeGetContent (node);
+ node = node->next;
+
+ group = GNOME_CANVAS_GROUP (gnome_canvas_item_new (root,
+ gnome_canvas_group_get_type (),
+ "x", 0,
+ "y", 0,
+ NULL));
+ if (figura.idHijo == 0) {
+
+ item = gnome_canvas_item_new(group,
+ gnome_canvas_ellipse_get_type(),
+ "x1", x1,
+ "y1", y1,
+ "x2", x2,
+ "y2", y2,
+ "fill_color_rgba", 0x00ffffff,
+ "outline_color", "black",
+ "width_units", 1.0,
+ NULL);
+
+ }
+ else{
+
+ item = gnome_canvas_item_new(group,
+ gnome_canvas_ellipse_get_type(),
+ "x1", x1,
+ "y1", y1,
+ "x2", x2,
+ "y2", y2,
+ "fill_color_rgba", 0x00ff66ff,
+ "outline_color", "black",
+ "width_units", 1.0,
+ NULL);
+
+ }
+
+ if ( strcmp((const char*)xmlGetProp (child, (const xmlChar*)"estado_inicial"), (const char*)"true") == 0 )
+ {
+ figura.estado_inicial = pinta_estado_inicial (group, item);
+ }
+ else
+ figura.estado_inicial = NULL;
+
+
+
+ if (figura.nombre != ""){
+ item2 = gnome_canvas_item_new (group,
+ gnome_canvas_text_get_type (),
+ "text", figura.nombre.c_str(),
+ "x", (x1 + x2)/2,
+ "y", (y1 + y2)/2,
+ "font", "Sans 28",
+ //"size", 32000,
+ //"size_set", (gboolean)TRUE,
+ //"scale", (gdouble) 3,
+ //"scale_set", (gboolean)TRUE,
+ "anchor", GTK_ANCHOR_CENTER,
+ "fill_color", "black",
+ NULL);
+
+ figura.item_nombre = item2;
+
+ }else{
+ figura.item_nombre = NULL;
+ }
+
+ // guardamos el primer item pintado, para asignarlo despues al destino de algunas transiciones.
+ if (item_guardado == NULL)
+ item_guardado = item;
+
+
+ /*Añadimos control (señal) al item creado*/
+ g_signal_connect (group, "event",
+ G_CALLBACK (item_event),
+ NULL);
+
+ //figura.id = (int)item;
+ figura.item = item;
+
+ if (node != NULL) {
+
+ nodeT = node->xmlChildrenNode;
+
+ while (nodeT != NULL)
+ {
+ t.origen = item;
+ t.destino = NULL;
+ cout << "ORIGEN: " << (int)item << endl;
+
+ /*Recuperamos Puntos Box*/
+ x1= atoi((const char*)xmlGetProp (nodeT->xmlChildrenNode, (const xmlChar*)"x1"));
+
+ y1 = atoi((const char*)xmlGetProp (nodeT->xmlChildrenNode, (const xmlChar*)"y1"));
+
+ x2 = atoi((const char*)xmlGetProp (nodeT->xmlChildrenNode, (const xmlChar*)"x2"));
+
+ y2 = atoi((const char*)xmlGetProp (nodeT->xmlChildrenNode, (const xmlChar*)"y2"));
+
+
+ groupT = GNOME_CANVAS_GROUP (gnome_canvas_item_new (root,
+ gnome_canvas_group_get_type (),
+ "x", 0,
+ "y", 0,
+ NULL));
+
+ create_drag_box (groupT, (char *)"box", (x1+x2)/2, (y1+y2)/2, G_CALLBACK (highlight_box));
+ t.item = GNOME_CANVAS_ITEM(groupT);
+
+ t.nombre = (const char*)xmlNodeGetContent (nodeT->xmlChildrenNode->next);
+
+ t.destino_id = atoi((const char*)xmlNodeGetContent (nodeT->xmlChildrenNode->next->next));
+ cout << "Destino ID: " << t.destino_id << endl;
+
+ if (nodeT->xmlChildrenNode->next->next->next != NULL){
+ if (strcmp((const char*)nodeT->xmlChildrenNode->next->next->next->name,"tiempo") == 0){
+ t.tiempo = atoi((const char*)xmlNodeGetContent (nodeT->xmlChildrenNode->next->next->next));
+ t.codigo = (const char*)"";
+ }
+ else if(strcmp((const char*)nodeT->xmlChildrenNode->next->next->next->name,"codigo") == 0) {
+ t.tiempo = -1;
+ t.codigo = (const char*)xmlNodeGetContent (nodeT->xmlChildrenNode->next->next->next);
+ }
+ }else{
+ t.tiempo = -1;
+ t.codigo = "";
+ }
+ t.origen_xml = id;
+
+ ListaTransicionesTemporales.push_back(t);
+
+ /* añadimos transicion adyacente */
+ //figura.listaAdyacentes.push_back(GNOME_CANVAS_ITEM(groupT));
+
+ nodeT = nodeT->next;
+
+ }
+ }
+
+ pos = ListaTransicionesTemporales.begin();
+
+ while (pos != ListaTransicionesTemporales.end())
+ {
+ if (id == pos->destino_id)
+ pos->destino = item;
+
+ pos++;
+ }
+
+ ListaElementos.push_back(figura);
+
+}
Property changes on: trunk/src/components/visualHFSM-3.1/xml.cpp
___________________________________________________________________
Added: svn:executable
+ *
Added: trunk/src/components/visualHFSM-3.1/xml.h
===================================================================
--- trunk/src/components/visualHFSM-3.1/xml.h (rev 0)
+++ trunk/src/components/visualHFSM-3.1/xml.h 2013-03-10 13:05:56 UTC (rev 882)
@@ -0,0 +1,41 @@
+#ifndef XML_H
+#define XML_H
+
+#include <iostream>
+#include <string>
+#include <list>
+#include <string.h>
+
+//#include "nodo.h"
+#include "transicion.h"
+//#include "ventanas.h"
+#include "int2string.h"
+
+#include "interfaz.h"
+
+
+#include <libxml/tree.h>
+
+
+typedef struct tipoId {
+
+ int id;
+ GnomeCanvasItem * item;
+
+} tId;
+
+
+
+void actualizar_array_id (tId *array);
+
+/* crea la estructura xmlDoc con nodo raiz "name" */
+xmlDocPtr xml_new_doc (const gchar *name);
+
+/* Guarda la informaicon en un xml del esquema */
+void xml_new_entry (xmlDocPtr doc);
+void xml_new_entry_sub (xmlDocPtr doc, xmlNodePtr ptrSub);
+
+/* Recupera la informacion de un estado y lo representa en el canvas */
+void xml_get_entry (xmlNodePtr child);
+
+#endif
Property changes on: trunk/src/components/visualHFSM-3.1/xml.h
___________________________________________________________________
Added: svn:executable
+ *
More information about the Jderobot-admin
mailing list