TinkerCell Core 1.0
TinkerCell's Core library providing all basic functionalities
C_API_Slots.cpp
Go to the documentation of this file.
00001 #include <QCoreApplication>
00002 #include <QInputDialog>
00003 #include <QDesktopServices>
00004 #include "C_API_Slots.h"
00005 #include "ItemHandle.h"
00006 #include "TextEditor.h"
00007 #include "NetworkHandle.h"
00008 #include "GraphicsScene.h"
00009 #include "GraphicsView.h"
00010 #include "NodeGraphicsItem.h"
00011 #include "ConnectionGraphicsItem.h"
00012 #include "TextGraphicsItem.h"
00013 #include "ItemHandle.h"
00014 #include "Tool.h"
00015 #include "MainWindow.h"
00016 #include "CThread.h"
00017 #include "MultithreadedSliderWidget.h"
00018 #include "ConsoleWindow.h"
00019 #include "AbstractInputWindow.h"
00020 #include "plugins/TextParser.h"
00021 #include "UndoCommands.h"
00022 #include "GlobalSettings.h"
00023 #include "Ontology.h"
00024 
00025 namespace Tinkercell
00026 {
00027         Core_FtoS * C_API_Slots::fToS = 0;
00028         
00029         C_API_Slots::C_API_Slots(MainWindow * main) : mainWindow(main), getStringDialog(0)
00030         { 
00031                 C_API_Slots::fToS = new Core_FtoS;
00032                 C_API_Slots::fToS->setParent(this);
00033                 connect(mainWindow,SIGNAL(setupFunctionPointers( QLibrary * )),this,SLOT(setupFunctionPointers( QLibrary * )));
00034                 connect(mainWindow,SIGNAL(escapeSignal(const QWidget*)),this,SLOT(escapeSlot(const QWidget*)));
00035                 connect(this,SIGNAL(saveNetwork(const QString&)), mainWindow, SIGNAL(saveNetwork(const QString&)));
00036                 connectTCFunctions();
00037         }
00038         
00039         ConsoleWindow * C_API_Slots::console() const
00040         {
00041                 if (mainWindow)
00042                         return mainWindow->console();
00043                 return 0;
00044         }
00045         
00046         NetworkHandle * C_API_Slots::currentNetwork() const
00047         {
00048                 if (mainWindow)
00049                         return mainWindow->currentNetwork();
00050                 return 0;
00051         }
00052         
00053         GraphicsScene * C_API_Slots::currentScene() const
00054         {
00055                 if (mainWindow)
00056                         return mainWindow->currentScene();
00057                 return 0;
00058         }
00059 
00060         typedef void (*main_api_func)(
00061                 tc_items (*tc_allItems0)(),
00062                 tc_items (*tc_selectedItems0)(),
00063                 tc_items (*tc_itemsOfFamily0)(const char*),
00064                 tc_items (*tc_itemsOfFamily1)(const char*, tc_items),
00065                 long (*tc_find0)(const char*),
00066                 tc_items (*tc_findItems0)(tc_strings),
00067                 tc_items (*tc_findItemsUsingRegex0)(const char*),
00068                 void (*tc_select0)(long),
00069                 void (*tc_deselect0)(),
00070                 const char* (*tc_getName0)(long),
00071                 const char* (*tc_getUniqueName0)(long),
00072                 void (*tc_setName0)(long item,const char* name),
00073                 tc_strings (*tc_getNames0)(tc_items),
00074                 tc_strings (*tc_getUniqueNames0)(tc_items),
00075                 const char* (*tc_getFamily0)(long),
00076                 int (*tc_isA0)(long,const char*),
00077 
00078                 void (*tc_clearText)(),
00079                 void (*tc_outputText0)(const char*),
00080                 void (*tc_errorReport0)(const char*),
00081                 void (*tc_outputTable0)(tc_matrix),
00082                 void (*tc_printFile0)(const char*),
00083 
00084                 void (*tc_removeItem0)(long),
00085                 long (*tc_insertItem0)(const char*, const char*),
00086                 long (*insertConnection)(tc_items, const char*, const char*),
00087                 tc_items (*getConnectedNodes)(long),
00088                 tc_items (*getConnections)(long),
00089 
00090                 double (*tc_getY0)(long),
00091                 double (*tc_getX0)(long),
00092 
00093                 tc_matrix (*tc_getPos0)(tc_items),
00094                 void (*tc_setPos0)(long,double,double),
00095 
00096                 void (*tc_setPos1)(tc_items,tc_matrix),
00097 
00098                 void (*tc_moveSelected0)(double,double),
00099 
00100                 int (*tc_isWindows0)(),
00101                 int (*tc_isMac0)(),
00102                 int (*tc_isLinux0)(),
00103                 const char* (*tc_appDir0)(),
00104                 const char* (*tc_homeDir0)(),
00105                 
00106                 void (*tc_createInputWindow0)(tc_matrix,const char*,const char*),
00107         void (*tc_createInputWindow1)(long, tc_matrix, const char*, void (*f)(tc_matrix)),
00108                 void (*createSliders)(long, tc_matrix, void (*f)(tc_matrix)),
00109                 
00110                 void (*tc_addInputWindowOptions0)(const char*, int i, int j, tc_strings),
00111                 void (*tc_addInputWindowCheckbox0)(const char*, int i, int j),
00112                 void (*tc_openNewWindow0)(const char * title),
00113                 
00114                 tc_items (*tc_getChildren0)(long),
00115                 long (*tc_getParent0)(long),
00116         
00117                 tc_matrix (*tc_getNumericalData0)(long,const char*),
00118                 void (*tc_setNumericalData0)(long,const char*,tc_matrix),
00119                 tc_table (*tc_getTextData0)(long,const char*),
00120                 void (*tc_setTextData0)(long,const char*, tc_table),
00121                                 
00122                 tc_strings (*tc_getNumericalDataNames0)(long),
00123                 tc_strings (*tc_getTextDataNames0)(long),
00124                 
00125                 void (*tc_zoom0)(double factor),
00126                 void (*tc_viewWindow0)(const char*),
00127 
00128                 const char* (*getString)(const char*),
00129                 int (*getSelectedString)(const char*, tc_strings, const char*),
00130                 double (*getNumber)(const char*),
00131                 tc_matrix (*getNumbers)( tc_strings),
00132                 const char* (*getFilename)(),
00133                 
00134                 int (*askQuestion)(const char*),
00135                 void (*messageDialog)(const char*),
00136                 void (*openFile)(const char*),
00137                 void (*saveToFile)(const char*),
00138                 
00139                 void (*setSize)(long,double,double,int),
00140                 double (*getWidth)(long),
00141                 double (*getHeight)(long),
00142                 void (*setAngle)(long,double,int),
00143                 const char* (*getColor)(long),
00144                 void (*setColor)(long,const char*,int),
00145                 
00146                 void (*changeGraphics)(long,const char*),
00147                 void (*changeArrowHead)(long,const char*),
00148                 
00149                 void (*screenshot)(const char*, int, int),
00150                 int (*screenWidth)(),
00151                 int (*screenHeight)(),
00152                 int (*screenX)(),
00153                 int (*screenY)(),
00154                 
00155                 const char * (*annotations)(),
00156                 void (*insertAnno)(const char *, double, double),
00157                 
00158                 void (*setNumericalValues)(tc_matrix),
00159                 void (*setNumericalValue)(const char *, double),
00160                 void (*setTextValues)(tc_table),
00161                 void (*setTextValue)(const char *, const char *),
00162                 
00163                 double (*getNumericalValue)(const char*),
00164                 const char* (*getTextValue)(const char*),
00165 
00166                 tc_matrix (*getNumericalValueRegexp)(const char*),
00167                 tc_table (*getTextValueRegexp)(const char*),
00168                 
00169                 void (*openUrl)(const char*),
00170                 
00171                 double (*getControlPointX)(long,long,int),
00172                 double (*getControlPointY)(long,long,int),
00173                 void (*setControlPoint)(long,long,int,double,double),
00174                 void (*setCenterPoint)(long,double,double),
00175                 double (*getCenterPointX)(long),
00176                 double (*getCenterPointY)(long),
00177                 void (*setStraight)(long,int),
00178                 void (*setAllStraight)(int),
00179                 void (*setLineWidth)(long,double,int)
00180         );
00181         
00182         void C_API_Slots::setupFunctionPointers(QLibrary * library)
00183         {
00184                 main_api_func f = (main_api_func)library->resolve("tc_Main_api_initialize");
00185                 if (f)
00186                 {
00187                         f(
00188                                 &(_allItems),
00189                                 &(_selectedItems),
00190                                 &(_itemsOfFamily),
00191                                 &(_itemsOfFamily2),
00192                                 &(_find),
00193                                 &(_findItems),
00194                                 &(_findItemsUsingRegex),
00195                                 &(_select),
00196                                 &(_deselect),
00197                                 &(_getName),
00198                                 &(_getUniqueName),
00199                                 &(_setName),
00200                                 &(_getNames),
00201                                 &(_getUniqueNames),
00202                                 &(_getFamily),
00203                                 &(_isA),
00204                                 &(_clearText),
00205                                 &(_outputText),
00206                                 &(_errorReport),
00207                                 &(_outputTable),
00208                                 &(_printFile),
00209                                 &(_removeItem),
00210                                 &(_insertItem),
00211                                 &(_insertConnection),
00212                                 &(_getConnectedNodes),
00213                                 &(_getConnections),
00214                                 &(_getY),
00215                                 &(_getX),
00216                                 &(_getPos),
00217                                 &(_setPos),
00218                                 &(_setPos2),
00219                                 &(_moveSelected),
00220                                 &(_isWindows),
00221                                 &(_isMac),
00222                                 &(_isLinux),
00223                                 &(_appDir),
00224                                 &(_homeDir),
00225                                 &(_createInputWindow1),
00226                                 &(_createInputWindow2),
00227                                 &(_createSliders),
00228                                 &(_addInputWindowOptions),
00229                                 &(_addInputWindowCheckbox),
00230                                 &(_openNewWindow),
00231                                 &(_getChildren),
00232                                 &(_getParent),
00233                                 &(_getNumericalData),
00234                                 &(_setNumericalData),
00235                                 &(_getTextData),
00236                                 &(_setTextData),
00237                                 &(_getNumericalDataNames),
00238                                 &(_getTextDataNames),
00239                                 &(_zoom),
00240                                 &(_viewWindow),
00241                                 &(_getString),
00242                                 &(_getSelectedString),
00243                                 &(_getNumber),
00244                                 &(_getNumbers),
00245                                 &(_getFilename),
00246                                 &(_askQuestion),
00247                                 &(_messageDialog),
00248                                 &(_openFile),
00249                                 &(_saveToFile),
00250                                 &(_setSize),
00251                                 &(_getWidth),
00252                                 &(_getHeight),
00253                                 &(_setAngle),
00254                                 &(_getColor),
00255                                 &(_setColor),
00256                                 &(_changeGraphics),
00257                                 &(_changeArrowHead),
00258                                 &(_screenshot),
00259                                 &(_screenWidth),
00260                                 &(_screenHeight),
00261                                 &(_screenX),
00262                                 &(_screenY),
00263                                 &(_annotations),
00264                                 &(_insertAnnotation),
00265                                 &(_setNumericalValues),
00266                                 &(_setNumericalValue),
00267                                 &(_setTextValues),
00268                                 &(_setTextValue),
00269                                 &(_getNumericalValue),
00270                                 &(_getTextValue),
00271                                 &(_getNumericalValueUsingRegex),
00272                                 &(_getTextValueUsingRegex),
00273                                 &(_openUrl),
00274                                 &(_getControlPointX),
00275                                 &(_getControlPointY),
00276                                 &(_setControlPoint),
00277                                 &(_setCenterPoint),
00278                                 &(_getCenterPointX),
00279                                 &(_getCenterPointY),
00280                                 &(_setStraight),
00281                                 &(_setAllStraight),
00282                                 &(_setLineWidth)
00283                         );
00284                 }
00285         }
00286         
00287         void C_API_Slots::connectTCFunctions()
00288         {
00289                 connect(fToS,SIGNAL(find(QSemaphore*,ItemHandle**,const QString&)),this,SLOT(findItem(QSemaphore*,ItemHandle**,const QString&)));
00290                 connect(fToS,SIGNAL(findItems(QSemaphore*,QList<ItemHandle*>*,const QStringList&)),
00291                                 this,SLOT(findItems(QSemaphore*,QList<ItemHandle*>*,const QStringList&)));
00292                 connect(fToS,SIGNAL(findItemsUsingRegex(QSemaphore*,QList<ItemHandle*>*,const QString&)),
00293                                 this,SLOT(findItemsUsingRegex(QSemaphore*,QList<ItemHandle*>*,const QString&)));
00294 
00295                 connect(fToS,SIGNAL(select(QSemaphore*,ItemHandle*)),this,SLOT(select(QSemaphore*,ItemHandle*)));
00296                 connect(fToS,SIGNAL(deselect(QSemaphore*)),this,SLOT(deselect(QSemaphore*)));
00297                 connect(fToS,SIGNAL(allItems(QSemaphore*,QList<ItemHandle*>*)),this,SLOT(allItems(QSemaphore*,QList<ItemHandle*>*)));
00298                 connect(fToS,SIGNAL(selectedItems(QSemaphore*,QList<ItemHandle*>*)),this,SLOT(selectedItems(QSemaphore*,QList<ItemHandle*>*)));
00299                 connect(fToS,SIGNAL(itemsOfFamily(QSemaphore*,QList<ItemHandle*>*,const QString&)),this,SLOT(itemsOfFamily(QSemaphore*,QList<ItemHandle*>*,const QString&)));
00300                 connect(fToS,SIGNAL(itemsOfFamily(QSemaphore*,QList<ItemHandle*>*,const QList<ItemHandle*>&, const QString&)),this,SLOT(itemsOfFamily(QSemaphore*,QList<ItemHandle*>*,const QList<ItemHandle*>&, const QString&)));
00301                 connect(fToS,SIGNAL(getX(QSemaphore*,qreal*,ItemHandle*)),this,SLOT(getX(QSemaphore*,qreal*,ItemHandle*)));
00302                 connect(fToS,SIGNAL(getY(QSemaphore*,qreal*,ItemHandle*)),this,SLOT(getY(QSemaphore*,qreal*,ItemHandle*)));
00303 
00304                 connect(fToS,SIGNAL(setPos(QSemaphore*,ItemHandle*,qreal,qreal)),this,SLOT(setPos(QSemaphore*,ItemHandle*,qreal,qreal)));
00305                 connect(fToS,SIGNAL(setPos(QSemaphore*,const QList<ItemHandle*>&,DataTable<qreal>&)),this,SLOT(setPos(QSemaphore*,const QList<ItemHandle*>&,DataTable<qreal>&)));
00306                 connect(fToS,SIGNAL(getPos(QSemaphore*,const QList<ItemHandle*>&,DataTable<qreal>*)),this,SLOT(getPos(QSemaphore*,const QList<ItemHandle*>&,DataTable<qreal>*)));
00307 
00308                 connect(fToS,SIGNAL(removeItem(QSemaphore*,ItemHandle*)),this,SLOT(removeItem(QSemaphore*,ItemHandle*)));
00309                 connect(fToS,SIGNAL(insertItem(QSemaphore*,ItemHandle**,const QString&,const QString&)),this,SLOT(insertItem(QSemaphore*,ItemHandle**,const QString&,const QString&)));
00310                 connect(fToS,SIGNAL(insertConnection(QSemaphore*,ItemHandle**,const QList<ItemHandle*>&,const QString&, const QString&)),
00311                         this,SLOT(insertConnection(QSemaphore*,ItemHandle**,const QList<ItemHandle*>&,const QString&, const QString&)));
00312 
00313                 connect(fToS,SIGNAL(getConnectedNodes(QSemaphore*,QList<ItemHandle*>*,ItemHandle*)),
00314                         this,SLOT(getConnectedNodes(QSemaphore*,QList<ItemHandle*>*,ItemHandle*)));
00315 
00316                 connect(fToS,SIGNAL(getConnections(QSemaphore*,QList<ItemHandle*>*,ItemHandle*)),
00317                         this,SLOT(getConnections(QSemaphore*,QList<ItemHandle*>*,ItemHandle*)));
00318 
00319                 connect(fToS,SIGNAL(moveSelected(QSemaphore*,qreal,qreal)),this,SLOT(moveSelected(QSemaphore*,qreal,qreal)));
00320                 connect(fToS,SIGNAL(getName(QSemaphore*,QString*,ItemHandle*)),this,SLOT(itemName(QSemaphore*,QString*,ItemHandle*)));
00321                 connect(fToS,SIGNAL(getUniqueName(QSemaphore*,QString*,ItemHandle*)),this,SLOT(uniqueName(QSemaphore*,QString*,ItemHandle*)));
00322                 connect(fToS,SIGNAL(setName(QSemaphore*,ItemHandle*,const QString&)),this,SLOT(setName(QSemaphore*,ItemHandle*,const QString&)));
00323 
00324                 connect(fToS,SIGNAL(getNames(QSemaphore*,QStringList*,const QList<ItemHandle*>&)),this,SLOT(itemNames(QSemaphore*,QStringList*,const QList<ItemHandle*>&)));
00325                 connect(fToS,SIGNAL(getUniqueNames(QSemaphore*,QStringList*,const QList<ItemHandle*>&)),this,SLOT(uniqueNames(QSemaphore*,QStringList*,const QList<ItemHandle*>&)));
00326                 connect(fToS,SIGNAL(getFamily(QSemaphore*,QString*,ItemHandle*)),this,SLOT(itemFamily(QSemaphore*,QString*,ItemHandle*)));
00327                 connect(fToS,SIGNAL(isA(QSemaphore*,int*,ItemHandle*,const QString&)),this,SLOT(isA(QSemaphore*,int*,ItemHandle*,const QString&)));
00328                 connect(fToS,SIGNAL(clearText(QSemaphore*)),this,SLOT(clearText(QSemaphore*)));
00329                 connect(fToS,SIGNAL(outputText(QSemaphore*,const QString&)),this,SLOT(outputText(QSemaphore*,const QString&)));
00330                 connect(fToS,SIGNAL(errorReport(QSemaphore*,const QString&)),this,SLOT(errorReport(QSemaphore*,const QString&)));
00331                 connect(fToS,SIGNAL(printFile(QSemaphore*,const QString&)),this,SLOT(printFile(QSemaphore*,const QString&)));
00332                 connect(fToS,SIGNAL(outputTable(QSemaphore*,const DataTable<qreal>&)),this,SLOT(outputTable(QSemaphore*,const DataTable<qreal>&)));
00333 
00334                 connect(fToS,SIGNAL(createInputWindow(QSemaphore*,const DataTable<qreal>&,const QString&,const QString&)),
00335                         this,SLOT(createInputWindow(QSemaphore*,const DataTable<qreal>&,const QString&,const QString&)));
00336 
00337                 connect(fToS,SIGNAL(createInputWindow(QSemaphore*,long, const DataTable<qreal>&,const QString&,MatrixInputFunction)),
00338                         this,SLOT(createInputWindow(QSemaphore*,long, const DataTable<qreal>&,const QString&,MatrixInputFunction)));
00339                 
00340                 connect(fToS,SIGNAL(createSliders(QSemaphore*,CThread*,const DataTable<qreal>&,MatrixInputFunction)),
00341                         this,SLOT(createSliders(QSemaphore*,CThread*,const DataTable<qreal>&,MatrixInputFunction)));
00342 
00343                 connect(fToS,SIGNAL(addInputWindowOptions(QSemaphore*,const QString&, int, int, const QStringList&)),
00344                         this,SLOT(addInputWindowOptions(QSemaphore*,const QString&, int, int, const QStringList&)));
00345 
00346                 connect(fToS,SIGNAL(addInputWindowCheckbox(QSemaphore*,const QString&, int, int)),
00347                         this,SLOT(addInputWindowCheckbox(QSemaphore*,const QString&, int, int)));
00348 
00349                 connect(fToS,SIGNAL(openNewWindow(QSemaphore*,const QString&)),this,SLOT(openNewWindow(QSemaphore*,const QString&)));
00350                 connect(fToS,SIGNAL(isWindows(QSemaphore*,int*)),this,SLOT(isWindows(QSemaphore*,int*)));
00351                 connect(fToS,SIGNAL(isMac(QSemaphore*,int*)),this,SLOT(isMac(QSemaphore*,int*)));
00352                 connect(fToS,SIGNAL(isLinux(QSemaphore*,int*)),this,SLOT(isLinux(QSemaphore*,int*)));
00353                 connect(fToS,SIGNAL(appDir(QSemaphore*,QString*)),this,SLOT(appDir(QSemaphore*,QString*)));
00354                 connect(fToS,SIGNAL(homeDir(QSemaphore*,QString*)),this,SLOT(homeDir(QSemaphore*,QString*)));
00355                 connect(fToS,SIGNAL(getChildren(QSemaphore*,QList<ItemHandle*>*,ItemHandle*)),this,SLOT(getChildren(QSemaphore*,QList<ItemHandle*>*,ItemHandle*)));
00356                 connect(fToS,SIGNAL(getParent(QSemaphore*,ItemHandle**,ItemHandle*)),this,SLOT(getParent(QSemaphore*,ItemHandle**,ItemHandle*)));
00357 
00358                 connect(fToS,SIGNAL(getNumericalData(QSemaphore*,DataTable<qreal>*,ItemHandle*,const QString&)),this,SLOT(getNumericalData(QSemaphore*,DataTable<qreal>*,ItemHandle*,const QString&)));
00359                 connect(fToS,SIGNAL(setNumericalData(QSemaphore*,ItemHandle*,const QString&,const DataTable<qreal>&)),this,SLOT(setNumericalData(QSemaphore*,ItemHandle*,const QString&,const DataTable<qreal>&)));
00360                 connect(fToS,SIGNAL(getTextData(QSemaphore*,DataTable<QString>*,ItemHandle*,const QString&)),this,SLOT(getTextData(QSemaphore*,DataTable<QString>*,ItemHandle*,const QString&)));
00361                 connect(fToS,SIGNAL(setTextData(QSemaphore*,ItemHandle*,const QString&,const DataTable<QString>&)),this,SLOT(setTextData(QSemaphore*,ItemHandle*,const QString&,const DataTable<QString>&)));
00362 
00363                 connect(fToS,SIGNAL(getTextDataNames(QSemaphore*,QStringList*,ItemHandle*)),this,SLOT(getTextDataNames(QSemaphore*,QStringList*,ItemHandle*)));
00364                 connect(fToS,SIGNAL(getNumericalDataNames(QSemaphore*,QStringList*,ItemHandle*)),this,SLOT(getNumericalDataNames(QSemaphore*,QStringList*,ItemHandle*)));
00365 
00366                 connect(fToS,SIGNAL(zoom(QSemaphore*,qreal)),this,SLOT(zoom(QSemaphore*,qreal)));
00367                 connect(fToS,SIGNAL(viewWindow(QSemaphore*,const QString&)),this,SLOT(viewWindow(QSemaphore*,const QString&)));
00368 
00369                 connect(fToS,SIGNAL(getString(QSemaphore*,QString*,const QString&)),this,SLOT(getString(QSemaphore*,QString*,const QString&)));
00370         connect(fToS,SIGNAL(getSelectedString(QSemaphore*,int*,const QString&,const QStringList&,const QString&)),this,SLOT(getSelectedString(QSemaphore*,int*,const QString&,const QStringList&,const QString&)));
00371         connect(fToS,SIGNAL(getNumber(QSemaphore*,qreal*,const QString&)),this,SLOT(getNumber(QSemaphore*,qreal*,const QString&)));
00372         connect(fToS,SIGNAL(getNumbers(QSemaphore*,const QStringList&,DataTable<qreal>*)),this,SLOT(getNumbers(QSemaphore*,const QStringList&,DataTable<qreal>*)));
00373         connect(fToS,SIGNAL(getFilename(QSemaphore*,QString*)),this,SLOT(getFilename(QSemaphore*,QString*)));
00374 
00375                 connect(fToS,SIGNAL(askQuestion(QSemaphore*,const QString&, int*)),this,SLOT(askQuestion(QSemaphore*,const QString&, int*)));
00376                 connect(fToS,SIGNAL(messageDialog(QSemaphore*,const QString&)),this,SLOT(messageDialog(QSemaphore*,const QString&)));
00377                 connect(fToS,SIGNAL(openFile(QSemaphore*,const QString&)),this,SLOT(openFile(QSemaphore*,const QString&)));
00378                 connect(fToS,SIGNAL(saveToFile(QSemaphore*,const QString&)),this,SLOT(saveToFile(QSemaphore*,const QString&)));
00379 
00380                 connect(fToS,SIGNAL(setSize(QSemaphore*, ItemHandle*,double,double,int)),this,SLOT(setSize(QSemaphore*, ItemHandle*,double,double,int)));
00381                 connect(fToS,SIGNAL(getWidth(QSemaphore*, ItemHandle*, double*)),this,SLOT(getWidth(QSemaphore*, ItemHandle*, double*)));
00382                 connect(fToS,SIGNAL(getHeight(QSemaphore*, ItemHandle*,double*)),this,SLOT(getHeight(QSemaphore*, ItemHandle*,double*)));
00383                 connect(fToS,SIGNAL(setAngle(QSemaphore*, ItemHandle*,double,int)),this,SLOT(setAngle(QSemaphore*, ItemHandle*,double,int)));
00384                 
00385                 connect(fToS,SIGNAL(getColor(QSemaphore*,QString*,ItemHandle*)),this,SLOT(getColor(QSemaphore*,QString*,ItemHandle*)));
00386                 connect(fToS,SIGNAL(setColor(QSemaphore*,ItemHandle*,const QString&,int)),this,SLOT(setColor(QSemaphore*,ItemHandle*,const QString&,int)));
00387                 connect(fToS,SIGNAL(changeGraphics(QSemaphore*,ItemHandle*,const QString&)),this,SLOT(changeGraphics(QSemaphore*,ItemHandle*,const QString&)));
00388                 connect(fToS,SIGNAL(changeArrowHead(QSemaphore*,ItemHandle*,const QString&)),this,SLOT(changeArrowHead(QSemaphore*,ItemHandle*,const QString&)));
00389 
00390                 connect(fToS,SIGNAL(screenshot(QSemaphore*, const QString&, int, int)),this,SLOT(screenshot(QSemaphore*, const QString&, int, int)));
00391                 connect(fToS,SIGNAL(screenHeight(QSemaphore*, int*)),this,SLOT(screenHeight(QSemaphore*, int*)));
00392                 connect(fToS,SIGNAL(screenWidth(QSemaphore*, int*)),this,SLOT(screenWidth(QSemaphore*, int*)));
00393                 connect(fToS,SIGNAL(screenX(QSemaphore*, int*)),this,SLOT(screenX(QSemaphore*, int*)));
00394                 connect(fToS,SIGNAL(screenY(QSemaphore*, int*)),this,SLOT(screenY(QSemaphore*, int*)));
00395                 
00396                 connect(fToS,SIGNAL(annotations(QSemaphore*, QString*)),this,SLOT(annotations(QSemaphore*, QString*)));
00397                 connect(fToS,SIGNAL(insertAnnotation(QSemaphore*, const QString&, double, double)),this,SLOT(insertAnnotation(QSemaphore*, const QString&, double, double)));
00398                 
00399                 connect(fToS,SIGNAL(setNumericalValues(QSemaphore*, const DataTable<qreal>&)),this,SLOT(setNumericalValues(QSemaphore*, const DataTable<qreal>&)));
00400                 connect(fToS,SIGNAL(setNumericalValue(QSemaphore*, const QString&, double)),this,SLOT(setNumericalValue(QSemaphore*, const QString&, double)));
00401                 connect(fToS,SIGNAL(setTextValues(QSemaphore*, const TextDataTable&)),this,SLOT(setTextValues(QSemaphore*, const TextDataTable&)));
00402                 connect(fToS,SIGNAL(setTextValue(QSemaphore*, const QString&, const QString&)),this,SLOT(setTextValue(QSemaphore*, const QString&, const QString&)));
00403                 
00404                 connect(fToS,SIGNAL(getNumericalValue(QSemaphore*, const QString&, double*)),this,SLOT(getNumericalValue(QSemaphore*, const QString&, double*)));
00405                 connect(fToS,SIGNAL(getTextValue(QSemaphore*, const QString&, QString*)),this,SLOT(getTextValue(QSemaphore*, const QString&, QString*)));
00406 
00407                 connect(fToS,SIGNAL(getNumericalValueUsingRegex(QSemaphore*,const QString&, DataTable<qreal>*)),
00408                                         this,SLOT(getNumericalValueUsingRegex(QSemaphore*,const QString&, DataTable<qreal>*)));
00409 
00410                 connect(fToS,SIGNAL(getTextValueUsingRegex(QSemaphore*,const QString&, DataTable<QString>*)),
00411                                         this,SLOT(getTextValueUsingRegex(QSemaphore*,const QString&, DataTable<QString>*)));
00412 
00413                 
00414                 connect(fToS,SIGNAL(getControlPointX(QSemaphore*,qreal*,ItemHandle*,ItemHandle*,int)),
00415                         this,SLOT(getControlPointX(QSemaphore*,qreal*,ItemHandle*,ItemHandle*,int)));
00416 
00417                 connect(fToS,SIGNAL(getControlPointY(QSemaphore*,qreal*,ItemHandle*,ItemHandle*,int)),
00418                         this,SLOT(getControlPointY(QSemaphore*,qreal*,ItemHandle*,ItemHandle*,int)));
00419 
00420                 connect(fToS,SIGNAL(setControlPoint(QSemaphore*,ItemHandle*,ItemHandle*,int,qreal,qreal)),
00421                         this,SLOT(setControlPoint(QSemaphore*,ItemHandle*,ItemHandle*,int,qreal,qreal)));
00422 
00423                 connect(fToS,SIGNAL(getCenterPointX(QSemaphore*,qreal*,ItemHandle*)),
00424                         this,SLOT(getCenterPointX(QSemaphore*,qreal*,ItemHandle*)));
00425 
00426                 connect(fToS,SIGNAL(getCenterPointY(QSemaphore*,qreal*,ItemHandle*)),
00427                         this,SLOT(getCenterPointY(QSemaphore*,qreal*,ItemHandle*)));
00428 
00429                 connect(fToS,SIGNAL(setCenterPoint(QSemaphore*,ItemHandle*,qreal,qreal)),
00430                         this,SLOT(setCenterPoint(QSemaphore*,ItemHandle*,qreal,qreal)));
00431 
00432                 connect(fToS,SIGNAL(setStraight(QSemaphore*,ItemHandle*,int)),
00433                         this,SLOT(setStraight(QSemaphore*,ItemHandle*,int)));
00434 
00435                 connect(fToS,SIGNAL(setAllStraight(QSemaphore*,int)),
00436                         this,SLOT(setAllStraight(QSemaphore*,int)));
00437 
00438                 connect(fToS,SIGNAL(setLineWidth(QSemaphore*,ItemHandle*,qreal,int)),
00439                         this,SLOT(setLineWidth(QSemaphore*,ItemHandle*,qreal,int)));
00440         }
00441         
00442         void C_API_Slots::zoom(QSemaphore* sem, qreal factor)
00443         {
00444                 if (currentScene())
00445                 {
00446                         currentScene()->zoom(factor);
00447                 }
00448                 if (sem)
00449                         sem->release();
00450         }
00451 
00452         void C_API_Slots::viewWindow(QSemaphore* sem, const QString& s)
00453         {
00454                 if (mainWindow)
00455                 {
00456                         QWidget * widget = mainWindow->tool(s);
00457                         if (widget)
00458                         {
00459                                 while (widget->parentWidget() && widget->parentWidget() != mainWindow)
00460                                         widget = widget->parentWidget();
00461 
00462                                 widget->show();
00463                         }
00464                 }
00465                 if (sem)
00466                         sem->release();
00467         }
00468 
00469         void C_API_Slots::clearText(QSemaphore* sem)
00470         {
00471             if (console())
00472             console()->clear();
00473                 if (sem)
00474                         sem->release();
00475         }
00476 
00477         void C_API_Slots::outputText(QSemaphore* sem,const QString& text)
00478         {
00479                 if (console())
00480             console()->message(text);
00481                 if (sem)
00482                         sem->release();
00483         }
00484 
00485         void C_API_Slots::errorReport(QSemaphore* sem,const QString& text)
00486         {
00487                 if (console())
00488             console()->error(text);
00489                 if (sem)
00490                         sem->release();
00491         }
00492 
00493         void C_API_Slots::printFile(QSemaphore* sem,const QString& filename)
00494         {
00495                 QString appDir = QCoreApplication::applicationDirPath();
00496 
00497                 QString name[] = {
00498                         GlobalSettings::tempDir() + tr("/") + filename,
00499                         GlobalSettings::homeDir() + tr("/") + filename,
00500                         filename,
00501                         QDir::currentPath() + tr("/") + filename,
00502                         appDir + tr("/") + filename };
00503 
00504                 QFile file;
00505                 bool opened = false;
00506                 for (int i=0; i < 5; ++i)
00507                 {
00508                         file.setFileName(name[i]);
00509                         if (file.open(QFile::ReadOnly | QFile::Text))
00510                         {
00511                                 opened = true;
00512                                 break;
00513                         }
00514                 }
00515                 if (!opened)
00516                 {
00517                         if (console())
00518                 console()->error(tr("file not found"));
00519                 }
00520                 else
00521                 {
00522                         QString allText(file.readAll());
00523                         if (console())
00524                 console()->message(allText);
00525                         file.close();
00526                 }
00527 
00528 
00529                 if (sem)
00530                         sem->release();
00531         }
00532 
00533         void C_API_Slots::outputTable(QSemaphore* sem,const DataTable<qreal>& table)
00534         {
00535                 if (console())
00536             console()->printTable(table);
00537                 if (sem)
00538                         sem->release();
00539         }
00540         
00541         void C_API_Slots::createInputWindow(QSemaphore* s,const DataTable<qreal>& data, const QString& title,const QString& function)
00542         {
00543                 SimpleInputWindow::CreateWindow(mainWindow,title,function,data);
00544                 if (s)
00545                         s->release();
00546         }
00547         
00548         void C_API_Slots::createInputWindow(QSemaphore* s, long ptr, const DataTable<qreal>& dat,const QString& title, MatrixInputFunction f)
00549         {
00550                 CThread * thread = static_cast<CThread*>( (void*)ptr );
00551                 if (CThread::cthreads.contains(thread))
00552                         SimpleInputWindow::CreateWindow(thread,title,f,dat);
00553                 if (s)
00554                         s->release();
00555         }
00556         
00557         void C_API_Slots::createSliders(QSemaphore* s, CThread * cthread, const DataTable<qreal>& data, MatrixInputFunction f)
00558         {
00559                 if (cthread)
00560                 {
00561                         cthread->setFunction(f);
00562                         
00563                         MultithreadedSliderWidget * widget = new MultithreadedSliderWidget(mainWindow, cthread, Qt::Horizontal);
00564                         
00565                         QStringList names(data.rowNames());
00566                         QList<double> min, max;
00567                         for (int i=0; i < names.size(); ++i)
00568                         {
00569                                 names[i].replace(tr("_"),tr("."));
00570                                 names[i].replace(tr(".."),tr("_"));
00571                                 min <<  data.at(i,0);
00572                                 max << data.at(i,1);
00573                         }
00574                         widget->setSliders(names, min, max);
00575                         
00576                         widget->show();
00577                 }
00578                 if (s)
00579                         s->release();
00580         }
00581         
00582         void C_API_Slots::addInputWindowOptions(QSemaphore* s,const QString& name, int i, int j,const QStringList& options)
00583         {
00584                 SimpleInputWindow::AddOptions(name,i,j,options);
00585                 if (s)
00586                         s->release();
00587         }
00588         void C_API_Slots::addInputWindowCheckbox(QSemaphore* s,const QString& name, int i, int j)
00589         {
00590                 QStringList list;
00591                 list << "Yes" << "No";
00592                 SimpleInputWindow::AddOptions(name,i,j,list);
00593                 if (s)
00594                         s->release();
00595         }
00596         void C_API_Slots::openNewWindow(QSemaphore* s,const QString& name)
00597         {
00598                 if (mainWindow)
00599                 {
00600                         mainWindow->newScene();
00601                         if (currentNetwork())
00602                                 currentNetwork()->setWindowTitle(name);
00603                 }
00604                 if (s)
00605                         s->release();
00606         }
00607         void C_API_Slots::isWindows(QSemaphore* s, int * i)
00608         {
00609 #ifdef Q_WS_WIN
00610                 if (i) (*i) = 1;
00611 #else
00612                 if (i) (*i) = 0;
00613 #endif
00614                 if (s)
00615                         s->release();
00616         }
00617         void C_API_Slots::isMac(QSemaphore* s, int * i)
00618         {
00619 #ifdef Q_WS_MAC
00620                 if (i) (*i) = 1;
00621 #else
00622                 if (i) (*i) = 0;
00623 #endif
00624                 if (s)
00625                         s->release();
00626         }
00627 
00628         void C_API_Slots::isLinux(QSemaphore* s, int * i)
00629         {
00630 #ifdef Q_WS_WIN
00631                 if (i) (*i) = 0;
00632 #else
00633 #ifdef Q_WS_MAC
00634                 if (i) (*i) = 0;
00635 #else
00636                 if (i) (*i) = 1;
00637 #endif
00638 #endif
00639                 if (s)
00640                         s->release();
00641         }
00642 
00643         void C_API_Slots::appDir(QSemaphore* s, QString * dir)
00644         {
00645                 QString appDir = QCoreApplication::applicationDirPath();
00646                 if (dir)
00647                         (*dir) = appDir;
00648                 if (s)
00649                         s->release();
00650         }
00651 
00652         void C_API_Slots::homeDir(QSemaphore* s, QString * dir)
00653         {
00654                 QString homeDir = GlobalSettings::homeDir();
00655                 if (dir)
00656                         (*dir) = homeDir;
00657                 if (s)
00658                         s->release();
00659         }
00660 
00661 
00662         void C_API_Slots::allItems(QSemaphore* s,QList<ItemHandle*>* returnPtr)
00663         {
00664                 NetworkHandle * win = currentNetwork();
00665                 if (!win || !returnPtr)
00666                 {
00667                         if (s) s->release();
00668                         return;
00669                 }
00670 
00671                 if (returnPtr)
00672                         (*returnPtr) = win->handles(true);
00673 
00674                 if (s)
00675                         s->release();
00676         }
00677 
00678         void C_API_Slots::itemsOfFamily(QSemaphore* s,QList<ItemHandle*>* returnPtr, const QString& family)
00679         {
00680                 NetworkHandle * win = currentNetwork();
00681                 if (!win || !returnPtr)
00682                 {
00683                         if (s) s->release();
00684                         return;
00685                 }
00686 
00687                 if (returnPtr)
00688                 {
00689                         QList<ItemHandle*> handles = win->handles(true);
00690                         for (int i=0; i < handles.size(); ++i)
00691                                 if (handles[i] && handles[i]->isA(family))
00692                                         (*returnPtr) += handles[i];
00693                 }
00694 
00695                 if (s)
00696                         s->release();
00697         }
00698 
00699         void C_API_Slots::itemsOfFamily(QSemaphore* s,QList<ItemHandle*>* returnPtr,const QList<ItemHandle*>& handles,const QString& family)
00700         {
00701                 NetworkHandle * win = currentNetwork();
00702                 if (!win || !returnPtr)
00703                 {
00704                         if (s) s->release();
00705                         return;
00706                 }
00707 
00708                 if (returnPtr)
00709                 {
00710                         for (int i=0; i < handles.size(); ++i)
00711                                 if (handles[i] && handles[i]->isA(family))
00712                                         (*returnPtr) += handles[i];
00713                 }
00714 
00715                 if (s)
00716                         s->release();
00717         }
00718 
00719         void C_API_Slots::selectedItems(QSemaphore* s,QList<ItemHandle*>* returnPtr)
00720         {
00721                 GraphicsScene * scene = currentScene();
00722                 if (!scene || !returnPtr)
00723                 {
00724                         if (s) s->release();
00725                         return;
00726                 }
00727 
00728                 QList<QGraphicsItem*> & selected = scene->selected();
00729 
00730                 if (returnPtr)
00731                 {
00732                         ItemHandle * h;
00733                         for (int i=0; i < selected.size(); ++i)
00734                                 if ((h = getHandle(selected[i])) && !returnPtr->contains(h))
00735                                         (*returnPtr) << h;
00736                 }
00737 
00738                 if (s)
00739                         s->release();
00740         }
00741 
00742         void C_API_Slots::screenshot(QSemaphore * s, const QString& fileName, int w, int h)
00743         {
00744                 GraphicsScene * scene = currentScene();
00745                 if (mainWindow && scene)
00746                 {
00747                         scene->fitAll();
00748                         mainWindow->printToFile(fileName,w,h);
00749                 }
00750                 if (s)
00751                         s->release();
00752         }
00753         
00754         void C_API_Slots::screenWidth(QSemaphore * s, int * w)
00755         {
00756                 GraphicsScene * scene = currentScene();
00757                 if (scene && w)
00758                 {
00759                         scene->fitAll();
00760                         QRectF viewport = scene->visibleRegion();
00761                         (*w) = (int)viewport.width();
00762                 }
00763                 if (s)
00764                         s->release();
00765         }
00766         
00767         void C_API_Slots::screenHeight(QSemaphore * s, int * h)
00768         {
00769                 GraphicsScene * scene = currentScene();
00770                 if (scene && h)
00771                 {
00772                         scene->fitAll();
00773                         QRectF viewport = scene->visibleRegion();
00774                         (*h) = (int)viewport.height();
00775                 }
00776                 if (s)
00777                         s->release();
00778         }
00779         
00780         void C_API_Slots::screenX(QSemaphore * s, int * x)
00781         {
00782                 GraphicsScene * scene = currentScene();
00783                 if (scene && x)
00784                 {
00785                         scene->fitAll();
00786                         QRectF viewport = scene->visibleRegion();
00787                         (*x) = (int)viewport.x();
00788                 }
00789                 if (s)
00790                         s->release();
00791         }
00792         
00793         void C_API_Slots::screenY(QSemaphore * s, int * y)
00794         {
00795                 GraphicsScene * scene = currentScene();
00796                 if (scene && y)
00797                 {
00798                         scene->fitAll();
00799                         QRectF viewport = scene->visibleRegion();
00800                         (*y) = (int)viewport.y();
00801                 }
00802                 if (s)
00803                         s->release();
00804         }
00805 
00806         void C_API_Slots::itemNames(QSemaphore* s,QStringList* list,const QList<ItemHandle*>& items)
00807         {
00808                 if (list)
00809                 {
00810                         (*list).clear();
00811                         for (int i=0; i < items.size(); ++i)
00812                         {
00813                                 if (items[i])
00814                                         (*list) << items[i]->name;
00815                         }
00816                 }
00817                 if (s)
00818                         s->release();
00819         }
00820 
00821         void C_API_Slots::uniqueNames(QSemaphore* s,QStringList* list,const QList<ItemHandle*>& items)
00822         {
00823                 if (list)
00824                 {
00825                         (*list).clear();
00826                         for (int i=0; i < items.size(); ++i)
00827                         {
00828                                 if (items[i])
00829                                         (*list) << items[i]->fullName(tr("_"));
00830                         }
00831                 }
00832                 if (s)
00833                         s->release();
00834         }
00835 
00836         void C_API_Slots::itemName(QSemaphore* s,QString* name,ItemHandle* handle)
00837         {
00838                 if (handle && name)
00839                 {
00840                         (*name) = handle->name;
00841                 }
00842                 if (s)
00843                         s->release();
00844         }
00845 
00846         void C_API_Slots::uniqueName(QSemaphore* s,QString* name,ItemHandle* handle)
00847         {
00848                 if (handle && name)
00849                 {
00850                         (*name) = handle->fullName(tr("_"));
00851                 }
00852                 if (s)
00853                         s->release();
00854         }
00855 
00856         void C_API_Slots::setName(QSemaphore* s,ItemHandle* handle,const QString& name)
00857         {
00858                 if (handle && !name.isNull() && !name.isEmpty() && currentNetwork())
00859                 {
00860                         currentNetwork()->rename(handle,name);
00861                 }
00862                 if (s)
00863                         s->release();
00864         }
00865 
00866         void C_API_Slots::itemFamily(QSemaphore* s,QString* family,ItemHandle* handle)
00867         {
00868                 if (handle && family && handle->family())
00869                 {
00870                         (*family) = handle->family()->name();
00871                 }
00872                 if (s)
00873                         s->release();
00874         }
00875 
00876         void C_API_Slots::isA(QSemaphore* s,int* boolean,ItemHandle* handle,const QString& family)
00877         {
00878                 if (handle && boolean)
00879                 {
00880                         (*boolean) = 0;
00881 
00882                         if (handle->family())
00883                         {
00884                                 (*boolean) = (int)(handle->family()->isA(family));
00885                         }
00886                 }
00887                 if (s)
00888                         s->release();
00889         }
00890 
00891         void C_API_Slots::findItem(QSemaphore* s,ItemHandle** returnPtr,const QString& name)
00892         {
00893                 NetworkHandle * win = currentNetwork();
00894                 if (!win || !returnPtr)
00895                 {
00896                         if (returnPtr)
00897                                 (*returnPtr) = 0;
00898                         if (s) s->release();
00899                         return;
00900                 }
00901 
00902                 (*returnPtr) = 0;
00903 
00904                 QList<ItemHandle*> items = win->findItem(name);
00905                 
00906                 if (items.isEmpty())
00907                 {
00908                         QList< QPair<ItemHandle*, QString> > data = win->findData(name);
00909                         if (data.size() > 0 && data[0].first)
00910                                 (*returnPtr) = data[0].first;
00911                 }
00912                 else
00913                         (*returnPtr) = items[0];
00914                 
00915                 if (s)
00916                         s->release();
00917         }
00918 
00919         void C_API_Slots::findItems(QSemaphore* s,QList<ItemHandle*>* returnPtr,const QStringList& names)
00920         {
00921                 NetworkHandle * win = currentNetwork();
00922                 if (!win || !returnPtr)
00923                 {
00924                         if (returnPtr)
00925                                 returnPtr->clear();
00926                         if (s) s->release();
00927                         return;
00928                 }
00929 
00930                 QList<ItemHandle*> items = win->findItem(names);
00931                 
00932                 if (items.isEmpty())
00933                 {
00934                         QList< QPair<ItemHandle*, QString> > data = win->findData(names);
00935                         for (int i=0; i < data.size(); ++i)
00936                                 if (data[i].first && !items.contains(data[i].first))
00937                                         items << data[i].first;
00938                 }
00939                 
00940                 (*returnPtr) = items;
00941 
00942                 if (s)
00943                         s->release();
00944         }
00945 
00946         void C_API_Slots::findItemsUsingRegex(QSemaphore* s,QList<ItemHandle*>* returnPtr,const QString& regex)
00947         {
00948                 NetworkHandle * win = currentNetwork();
00949                 if (!win || !returnPtr)
00950                 {
00951                         if (returnPtr)
00952                                 returnPtr->clear();
00953                         if (s) s->release();
00954                         return;
00955                 }
00956 
00957                 (*returnPtr) = win->findItem(QRegExp(regex));;
00958 
00959                 if (s)
00960                         s->release();
00961         }
00962 
00966         void C_API_Slots::select(QSemaphore* sem,ItemHandle* item)
00967         {
00968                 GraphicsScene * scene = currentScene();
00969                 if (item && scene)
00970                         scene->select(item->graphicsItems);
00971                 if (sem)
00972                         sem->release();
00973         }
00974 
00978         void C_API_Slots::deselect(QSemaphore* sem)
00979         {
00980                 mainWindow->sendEscapeSignal();
00981                 if (sem)
00982                         sem->release();
00983         }
00984 
00985 
00989         void C_API_Slots::removeItem(QSemaphore* sem, ItemHandle * item)
00990         {
00991                 if (currentScene() && item)
00992                         currentScene()->remove(tr("item removed"),item->graphicsItems);
00993                 //else
00994                 //if (currentTextEditor() && item)
00995 
00996                 if (sem)
00997                         sem->release();
00998         }
00999 
01000         QList<QGraphicsItem*> C_API_Slots::createNewNode(GraphicsScene * scene, const QPointF& point, const QString& s, const QString & familyname, const QStringList & usedNames)
01001         {
01002                 NodeFamily * family = Ontology::nodeFamily(familyname);
01003                 QList<QGraphicsItem*> list;
01004                 if (family && scene)
01005                 {
01006                         QString name = s;
01007                         if (s.isNull() || s.isEmpty())
01008                         {
01009                                 name = family->name().toLower() + tr("1");
01010                                 QStringList words = name.split(tr(" "));
01011                                 if (words.size() > 1)
01012                                 {
01013                                         name = words.first().left(1) + words.last().left(1);
01014                                         name += tr("1");
01015                                 }
01016                                 
01017                                 if (name.length() > 3)
01018                                         name = name.left( 3 ) + tr("1");
01019                                 
01020                                 if (!name[0].isLetter())
01021                                                 name = tr("x") + name;
01022                         }
01023 
01024                         QList<NodeFamily*> allFamilies;         
01025                         allFamilies += family;
01026                         qreal xpos = point.x();
01027                         qreal height = 0.0;
01028                         qreal width = 0.0;
01029 
01030                         for (int j=0; j < allFamilies.size(); ++j)
01031                         {
01032                                 NodeFamily * nodeFamily = allFamilies[j];
01033 
01034                                 for (int i=0; i < nodeFamily->graphicsItems.size(); ++i)
01035                                         if (NodeGraphicsItem::cast(nodeFamily->graphicsItems[i]))
01036                                                 width += NodeGraphicsItem::cast(nodeFamily->graphicsItems[i])->defaultSize.width();
01037                         }
01038 
01039                         xpos -= width/2.0;
01040                         bool alternate = false;
01041 
01042                         for (int j=0; j < allFamilies.size(); ++j)
01043                         {
01044                                 NodeFamily * nodeFamily = allFamilies[j];
01045 
01046                                 NodeHandle * handle = new NodeHandle(nodeFamily);
01047                                 handle->name = RemoveDisallowedCharactersFromName(name);
01048                                 if (!handle->name[0].isLetter())
01049                                                 handle->name = tr("S") + handle->name;
01050                                 handle->name = scene->network->makeUnique(handle->name,usedNames);
01051                                 
01052                                 NodeGraphicsItem * image = 0;
01053 
01054                                 for (int i=0; i < nodeFamily->graphicsItems.size(); ++i)
01055                                 {
01056                                         image = (NodeGraphicsItem::cast(nodeFamily->graphicsItems[i]));
01057                                         if (image)
01058                                         {
01059                                                 image = image->clone();
01060                                                 if (image->defaultSize.width() > 0 && image->defaultSize.height() > 0)
01061                                                         image->scale(image->defaultSize.width()/image->sceneBoundingRect().width(),image->defaultSize.height()/image->sceneBoundingRect().height());
01062 
01063                                                 qreal w = image->sceneBoundingRect().width();
01064 
01065                                                 image->setPos(xpos + w/2.0, point.y());
01066 
01067                                                 image->setBoundingBoxVisible(false);
01068 
01069                                                 if (image->isValid())
01070                                                 {
01071                                                         xpos += w;
01072                                                         setHandle(image,handle);
01073                                                         list += image;
01074                                                 }
01075                                                 if (image->sceneBoundingRect().height() > height)
01076                                                         height = image->sceneBoundingRect().height();
01077                                         }
01078                                 }
01079 
01080                                 if (nodeFamily->graphicsItems.size() > 0)
01081                                 {
01082                                         if (handle->family() && !handle->family()->isA("Empty"))
01083                                         {
01084                                                 TextGraphicsItem * nameItem = new TextGraphicsItem(handle,0);
01085                                                 if (image)
01086                                                         nameItem->relativePosition = QPair<QGraphicsItem*,QPointF>(image,QPointF(0,0));
01087                                                 QFont font = nameItem->font();
01088                                                 font.setPointSize(22);
01089                                                 nameItem->setFont(font);
01090                                                 if (alternate)
01091                                                         nameItem->setPos(xpos - nameItem->boundingRect().width(), point.y() - height/2.0 - 40.0);
01092                                                 else
01093                                                         nameItem->setPos(xpos - nameItem->boundingRect().width(), point.y() + height/2.0 + 5.0);
01094                                                 list += nameItem;
01095                                                 alternate = !alternate;
01096                                         }
01097                                 }
01098                         }
01099                 }
01100                 return list;
01101         }
01102 
01103         void C_API_Slots::insertItem(QSemaphore * sem, ItemHandle** item, const QString& name, const QString& family)
01104         {
01105                 if (mainWindow && mainWindow->currentScene() && !name.isEmpty())
01106                 {
01107                         GraphicsScene * scene = mainWindow->currentScene();
01108                         if (item)
01109                                 (*item) = 0;
01110                         if (scene)
01111                         {
01112                                 //scene->lastPoint().rx() = scene->lastPoint().ry() = 0.0; //make null
01113                                 QList<QGraphicsItem*> list = createNewNode(scene, scene->visibleRegion().center(), name, family);
01114                                 if (!list.isEmpty())
01115                                 {
01116                                         scene->insert(name + tr(" inserted"),list);
01117                                         QList<ItemHandle*> handles = getHandle(list);
01118                                         if (handles.size() > 0)
01119                                                 (*item) = handles[0];
01120                                 }
01121                                 else
01122                                 {
01123                                         NodeFamily * nodeFamily = 0;
01124                                         if (!family.isEmpty())
01125                                         {
01126                                                 nodeFamily = Ontology::nodeFamily(family);
01127                                                 if (!nodeFamily)
01128                                                 {
01129                                                         nodeFamily = new NodeFamily(family.toLower());
01130                                                         Ontology::insertNodeFamily(family.toLower(), nodeFamily);
01131                                                 }
01132                                         }
01133                                         NodeGraphicsItem * nodeItem = new NodeGraphicsItem(":/images/defaultnode.xml");
01134                                         nodeItem->setPos(scene->visibleRegion().center());
01135                                         NodeHandle * h = new NodeHandle(nodeFamily, nodeItem);
01136                                         if (scene->network)
01137                                                 scene->network->makeUnique(h);
01138                                         TextGraphicsItem * text = new TextGraphicsItem(h);
01139                                         QPointF bottom(0, nodeItem->boundingRect().height()/2);
01140                                         text->setPos( nodeItem->pos() + bottom );
01141                                         QFont font = text->font();
01142                                         font.setPointSize(22);
01143                                         text->setFont(font);                                    
01144                                         QList<QGraphicsItem*> list;
01145                                         list << nodeItem << text;
01146                                         scene->insert(h->name + tr(" inserted"), list);
01147                                         (*item) = h;
01148                                 }
01149                         }
01150                 }
01151                 if (sem)
01152                         sem->release();
01153         }
01154 
01155 
01156         void C_API_Slots::getX(QSemaphore * s, qreal * returnPtr, ItemHandle * item)
01157         {
01158                 if (item == 0 || item->graphicsItems.isEmpty() || !returnPtr)
01159                 {
01160                         if (s) s->release();
01161                         return;
01162                 }
01163                 
01164                 NodeGraphicsItem * node;
01165                 ConnectionGraphicsItem * connection;
01166                 
01167                 bool found = false;
01168                 for (int i=0; i < item->graphicsItems.size(); ++i)
01169                         if (node = NodeGraphicsItem::cast(item->graphicsItems[i]))
01170                         {
01171                                 (*returnPtr) = node->scenePos().x();
01172                                 found = true;
01173                                 break;
01174                         }
01175 
01176                 if (!found)
01177                 {
01178                         for (int i=0; i < item->graphicsItems.size(); ++i)
01179                                 if (connection = ConnectionGraphicsItem::cast(item->graphicsItems[i]))
01180                                 {
01181                                         (*returnPtr) = connection->centerLocation().x();
01182                                         found = true;
01183                                         break;
01184                                 }
01185                 }
01186 
01187                 if (!found)
01188                 {
01189                         for (int i=0; i < item->graphicsItems.size(); ++i)
01190                                 if (item->graphicsItems[i])
01191                                 {
01192                                         (*returnPtr) = item->graphicsItems[i]->scenePos().x();
01193                                         found = true;
01194                                         break;
01195                                 }
01196                 }
01197 
01198                 if (s)
01199                         s->release();
01200         }
01201 
01202         void C_API_Slots::getY(QSemaphore * s, qreal * returnPtr, ItemHandle * item)
01203         {
01204                 if (item == 0 || item->graphicsItems.isEmpty() || !returnPtr)
01205                 {
01206                         if (s) s->release();
01207                         return;
01208                 }
01209 
01210                 bool found = false;
01211                 NodeGraphicsItem * node;
01212                 ConnectionGraphicsItem * connection;
01213                 
01214                 for (int i=0; i < item->graphicsItems.size(); ++i)
01215                         if (node = NodeGraphicsItem::cast(item->graphicsItems[i]))
01216                         {
01217                                 (*returnPtr) = node->scenePos().y();
01218                                 found = true;
01219                                 break;
01220                         }
01221                 
01222                 if (!found)
01223                 {
01224                         for (int i=0; i < item->graphicsItems.size(); ++i)
01225                                 if (connection = ConnectionGraphicsItem::cast(item->graphicsItems[i]))
01226                                 {
01227                                         (*returnPtr) = connection->centerLocation().y();
01228                                         found = true;
01229                                         break;
01230                                 }
01231                 }
01232                 
01233                 if (!found)
01234                 {
01235                         for (int i=0; i < item->graphicsItems.size(); ++i)
01236                                 if (item->graphicsItems[i])
01237                                 {
01238                                         (*returnPtr) = item->graphicsItems[i]->scenePos().y();
01239                                         found = true;
01240                                         break;
01241                                 }
01242                 }
01243                 if (s)
01244                         s->release();
01245         }
01246 
01247         void C_API_Slots::moveSelected(QSemaphore* sem,qreal dx, qreal dy)
01248         {
01249                 if (currentScene())
01250                 {
01251                         QList<QGraphicsItem*> items = currentScene()->selected();
01252                         currentScene()->move( items , QPointF(dx,dy) );
01253                 }
01254                 if (sem)
01255                         sem->release();
01256         }
01257 
01258         void C_API_Slots::setPos(QSemaphore* sem, ItemHandle * item, qreal x, qreal y)
01259         {
01260                 if (currentScene() && item && !item->graphicsItems.isEmpty() && item->graphicsItems[0])
01261                 {
01262                         currentScene()->move( item->graphicsItems , QPointF(x,y) - item->graphicsItems[0]->scenePos() );
01263                 }
01264                 if (sem)
01265                         sem->release();
01266         }
01267 
01268         void C_API_Slots::setPos(QSemaphore* sem,const QList<ItemHandle*>& items, DataTable<qreal>& pos)
01269         {
01270                 if (currentScene() && !items.isEmpty() && items.size() == pos.rows() && pos.columns() == 2)
01271                 {
01272                         QList<QGraphicsItem*> graphicsItems;
01273                         QGraphicsItem* item;
01274                         QList<QPointF> p;
01275                         QPointF diff, target;
01276                         ConnectionGraphicsItem * connection = 0;
01277                         NodeGraphicsItem *  node = 0;
01278                         int m;
01279                         for (int i=0; i < items.size(); ++i)
01280                         {
01281                                 for (int j=0; j < items[i]->graphicsItems.size(); ++j)
01282                                         if ((item = items[i]->graphicsItems[j]))
01283                                         {
01284                                                 if ((connection = ConnectionGraphicsItem::cast(item)))
01285                                                 {
01286                                                         graphicsItems << item;
01287                                                         p << QPointF(pos.value(i,0),pos.value(i,1)) - connection->centerLocation();
01288                                                 }
01289                                         }
01290                         }
01291                         currentScene()->move( graphicsItems , p );
01292                 }
01293                 else
01294                         if (console())
01295                 console()->message(QString::number(items.size()) + tr(" ") + QString::number(pos.columns()));
01296 
01297                 if (sem)
01298                         sem->release();
01299         }
01300 
01301         void C_API_Slots::getPos(QSemaphore* sem,const QList<ItemHandle*>& items, DataTable<qreal>* pos)
01302         {
01303                 if (currentScene() && !items.isEmpty() && pos)
01304                 {
01305                         QList<QPointF> p;
01306                         for (int i=0; i < items.size(); ++i)
01307                         {
01308                                 for (int j=0; j < items[i]->graphicsItems.size(); ++j)
01309                                 {
01310                                         if (ConnectionGraphicsItem::cast(items[i]->graphicsItems[j]))
01311                                         {
01312                                                 p << (ConnectionGraphicsItem::cast(items[i]->graphicsItems[j]))->centerLocation();
01313                                                 break;
01314                                         }
01315                                         else
01316                                         if (NodeGraphicsItem::cast(items[i]->graphicsItems[j]) || (j == (items[i]->graphicsItems.size() - 1)))
01317                                         {
01318                                                 p << items[i]->graphicsItems[j]->scenePos();
01319                                                 break;
01320                                         }
01321                                 }
01322                         }
01323 
01324                         (*pos).resize(p.size(),2);
01325                         (*pos).columnName(0) = tr("x");
01326                         (*pos).columnName(1) = tr("y");
01327                         for (int i=0; i < p.size(); ++i)
01328                         {
01329                                 (*pos).value(i,0) = p[i].rx();
01330                                 (*pos).value(i,1) = p[i].ry();
01331                         }
01332                 }
01333                 if (sem)
01334                         sem->release();
01335         }
01336 
01337 
01338         void C_API_Slots::getNumericalData(QSemaphore* sem,DataTable<qreal>* dat,ItemHandle* item,const QString& tool)
01339         {
01340                 if (!item && currentNetwork())
01341                         item = currentNetwork()->globalHandle();
01342 
01343                 if (dat && item && item->hasNumericalData(tool))
01344                 {
01345                         (*dat) = item->numericalDataTable(tool);
01346                 }
01347                 if (sem)
01348                         sem->release();
01349         }
01350 
01351         void C_API_Slots::setNumericalData(QSemaphore* sem,ItemHandle* item,const QString& tool, const DataTable<qreal>& dat)
01352         {
01353                 if (!item && currentNetwork())
01354                         item = currentNetwork()->globalHandle();
01355 
01356                 if (item)
01357                 {
01358                         if (!item->hasNumericalData(tool))
01359                         {
01360                                 item->numericalDataTable(tool) = DataTable<qreal>();
01361                         }
01362                         NetworkHandle * win = currentNetwork();
01363                         if (win)
01364                         {
01365                                 win->changeData(tool + tr(" changed for ") + item->fullName(),item,tool,&dat);
01366                         }
01367                 }
01368                 if (sem)
01369                         sem->release();
01370         }
01371 
01372         void C_API_Slots::getTextData(QSemaphore* sem,DataTable<QString>* dat,ItemHandle* item,const QString& tool)
01373         {
01374                 if (!item && currentNetwork())
01375                         item = currentNetwork()->globalHandle();
01376 
01377                 if (dat && item && item->hasTextData(tool))
01378                 {
01379                         (*dat) = item->textDataTable(tool);
01380                 }
01381                 if (sem)
01382                         sem->release();
01383         }
01384 
01385         void C_API_Slots::setTextData(QSemaphore* sem,ItemHandle* item,const QString& tool, const DataTable<QString>& dat)
01386         {
01387                 if (!item && currentNetwork())
01388                         item = currentNetwork()->globalHandle();
01389 
01390                 if (item)
01391                 {
01392                         if (!item->hasTextData(tool))
01393                         {
01394                                 item->textDataTable(tool) = TextDataTable();
01395                         }
01396                         NetworkHandle * win = currentNetwork();
01397                         if (win)
01398                         {
01399                                 win->changeData(tool + tr(" changed for ") + item->fullName(),item,tool,&dat);
01400                         }
01401                 }
01402                 if (sem)
01403                         sem->release();
01404         }
01405         
01406         void C_API_Slots::getNumericalDataNames(QSemaphore* sem,QStringList* list,ItemHandle* item)
01407         {
01408                 if (!item && currentNetwork())
01409                         item = currentNetwork()->globalHandle();
01410                         
01411                 if (item && list)
01412                 {
01413                         (*list) << item->numericalDataNames();
01414                 }
01415                 if (sem)
01416                         sem->release();
01417         }
01418 
01419         void C_API_Slots::getTextDataNames(QSemaphore*sem,QStringList* list,ItemHandle* item)
01420         {
01421                 if (!item && currentNetwork())
01422                         item = currentNetwork()->globalHandle();
01423                         
01424                 if (item && list)
01425                 {
01426                         (*list) << item->textDataNames();
01427                 }
01428                 if (sem)
01429                         sem->release();
01430         }
01431 
01432         void C_API_Slots::getChildren(QSemaphore* sem,QList<ItemHandle*>* ret,ItemHandle* item)
01433         {
01434                 if (item && ret)
01435                 {
01436                         (*ret) << item->children;
01437                 }
01438                 if (sem)
01439                         sem->release();
01440         }
01441 
01442         void C_API_Slots::getParent(QSemaphore* sem,ItemHandle** ret,ItemHandle* item)
01443         {
01444                 if (item && ret)
01445                 {
01446                         (*ret) = item->parent;
01447                 }
01448                 if (sem)
01449                         sem->release();
01450         }
01451 
01452         void C_API_Slots::_zoom(double x)
01453         {
01454                 fToS->zoom(x);
01455         }
01456 
01457         void C_API_Slots::_viewWindow(const char * s)
01458         {
01459                 fToS->viewWindow(s);
01460         }
01461 
01462         long C_API_Slots::_find(const char* c)
01463         {
01464                 return fToS->find(c);
01465         }
01466 
01467         tc_items C_API_Slots::_findItems(tc_strings c)
01468         {
01469                 return fToS->findItems(c);
01470         }
01471 
01472         tc_items C_API_Slots::_findItemsUsingRegex(const char* c)
01473         {
01474                 return fToS->findItemsUsingRegex(c);
01475         }
01476 
01477         void C_API_Slots::_select(long o)
01478         {
01479                 return fToS->select(o);
01480         }
01481 
01482         void C_API_Slots::_deselect()
01483         {
01484                 return fToS->deselect();
01485         }
01486 
01487         tc_items C_API_Slots::_allItems()
01488         {
01489                 return fToS->allItems();
01490         }
01491 
01492         tc_items C_API_Slots::_itemsOfFamily(const char* f)
01493         {
01494                 return fToS->itemsOfFamily(f);
01495         }
01496 
01497         tc_items C_API_Slots::_itemsOfFamily2(const char* f, tc_items a)
01498         {
01499                 return fToS->itemsOfFamily(f,a);
01500         }
01501 
01502         tc_items C_API_Slots::_selectedItems()
01503         {
01504                 return fToS->selectedItems();
01505         }
01506 
01507         const char* C_API_Slots::_getName(long o)
01508         {
01509                 return fToS->getName(o);
01510         }
01511 
01512         const char* C_API_Slots::_getUniqueName(long o)
01513         {
01514                 return fToS->getUniqueName(o);
01515         }
01516 
01517 
01518         void C_API_Slots::_setName(long o,const char* c)
01519         {
01520                 return fToS->setName(o,c);
01521         }
01522 
01523         tc_strings C_API_Slots::_getNames(tc_items a)
01524         {
01525                 return fToS->getNames(a);
01526         }
01527 
01528         tc_strings C_API_Slots::_getUniqueNames(tc_items a)
01529         {
01530                 return fToS->getUniqueNames(a);
01531         }
01532 
01533         const char* C_API_Slots::_getFamily(long o)
01534         {
01535                 return fToS->getFamily(o);
01536         }
01537 
01538         int C_API_Slots::_isA(long o,const char* c)
01539         {
01540                 return fToS->isA(o,c);
01541         }
01542 
01543         void C_API_Slots::_removeItem(long o)
01544         {
01545                 return fToS->removeItem(o);
01546         }
01547 
01548         long C_API_Slots::_insertItem(const char* a, const char* b)
01549         {
01550                 return fToS->insertItem(a,b);
01551         }
01552 
01553         void C_API_Slots::_setPos(long o,double x,double y)
01554         {
01555                 return fToS->setPos(o,x,y);
01556         }
01557 
01558         void C_API_Slots::_setPos2(tc_items a,tc_matrix m)
01559         {
01560                 return fToS->setPos(a,m);
01561         }
01562 
01563         tc_matrix C_API_Slots::_getPos(tc_items a)
01564         {
01565                 return fToS->getPos(a);
01566         }
01567 
01568         double C_API_Slots::_getY(long o)
01569         {
01570                 return fToS->getY(o);
01571         }
01572 
01573         double C_API_Slots::_getX(long o)
01574         {
01575                 return fToS->getX(o);
01576         }
01577 
01578         void C_API_Slots::_moveSelected(double dx,double dy)
01579         {
01580                 return fToS->moveSelected(dx,dy);
01581         }
01582 
01583         void C_API_Slots::_clearText()
01584         {
01585                 return fToS->clearText();
01586         }
01587 
01588         void C_API_Slots::_outputTable(tc_matrix m)
01589         {
01590                 return fToS->outputTable(m);
01591         }
01592 
01593         void C_API_Slots::_outputText(const char * c)
01594         {
01595                 return fToS->outputText(c);
01596         }
01597 
01598         void C_API_Slots::_errorReport(const char * c)
01599         {
01600                 return fToS->errorReport(c);
01601         }
01602 
01603         void C_API_Slots::_printFile(const char* c)
01604         {
01605                 return fToS->printFile(c);
01606         }
01607 
01608         void  C_API_Slots::_createInputWindow1(tc_matrix m,const char* a,const char* b)
01609         {
01610                 return fToS->createInputWindow(m,a,b);
01611         }
01612 
01613         void  C_API_Slots::_createInputWindow2(long ptr, tc_matrix m,const char* a, MatrixInputFunction f)
01614         {
01615                 return fToS->createInputWindow(ptr, m,a,f);
01616         }
01617         
01618         void  C_API_Slots::_createSliders(long c, tc_matrix m,MatrixInputFunction f)
01619         {
01620                 return fToS->createSliders(c,m,f);
01621         }
01622 
01623         void  C_API_Slots::_addInputWindowOptions(const char* a,int i, int j, tc_strings c)
01624         {
01625                 return fToS->addInputWindowOptions(a,i,j,c);
01626         }
01627 
01628         void  C_API_Slots::_addInputWindowCheckbox(const char* a,int i, int j)
01629         {
01630                 return fToS->addInputWindowCheckbox(a,i,j);
01631         }
01632 
01633         void  C_API_Slots::_openNewWindow(const char* c)
01634         {
01635                 return fToS->openNewWindow(c);
01636         }
01637 
01638         int  C_API_Slots::_isWindows()
01639         {
01640                 return fToS->isWindows();
01641         }
01642 
01643         int  C_API_Slots::_isMac()
01644         {
01645                 return fToS->isMac();
01646         }
01647 
01648         int  C_API_Slots::_isLinux()
01649         {
01650                 return fToS->isLinux();
01651         }
01652 
01653         const char*  C_API_Slots::_appDir()
01654         {
01655                 return fToS->appDir();
01656         }
01657 
01658         const char*  C_API_Slots::_homeDir()
01659         {
01660                 return fToS->homeDir();
01661         }
01662 
01663 
01664         tc_matrix C_API_Slots::_getNumericalData(long o,const char* a)
01665         {
01666                 return fToS->getNumericalData(o,a);
01667         }
01668 
01669         void C_API_Slots::_setNumericalData(long o ,const char* a,tc_matrix m)
01670         {
01671                 return fToS->setNumericalData(o,a,m);
01672         }
01673         
01674         tc_table C_API_Slots::_getTextData(long o,const char* a)
01675         {
01676                 return fToS->getTextData(o,a);
01677         }
01678 
01679         void C_API_Slots::_setTextData(long o ,const char* a,tc_table m)
01680         {
01681                 return fToS->setTextData(o,a,m);
01682         }
01683         
01684         tc_strings C_API_Slots::_getTextDataNames(long o)
01685         {
01686                 return fToS->getTextDataNames(o);
01687         }
01688         
01689         tc_strings C_API_Slots::_getNumericalDataNames(long o)
01690         {
01691                 return fToS->getNumericalDataNames(o);
01692         }
01693 
01694         tc_items C_API_Slots::_getChildren(long o)
01695         {
01696                 return fToS->getChildren(o);
01697         }
01698 
01699         long C_API_Slots::_getParent(long o)
01700         {
01701                 return fToS->getParent(o);
01702         }
01703         
01704         const char * C_API_Slots::_annotations()
01705         {
01706                 return fToS->annotation();
01707         }
01708         
01709         void C_API_Slots::_insertAnnotation(const char * c, double x, double y)
01710         {
01711                 fToS->insertAnnotation(c,x,y);
01712         }
01713         
01714         void C_API_Slots::_setNumericalValues(tc_matrix t)
01715         {
01716                 fToS->setNumericalValues(t);
01717         }
01718         
01719         void Core_FtoS::setNumericalValues(tc_matrix t)
01720         {
01721                 QSemaphore * s = new QSemaphore(1);
01722                 DataTable<qreal> * dat = ConvertValue(t);
01723                 s->acquire();
01724                 emit setNumericalValues(s,*dat);
01725                 delete dat;
01726                 s->acquire();
01727                 s->release();
01728                 delete s;
01729         }
01730         
01731         void C_API_Slots::_setNumericalValue(const char * s, double v)
01732         {
01733                 fToS->setNumericalValue(s,v);
01734         }
01735         
01736         void Core_FtoS::setNumericalValue(const char * c, double v)
01737         {
01738                 QSemaphore * s = new QSemaphore(1);
01739                 s->acquire();
01740                 emit setNumericalValue(s,ConvertValue(c),v);
01741                 s->acquire();
01742                 s->release();
01743                 delete s;
01744         }
01745         
01746         void C_API_Slots::_setTextValues(tc_table t)
01747         {
01748                 fToS->setTextValues(t);
01749         }
01750 
01751         void Core_FtoS::setTextValues(tc_table t)
01752         {
01753                 QSemaphore * s = new QSemaphore(1);
01754                 TextDataTable * dat = ConvertValue(t);
01755                 s->acquire();
01756                 emit setTextValues(s,*dat);
01757                 delete dat;
01758                 s->acquire();
01759                 s->release();
01760                 delete s;
01761         }
01762         
01763         void C_API_Slots::_setTextValue(const char * s, const char *v)
01764         {
01765                 fToS->setTextValue(s,v);
01766         }
01767 
01768         void Core_FtoS::setTextValue(const char * c, const char *v)
01769         {
01770                 QSemaphore * s = new QSemaphore(1);
01771                 s->acquire();
01772                 emit setTextValue(s,ConvertValue(c),ConvertValue(v));
01773                 s->acquire();
01774                 s->release();
01775                 delete s;
01776         }
01777         
01778         double C_API_Slots::_getNumericalValue(const char* s)
01779         {
01780                 return fToS->getNumericalValue(s);
01781         }
01782 
01783         double Core_FtoS::getNumericalValue(const char* c)
01784         {
01785                 QSemaphore * s = new QSemaphore(1);
01786                 double d;
01787                 s->acquire();
01788                 emit getNumericalValue(s, ConvertValue(c), &d);
01789                 s->acquire();
01790                 s->release();
01791                 delete s;
01792                 return d;
01793         }
01794 
01795         const char* C_API_Slots::_getTextValue(const char* s)
01796         {
01797                 return fToS->getTextValue(s);
01798         }
01799 
01800         const char* Core_FtoS::getTextValue(const char* c)
01801         {
01802                 QSemaphore * s = new QSemaphore(1);
01803                 QString d;
01804                 s->acquire();
01805                 emit getTextValue(s, ConvertValue(c), &d);
01806                 s->acquire();
01807                 s->release();
01808                 delete s;
01809                 return ConvertValue(d);
01810         }
01811 
01812         tc_table C_API_Slots::_getTextValueUsingRegex(const char* s)
01813         {
01814                 return fToS->getTextValueUsingRegex(s);
01815         }
01816 
01817         tc_table Core_FtoS::getTextValueUsingRegex(const char* c)
01818         {
01819                 QSemaphore * s = new QSemaphore(1);
01820                 s->acquire();
01821                 DataTable<QString> * p = new DataTable<QString>();
01822                 emit getTextValueUsingRegex(s,ConvertValue(c),p);
01823                 s->acquire();
01824                 s->release();
01825                 delete s;
01826                 tc_table m;
01827                 if (p)
01828                 {
01829                         m = ConvertValue(*p);
01830                         delete p;
01831                         return m;
01832                 }
01833                 m.strings = 0;
01834                 m.rownames.length = m.colnames.length =0;
01835                 m.rownames.strings = m.colnames.strings = 0;
01836                 return m;
01837         }
01838 
01839         tc_matrix C_API_Slots::_getNumericalValueUsingRegex(const char* s)
01840         {
01841                 return fToS->getNumericalValueUsingRegex(s);
01842         }
01843 
01844         tc_matrix Core_FtoS::getNumericalValueUsingRegex(const char* c)
01845         {
01846                 QSemaphore * s = new QSemaphore(1);
01847                 s->acquire();
01848                 DataTable<qreal> * p = new DataTable<qreal>();
01849                 emit getNumericalValueUsingRegex(s, ConvertValue(c),p);
01850                 s->acquire();
01851                 s->release();
01852                 delete s;
01853                 tc_matrix m;
01854                 if (p)
01855                 {
01856                         m = ConvertValue(*p);
01857                         delete p;
01858                         return m;
01859                 }
01860                 m.values = 0;
01861                 m.rownames.length = m.colnames.length = 0;
01862                 m.rownames.strings = m.colnames.strings = 0;
01863                 return m;
01864         }
01865 
01866         void Core_FtoS::zoom(double x)
01867         {
01868                 emit zoom(0,x);
01869         }
01870 
01871         void Core_FtoS::viewWindow(const char * s)
01872         {
01873                 emit viewWindow(0,s);
01874         }
01875 
01876 
01877         long Core_FtoS::find(const char* c)
01878         {
01879                 QSemaphore * s = new QSemaphore(1);
01880                 ItemHandle * p;
01881                 s->acquire();
01882                 emit find(s,&p,ConvertValue(c));
01883                 s->acquire();
01884                 s->release();
01885                 delete s;
01886                 return ConvertValue(p);
01887         }
01888 
01889         tc_items Core_FtoS::findItems(tc_strings c)
01890         {
01891                 QSemaphore * s = new QSemaphore(1);
01892                 QList<ItemHandle*>* p = new QList<ItemHandle*>;
01893                 s->acquire();
01894                 emit findItems(s,p,ConvertValue(c));
01895                 s->acquire();
01896                 s->release();
01897                 delete s;
01898                 tc_items A = ConvertValue(*p);
01899                 delete p;
01900                 return A;
01901         }
01902 
01903         tc_items Core_FtoS::findItemsUsingRegex(const char* c)
01904         {
01905                 QSemaphore * s = new QSemaphore(1);
01906                 QList<ItemHandle*>* p = new QList<ItemHandle*>;
01907                 s->acquire();
01908                 emit findItemsUsingRegex(s,p,ConvertValue(c));
01909                 s->acquire();
01910                 s->release();
01911                 delete s;
01912                 tc_items A = ConvertValue(*p);
01913                 delete p;
01914                 return A;
01915         }
01916 
01917         void Core_FtoS::select(long o)
01918         {
01919                 QSemaphore * s = new QSemaphore(1);
01920                 s->acquire();
01921                 emit select(s,ConvertValue(o));
01922                 s->acquire();
01923                 s->release();
01924                 delete s;
01925         }
01926 
01927         void Core_FtoS::deselect()
01928         {
01929                 QSemaphore * s = new QSemaphore(1);
01930                 s->acquire();
01931                 emit deselect(s);
01932                 s->acquire();
01933                 s->release();
01934                 delete s;
01935         }
01936 
01937         tc_items Core_FtoS::allItems()
01938         {
01939                 QSemaphore * s = new QSemaphore(1);
01940                 QList<ItemHandle*>* p = new QList<ItemHandle*>;
01941                 s->acquire();
01942                 emit allItems(s,p);
01943                 s->acquire();
01944                 s->release();
01945                 delete s;
01946                 tc_items A = ConvertValue(*p);
01947                 delete p;
01948                 return A;
01949         }
01950 
01951         tc_items Core_FtoS::itemsOfFamily(const char * f)
01952         {
01953                 QSemaphore * s = new QSemaphore(1);
01954                 QList<ItemHandle*>* p = new QList<ItemHandle*>;
01955                 s->acquire();
01956                 emit itemsOfFamily(s,p,ConvertValue(f));
01957                 s->acquire();
01958                 s->release();
01959                 delete s;
01960                 tc_items A = ConvertValue(*p);
01961                 delete p;
01962                 return A;
01963         }
01964 
01965         tc_items Core_FtoS::itemsOfFamily(const char * f, tc_items a)
01966         {
01967                 QSemaphore * s = new QSemaphore(1);
01968                 QList<ItemHandle*> * list = ConvertValue(a);
01969                 QList<ItemHandle*>* p = new QList<ItemHandle*>;
01970                 s->acquire();
01971                 emit itemsOfFamily(s,p,*list,ConvertValue(f));
01972                 s->acquire();
01973                 s->release();
01974                 delete s;
01975                 tc_items A = ConvertValue(*p);
01976                 delete p;
01977                 delete list;
01978                 return A;
01979         }
01980 
01981         tc_items Core_FtoS::selectedItems()
01982         {
01983                 QSemaphore * s = new QSemaphore(1);
01984                 QList<ItemHandle*>* p = new QList<ItemHandle*>;
01985                 s->acquire();
01986                 emit selectedItems(s,p);
01987                 s->acquire();
01988                 s->release();
01989                 delete s;
01990                 tc_items A = ConvertValue(*p);
01991                 delete p;
01992                 return A;
01993         }
01994 
01995         const char* Core_FtoS::getName(long o)
01996         {
01997                 QSemaphore * s = new QSemaphore(1);
01998                 QString p;
01999                 s->acquire();
02000                 emit getName(s,&p,ConvertValue(o));
02001                 s->acquire();
02002                 s->release();
02003                 delete s;
02004                 return ConvertValue(p);
02005         }
02006         
02007         const char* Core_FtoS::getUniqueName(long o)
02008         {
02009                 QSemaphore * s = new QSemaphore(1);
02010                 QString p;
02011                 s->acquire();
02012                 emit getUniqueName(s,&p,ConvertValue(o));
02013                 s->acquire();
02014                 s->release();
02015                 delete s;
02016                 return ConvertValue(p);
02017         }
02018 
02019 
02020         void Core_FtoS::setName(long o, const char* c)
02021         {
02022                 QSemaphore * s = new QSemaphore(1);
02023                 s->acquire();
02024                 emit setName(s,ConvertValue(o),ConvertValue(c));
02025                 s->acquire();
02026                 s->release();
02027                 delete s;
02028         }
02029 
02030         tc_strings Core_FtoS::getNames(tc_items a0)
02031         {
02032                 QSemaphore * s = new QSemaphore(1);
02033                 QStringList p;
02034                 s->acquire();
02035                 QList<ItemHandle*> * list = ConvertValue(a0);
02036                 emit getNames(s,&p,*list);
02037                 s->acquire();
02038                 s->release();
02039                 delete s;
02040                 delete list;
02041                 return ConvertValue(p);
02042         }
02043 
02044         tc_strings Core_FtoS::getUniqueNames(tc_items a0)
02045         {
02046                 QSemaphore * s = new QSemaphore(1);
02047                 QStringList p;
02048                 s->acquire();
02049                 QList<ItemHandle*> * list = ConvertValue(a0);
02050                 emit getUniqueNames(s,&p,*list);
02051                 s->acquire();
02052                 s->release();
02053                 delete s;
02054                 delete list;
02055                 return ConvertValue(p);
02056         }
02057 
02058         const char* Core_FtoS::getFamily(long a0)
02059         {
02060                 QSemaphore * s = new QSemaphore(1);
02061                 QString p;
02062                 s->acquire();
02063                 emit getFamily(s,&p,ConvertValue(a0));
02064                 s->acquire();
02065                 s->release();
02066                 delete s;
02067                 return ConvertValue(p);
02068         }
02069 
02070         int Core_FtoS::isA(long a0, const char* name)
02071         {
02072                 QSemaphore * s = new QSemaphore(1);
02073                 int p = 0;
02074                 s->acquire();
02075                 emit isA(s,&p,ConvertValue(a0),ConvertValue(name));
02076                 s->acquire();
02077                 s->release();
02078                 delete s;
02079                 return p;
02080         }
02081 
02082         void Core_FtoS::removeItem(long a0)
02083         {
02084                 QSemaphore * s = new QSemaphore(1);
02085                 s->acquire();
02086                 emit removeItem(s,ConvertValue(a0));
02087                 s->acquire();
02088                 s->release();
02089                 delete s;
02090         }
02091 
02092         long Core_FtoS::insertItem(const char* a0, const char* a1)
02093         {
02094                 QSemaphore * s = new QSemaphore(1);
02095                 ItemHandle * item = 0;
02096                 s->acquire();
02097                 emit insertItem(s,&item,ConvertValue(a0),ConvertValue(a1));
02098                 s->acquire();
02099                 s->release();
02100                 delete s;
02101                 return ConvertValue(item);
02102         }
02103 
02104         void Core_FtoS::setPos(long a0,double a1,double a2)
02105         {
02106                 QSemaphore * s = new QSemaphore(1);
02107                 s->acquire();
02108                 emit setPos(s,ConvertValue(a0),a1,a2);
02109                 s->acquire();
02110                 s->release();
02111                 delete s;
02112         }
02113 
02114         void Core_FtoS::setPos(tc_items a0,tc_matrix m)
02115         {
02116                 QSemaphore * s = new QSemaphore(1);
02117                 s->acquire();
02118                 QList<ItemHandle*> * list = ConvertValue(a0);
02119                 DataTable<qreal> * dat = ConvertValue(m);
02120                 emit setPos(s,*list,*dat);
02121                 s->acquire();
02122                 s->release();
02123                 delete dat;
02124                 delete list;
02125                 delete s;
02126         }
02127 
02128         tc_matrix Core_FtoS::getPos(tc_items a0)
02129         {
02130                 QSemaphore * s = new QSemaphore(1);
02131                 s->acquire();
02132                 QList<ItemHandle*> * list = ConvertValue(a0);
02133                 DataTable<qreal> * p = new DataTable<qreal>;
02134                 emit getPos(s,*list,p);
02135                 s->acquire();
02136                 s->release();
02137                 delete list;
02138                 delete s;
02139                 tc_matrix m;
02140                 if (p)
02141                 {
02142                         m = ConvertValue(*p);
02143                         delete p;
02144                         return m;
02145                 }
02146                 m.values = 0;
02147                 m.rownames.length = m.colnames.length = 0;
02148                 m.rownames.strings = m.colnames.strings = 0;
02149                 return m;
02150         }
02151 
02152 
02153         double Core_FtoS::getY(long a0)
02154         {
02155                 QSemaphore * s = new QSemaphore(1);
02156                 qreal p;
02157                 s->acquire();
02158                 emit getY(s,&p,ConvertValue(a0));
02159                 s->acquire();
02160                 s->release();
02161                 delete s;
02162                 return (double)p;
02163         }
02164 
02165         double Core_FtoS::getX(long a0)
02166         {
02167                 QSemaphore * s = new QSemaphore(1);
02168                 qreal p;
02169                 s->acquire();
02170                 emit getX(s,&p,ConvertValue(a0));
02171                 s->acquire();
02172                 s->release();
02173                 delete s;
02174                 return (double)p;
02175         }
02176 
02177         void Core_FtoS::moveSelected(double a0,double a1)
02178         {
02179                 QSemaphore * s = new QSemaphore(1);
02180                 s->acquire();
02181                 emit moveSelected(s,a0,a1);
02182                 s->acquire();
02183                 s->release();
02184                 delete s;
02185         }
02186 
02187         void Core_FtoS::clearText()
02188         {
02189                 QSemaphore * s = new QSemaphore(1);
02190                 s->acquire();
02191                 emit clearText(s);
02192                 s->acquire();
02193                 s->release();
02194                 delete s;
02195         }
02196 
02197         void Core_FtoS::outputTable(tc_matrix m)
02198         {
02199                 QSemaphore * s = new QSemaphore(1);
02200                 s->acquire();
02201                 DataTable<qreal> * dat = ConvertValue(m);
02202                 emit outputTable(s,*dat);
02203                 s->acquire();
02204                 s->release();
02205                 delete s;
02206                 delete dat;
02207         }
02208 
02209         void Core_FtoS::outputText(const char * c)
02210         {
02211                 QSemaphore * s = new QSemaphore(1);
02212                 s->acquire();
02213                 emit outputText(s,ConvertValue(c));
02214                 s->acquire();
02215                 s->release();
02216                 delete s;
02217         }
02218 
02219         void Core_FtoS::errorReport(const char * c)
02220         {
02221                 QSemaphore * s = new QSemaphore(1);
02222                 s->acquire();
02223                 emit errorReport(s,ConvertValue(c));
02224                 s->acquire();
02225                 s->release();
02226                 delete s;
02227         }
02228 
02229         void Core_FtoS::printFile(const char * c)
02230         {
02231                 QSemaphore * s = new QSemaphore(1);
02232                 s->acquire();
02233                 emit printFile(s,ConvertValue(c));
02234                 s->acquire();
02235                 s->release();
02236                 delete s;
02237         }
02238 
02239         void Core_FtoS::createInputWindow(tc_matrix m, const char* title,const char* fname)
02240         {
02241                 DataTable<qreal>* dat = ConvertValue(m);
02242                 QSemaphore * s = new QSemaphore(1);
02243                 s->acquire();
02244                 emit createInputWindow(s,*dat,ConvertValue(title),ConvertValue(fname));
02245                 s->acquire();
02246                 s->release();
02247                 delete s;
02248                 delete dat;
02249         }
02250 
02251         void Core_FtoS::createInputWindow(long ptr, tc_matrix m, const char* title, MatrixInputFunction f)
02252         {
02253                 DataTable<qreal>* dat = ConvertValue(m);
02254                 QSemaphore * s = new QSemaphore(1);
02255                 s->acquire();
02256                 emit createInputWindow(s,ptr,*dat,ConvertValue(title),f);
02257                 s->acquire();
02258                 s->release();
02259                 delete s;
02260                 delete dat;
02261         }
02262         
02263         void Core_FtoS::createSliders(long c, tc_matrix m, MatrixInputFunction f)
02264         {
02265                 CThread * cthread = static_cast<CThread*>((void*)(c));
02266                 DataTable<qreal>* dat = ConvertValue(m);
02267                 QSemaphore * s = new QSemaphore(1);
02268                 s->acquire();
02269                 emit createSliders(s,cthread,*dat,f);
02270                 s->acquire();
02271                 s->release();
02272                 delete s;
02273                 delete dat;
02274         }
02275 
02276         void Core_FtoS::addInputWindowOptions(const char * a, int i, int j, tc_strings list)
02277         {
02278                 QSemaphore * s = new QSemaphore(1);
02279                 s->acquire();
02280                 emit addInputWindowOptions(s,ConvertValue(a),i,j,ConvertValue(list));
02281                 s->acquire();
02282                 s->release();
02283                 delete s;
02284         }
02285 
02286         void Core_FtoS::addInputWindowCheckbox(const char * a, int i, int j)
02287         {
02288                 QSemaphore * s = new QSemaphore(1);
02289                 s->acquire();
02290                 emit addInputWindowCheckbox(s,ConvertValue(a),i,j);
02291                 s->acquire();
02292                 s->release();
02293                 delete s;
02294         }
02295 
02296         void Core_FtoS::openNewWindow(const char* c)
02297         {
02298                 QSemaphore * s = new QSemaphore(1);
02299                 s->acquire();
02300                 emit openNewWindow(s,ConvertValue(c));
02301                 s->acquire();
02302                 s->release();
02303                 delete s;
02304         }
02305 
02306         int Core_FtoS::isWindows()
02307         {
02308                 int i=0;
02309                 QSemaphore * s = new QSemaphore(1);
02310                 s->acquire();
02311                 emit isWindows(s,&i);
02312                 s->acquire();
02313                 s->release();
02314                 delete s;
02315                 return i;
02316         }
02317 
02318         int Core_FtoS::isMac()
02319         {
02320                 int i=0;
02321                 QSemaphore * s = new QSemaphore(1);
02322                 s->acquire();
02323                 emit isMac(s,&i);
02324                 s->acquire();
02325                 s->release();
02326                 delete s;
02327                 return i;
02328         }
02329 
02330         int Core_FtoS::isLinux()
02331         {
02332                 int i=0;
02333                 QSemaphore * s = new QSemaphore(1);
02334                 s->acquire();
02335                 emit isLinux(s,&i);
02336                 s->acquire();
02337                 s->release();
02338                 delete s;
02339                 return i;
02340         }
02341 
02342         const char* Core_FtoS::appDir()
02343         {
02344                 QString dir;
02345                 QSemaphore * s = new QSemaphore(1);
02346                 s->acquire();
02347                 emit appDir(s,&dir);
02348                 s->acquire();
02349                 s->release();
02350                 delete s;
02351                 return ConvertValue(dir);
02352         }
02353 
02354         const char* Core_FtoS::homeDir()
02355         {
02356                 QString dir;
02357                 QSemaphore * s = new QSemaphore(1);
02358                 s->acquire();
02359                 emit homeDir(s,&dir);
02360                 s->acquire();
02361                 s->release();
02362                 delete s;
02363                 return ConvertValue(dir);
02364         }
02365 
02366         tc_matrix Core_FtoS::getNumericalData(long o,const char* c)
02367         {
02368                 QSemaphore * s = new QSemaphore(1);
02369                 DataTable<qreal> * p = new DataTable<qreal>;
02370                 s->acquire();
02371                 emit getNumericalData(s,p,ConvertValue(o),ConvertValue(c));
02372                 s->acquire();
02373                 s->release();
02374                 delete s;
02375                 tc_matrix m;
02376                 if (p)
02377                 {
02378                         m = ConvertValue(*p);
02379                         delete p;
02380                         return m;
02381                 }
02382                 m.values = 0;
02383                 m.rownames.length = m.colnames.length =0;
02384                 m.rownames.strings = m.colnames.strings = 0;
02385                 return m;
02386         }
02387 
02388         void Core_FtoS::setNumericalData(long o, const char * c, tc_matrix M)
02389         {
02390                 DataTable<qreal>* dat = ConvertValue(M);
02391                 QSemaphore * s = new QSemaphore(1);
02392                 s->acquire();
02393                 emit setNumericalData(s,ConvertValue(o),ConvertValue(c),*dat);
02394                 s->acquire();
02395                 s->release();
02396                 delete s;
02397                 delete dat;
02398         }
02399         
02400         tc_table Core_FtoS::getTextData(long o,const char* c)
02401         {
02402                 QSemaphore * s = new QSemaphore(1);
02403                 DataTable<QString> * p = new DataTable<QString>;
02404                 s->acquire();
02405                 emit getTextData(s,p,ConvertValue(o),ConvertValue(c));
02406                 s->acquire();
02407                 s->release();
02408                 delete s;
02409                 tc_table m;
02410                 if (p)
02411                 {
02412                         m = ConvertValue(*p);
02413                         delete p;
02414                         return m;
02415                 }
02416                 m.strings = 0;
02417                 m.rownames.length = m.colnames.length =0;
02418                 m.rownames.strings = m.colnames.strings = 0;
02419                 return m;
02420         }
02421         
02422         void Core_FtoS::setTextData(long o, const char * c, tc_table M)
02423         {
02424                 DataTable<QString>* dat = ConvertValue(M);
02425                 QSemaphore * s = new QSemaphore(1);
02426                 s->acquire();
02427                 emit setTextData(s,ConvertValue(o),ConvertValue(c),*dat);
02428                 s->acquire();
02429                 s->release();
02430                 delete s;
02431                 delete dat;
02432         }
02433 
02434         tc_strings Core_FtoS::getNumericalDataNames(long o)
02435         {
02436                 QStringList p;
02437                 QSemaphore * s = new QSemaphore(1);
02438                 s->acquire();
02439                 emit getNumericalDataNames(s,&p,ConvertValue(o));
02440                 s->acquire();
02441                 s->release();
02442                 delete s;
02443                 return ConvertValue(p);
02444         }
02445 
02446         tc_strings Core_FtoS::getTextDataNames(long o)
02447         {
02448                 QStringList p;
02449                 QSemaphore * s = new QSemaphore(1);
02450                 s->acquire();
02451                 emit getTextDataNames(s,&p,ConvertValue(o));
02452                 s->acquire();
02453                 s->release();
02454                 delete s;
02455                 return ConvertValue(p);
02456         }
02457 
02458         tc_items Core_FtoS::getChildren(long o)
02459         {
02460                 QSemaphore * s = new QSemaphore(1);
02461                 QList<ItemHandle*>* p = new QList<ItemHandle*>;
02462                 s->acquire();
02463                 emit getChildren(s,p,ConvertValue(o));
02464                 s->acquire();
02465                 s->release();
02466                 delete s;
02467                 tc_items A = ConvertValue(*p);
02468                 delete p;
02469                 return A;
02470         }
02471 
02472         long Core_FtoS::getParent(long o)
02473         {
02474                 ItemHandle * p = 0;
02475                 QSemaphore * s = new QSemaphore(1);
02476                 s->acquire();
02477                 emit getParent(s,&p,ConvertValue(o));
02478                 s->acquire();
02479                 s->release();
02480                 delete s;
02481                 return ConvertValue(p);
02482         }
02483         
02484         const char * Core_FtoS::annotation()
02485         {
02486                 QSemaphore * s = new QSemaphore(1);
02487                 QString a;
02488                 s->acquire();
02489                 emit annotations(s,&a);
02490                 s->acquire();
02491                 s->release();
02492                 delete s;
02493                 return ConvertValue(a);
02494         }
02495         
02496         void Core_FtoS::insertAnnotation(const char * c, double x, double y)
02497         {
02498                 QSemaphore * s = new QSemaphore(1);
02499                 QString a = ConvertValue(c);
02500                 s->acquire();
02501                 emit insertAnnotation(s,a,x,y);
02502                 s->acquire();
02503                 s->release();
02504                 delete s;
02505         }
02506 
02507         void C_API_Slots::getNumber(QSemaphore* s,double* p,const QString& name)
02508     {
02509         if (p)
02510         {
02511             (*p) = QInputDialog::getDouble(mainWindow,tr("Get Number"),name);
02512         }
02513         if (s)
02514             s->release();
02515     }
02516 
02517     void C_API_Slots::getString(QSemaphore* s,QString* p,const QString& name)
02518     {
02519         if (p)
02520         {
02521             (*p) = QInputDialog::getText(mainWindow,tr("Get Text"),name);
02522             (*p).replace(tr("."),tr("_"));
02523         }
02524         if (s)
02525             s->release();
02526     }
02527 
02528     void C_API_Slots::getNumbers(QSemaphore* s,const QStringList& names,DataTable<qreal>* res)
02529     {
02530         QDialog * dialog = new QDialog(mainWindow);
02531 
02532         QGridLayout * layout = new QGridLayout;
02533 
02534         QList< QDoubleSpinBox* > spinBoxes;
02535         for (int i=0; i < names.size(); ++i)
02536         {
02537             QDoubleSpinBox * spinBox = new QDoubleSpinBox(dialog);
02538             spinBox->setRange(-1.0E300,1.0E300);
02539 
02540             spinBoxes += spinBox;
02541             layout->addWidget( new QLabel(names[i],dialog), i, 0 );
02542             layout->addWidget( spinBox, i, 1 );
02543         }
02544 
02545         QPushButton * ok = new QPushButton(tr("Done"), mainWindow);
02546         connect(ok,SIGNAL(released()),dialog,SLOT(accept()));
02547 
02548         layout->addWidget(ok, names.size(), 1 );
02549         dialog->setLayout(layout);
02550         dialog->exec();
02551 
02552         if (res)
02553         {
02554                         res->setRowNames(names);
02555             for (int i=0; i < spinBoxes.size() && i < names.size(); ++i)
02556                 if (spinBoxes[i])
02557                     (*res)(i,0) = spinBoxes[i]->value();
02558         }
02559 
02560         if (s)
02561             s->release();
02562     }
02563 
02564     void C_API_Slots::getFilename(QSemaphore* s,QString* p)
02565     {
02566         if (p)
02567         {
02568             QString file = QFileDialog::getOpenFileName(mainWindow,tr("Select file"));
02569             if (!file.isNull() && !file.isEmpty())
02570                 (*p) = file;
02571         }
02572         if (s)
02573             s->release();
02574     }
02575 
02576     void C_API_Slots::getStringListItemSelected(QListWidgetItem * item)
02577     {
02578         if (item)
02579             getStringListNumber = getStringList.currentRow();
02580         if (getStringDialog)
02581             getStringDialog->accept();
02582     }
02583 
02584     void C_API_Slots::getStringListRowChanged ( int  )
02585     {
02586         if (getStringList.currentItem())
02587             getStringListNumber = getStringListText.indexOf(getStringList.currentItem()->text());
02588     }
02589 
02590     void C_API_Slots::getStringListCanceled (  )
02591     {
02592         getStringListNumber = -1;
02593     }
02594 
02595     void C_API_Slots::getStringSearchTextEdited ( const QString & text )
02596     {
02597         getStringList.clear();
02598 
02599         QStringList list;
02600 
02601         if (text.isEmpty())
02602             list = getStringListText;
02603         else
02604             for (int i=0; i < getStringListText.size(); ++i)
02605                 if (getStringListText[i].toLower().contains(text.toLower()))
02606                     list << getStringListText[i];
02607 
02608         getStringList.addItems(list);
02609         getStringList.setCurrentRow(0);
02610     }
02611 
02612     void C_API_Slots::getSelectedString(QSemaphore* s,int* p,const QString& name, const QStringList& list0,const QString& init)
02613     {
02614         int option = 0;
02615         
02616         if (p)
02617         {
02618             getStringListText.clear();
02619             if (option == 0 && !getStringDialog)
02620             {
02621                 getStringDialog = new QDialog(mainWindow);
02622                 getStringDialog->setSizeGripEnabled (true);
02623                 QVBoxLayout * layout = new QVBoxLayout;
02624                 layout->addWidget(&getStringListLabel);
02625                 layout->addWidget(&getStringList);
02626                 QHBoxLayout * buttonsLayout = new QHBoxLayout;
02627 
02628                 QLineEdit * search = new QLineEdit(tr("Search"));
02629                 connect(search,SIGNAL(textEdited(const QString &)),this,SLOT(getStringSearchTextEdited(const QString &)));
02630 
02631                 QPushButton * okButton = new QPushButton(tr("OK"));
02632                 QPushButton * cancelButton = new QPushButton(tr("Cancel"));
02633                 connect(okButton,SIGNAL(released()),getStringDialog,SLOT(accept()));
02634                 connect(cancelButton,SIGNAL(released()),getStringDialog,SLOT(reject()));
02635 
02636                 buttonsLayout->addWidget(okButton,1,Qt::AlignLeft);
02637                 buttonsLayout->addWidget(cancelButton,1,Qt::AlignLeft);
02638                 buttonsLayout->addStretch(2);
02639                 buttonsLayout->addWidget(search,5,Qt::AlignRight);
02640 
02641                 layout->addLayout(buttonsLayout);
02642 
02643                 connect(&getStringList,SIGNAL(itemActivated(QListWidgetItem * item)),this,SLOT(getStringListItemSelected(QListWidgetItem * item)));
02644                 connect(&getStringList,SIGNAL(currentRowChanged (int)),this,SLOT(getStringListRowChanged (int)));
02645                 connect(getStringDialog,SIGNAL(rejected()),this,SLOT(getStringListCanceled()));
02646 
02647                 getStringDialog->setLayout(layout);
02648             }
02649 
02650             QStringList list = list0;
02651             bool ok;
02652             QRegExp regex(QString("([A-Za-z0-9])_([A-Za-z0-9])"));
02653 
02654                         int index = list.indexOf(init);
02655                         if (index < 0) index = 0;
02656 
02657             for (int i=0; i < list.size(); ++i)
02658                 list[i].replace(regex,tr("\\1.\\2"));
02659 
02660             if (option == 0 && !list0.isEmpty())
02661             {
02662                 getStringListLabel.setText(name);
02663                 getStringListText = list;
02664                 getStringList.clear();
02665                 getStringList.addItems(list);
02666                 getStringList.setCurrentRow(index);
02667                 getStringDialog->exec();
02668                 (*p) = getStringListNumber;
02669             }
02670             else
02671             {
02672                 QString s = QInputDialog::getItem(mainWindow,tr("Get Text"),name,list,index,false,&ok);
02673                 if (ok)
02674                     (*p) = list.indexOf(s);
02675                 else
02676                     (*p) = -1;
02677             }
02678         }
02679         if (s)
02680             s->release();
02681     }
02682 
02683         void C_API_Slots::askQuestion(QSemaphore* s, const QString& msg, int * x)
02684         {
02685                 QMessageBox::StandardButton ans = QMessageBox::question(mainWindow,tr("Question"),msg,QMessageBox::Yes | QMessageBox::No);
02686 
02687                 if (x)
02688 
02689                         if (ans == QMessageBox::Yes)
02690                                 (*x) = 1;
02691                         else
02692                                 (*x) = 0;
02693 
02694                 if (s)
02695                         s->release();
02696         }
02697 
02698         void C_API_Slots::messageDialog(QSemaphore* s, const QString& msg)
02699         {
02700                 QMessageBox::information(mainWindow,tr("Message"),msg);
02701 
02702                 if (s)
02703                         s->release();
02704         }
02705         
02706         void C_API_Slots::openFile(QSemaphore* s,const QString& file)
02707         {
02708                 mainWindow->open(file);
02709                 if (s)
02710                         s->release();
02711         }
02712 
02713         void C_API_Slots::saveToFile(QSemaphore* s,const QString& file)
02714         {
02715                 emit saveNetwork(file);
02716                 if (s)
02717                         s->release();
02718         }
02719 
02720     const char* C_API_Slots::_getString(const char* title)
02721     {
02722         return fToS->getString(title);
02723     }
02724 
02725     const char* C_API_Slots::_getFilename()
02726     {
02727         return fToS->getFilename();
02728     }
02729 
02730     int C_API_Slots::_getSelectedString(const char* title,tc_strings list,const char* c)
02731     {
02732         return fToS->getSelectedString(title,list,c);
02733     }
02734 
02735     double C_API_Slots::_getNumber(const char* title)
02736     {
02737         return fToS->getNumber(title);
02738     }
02739 
02740     tc_matrix C_API_Slots::_getNumbers(tc_strings names)
02741     {
02742         return fToS->getNumbers(names);
02743     }
02744 
02745         int C_API_Slots::_askQuestion(const char* msg)
02746     {
02747         return fToS->askQuestion(msg);
02748     }
02749 
02750         void C_API_Slots::_messageDialog(const char* msg)
02751     {
02752         return fToS->messageDialog(msg);
02753     }
02754     
02755     void C_API_Slots::_openFile(const char* file)
02756     {
02757         return fToS->openFile(file);
02758     }
02759     
02760      void C_API_Slots::_saveToFile(const char* file)
02761     {
02762         return fToS->saveToFile(file);
02763     }
02764 
02765     double Core_FtoS::getNumber(const char* c)
02766     {
02767         //qDebug() << "get number dialog";
02768         QSemaphore * s = new QSemaphore(1);
02769         qreal p;
02770         s->acquire();
02771         emit getNumber(s,&p,ConvertValue(c));
02772         s->acquire();
02773         s->release();
02774         delete s;
02775         return (double)p;
02776     }
02777 
02778     tc_matrix Core_FtoS::getNumbers(tc_strings c)
02779     {
02780         QSemaphore * s = new QSemaphore(1);
02781                 DataTable<qreal> res;
02782                 res.resize(c.length,1);
02783         s->acquire();
02784         emit getNumbers(s,ConvertValue(c), &res);
02785         s->acquire();
02786         s->release();
02787         delete s;
02788                 return ConvertValue(res);
02789     }
02790 
02791     const char* Core_FtoS::getString(const char* c)
02792     {
02793         //qDebug() << "get string dialog";
02794         QSemaphore * s = new QSemaphore(1);
02795         QString p;
02796         s->acquire();
02797         emit getString(s,&p,ConvertValue(c));
02798         s->acquire();
02799         s->release();
02800         delete s;
02801         return ConvertValue(p);
02802     }
02803 
02804     const char* Core_FtoS::getFilename()
02805     {
02806         QSemaphore * s = new QSemaphore(1);
02807         QString p;
02808         s->acquire();
02809         emit getFilename(s,&p);
02810         s->acquire();
02811         s->release();
02812         delete s;
02813         return ConvertValue(p);
02814     }
02815 
02816         int Core_FtoS::askQuestion(const char* c)
02817     {
02818         QSemaphore * s = new QSemaphore(1);
02819         s->acquire();
02820                 int x;
02821         emit askQuestion(s,ConvertValue(c), &x);
02822         s->acquire();
02823         s->release();
02824         delete s;
02825                 return x;
02826     }
02827 
02828         void Core_FtoS::messageDialog(const char* c)
02829     {
02830         QSemaphore * s = new QSemaphore(1);
02831         s->acquire();
02832         emit messageDialog(s,ConvertValue(c));
02833         s->acquire();
02834         s->release();
02835         delete s;
02836     }
02837     
02838         void Core_FtoS::openFile(const char* c)
02839     {
02840         QSemaphore * s = new QSemaphore(1);
02841         s->acquire();
02842         emit openFile(s,ConvertValue(c));
02843         s->acquire();
02844         s->release();
02845         delete s;
02846     }
02847     
02848         void Core_FtoS::saveToFile(const char* c)
02849     {
02850         QSemaphore * s = new QSemaphore(1);
02851         s->acquire();
02852         emit saveToFile(s,ConvertValue(c));
02853         s->acquire();
02854         s->release();
02855         delete s;
02856     }
02857 
02858     int Core_FtoS::getSelectedString(const char* c, tc_strings list,const char* c1)
02859     {
02860         //qDebug() << "get item dialog";
02861         QSemaphore * s = new QSemaphore(1);
02862         int p;
02863         s->acquire();
02864         emit getSelectedString(s,&p,ConvertValue(c),ConvertValue(list),ConvertValue(c1));
02865         s->acquire();
02866         s->release();
02867         delete s;
02868         return p;
02869     }
02870     
02871     void C_API_Slots::escapeSlot(const QWidget* )
02872         {
02873                 if (temporarilyColorChanged.size() > 0)
02874                 {
02875                         NodeGraphicsItem::Shape * shape = 0;
02876                         ConnectionGraphicsItem * connection = 0;
02877                         for (int i=0; i < temporarilyColorChanged.size(); ++i)
02878                                 if (shape = qgraphicsitem_cast<NodeGraphicsItem::Shape*>(temporarilyColorChanged[i]))
02879                                 {
02880                                         shape->setPen(shape->defaultPen);
02881                                         shape->setBrush(shape->defaultBrush);
02882                                 }
02883                                 else
02884                                         if (connection = ConnectionGraphicsItem::cast(temporarilyColorChanged[i]))
02885                                         {
02886                                                 connection->setPen(connection->defaultPen);
02887                                         }
02888                         temporarilyColorChanged.clear();
02889                 }
02890                 
02891                 NodeGraphicsItem * node;
02892                 
02893                 if (temporarilyChangedSize.size() > 0)
02894                 {
02895                         for (int i=0; i < temporarilyChangedSize.size(); ++i)
02896                                 if (node = temporarilyChangedSize[i].first)
02897                                 {
02898                                         QPointF p = node->scenePos();
02899                                         node->setBoundingRect( p - temporarilyChangedSize[i].second, p + temporarilyChangedSize[i].second );
02900                                 }
02901                         temporarilyChangedSize.clear();
02902                 }
02903                 
02904                 if (temporarilyChangedAngle.size() > 0)
02905                 {
02906                         for (int i=0; i < temporarilyChangedAngle.size(); ++i)
02907                                 if (node = temporarilyChangedAngle[i].first)
02908                                 {
02909                                         node->rotate( - temporarilyChangedAngle[i].second );
02910                                 }
02911                         temporarilyChangedAngle.clear();
02912                 }
02913         }
02914         
02915         void C_API_Slots::changeGraphics(QSemaphore* s,ItemHandle* h,const QString& file)
02916         {
02917                 if (h)
02918                 {
02919                         QStringList filenames;
02920                         QList<NodeGraphicsItem*> nodesList;
02921                         NodeGraphicsItem * node;
02922 
02923                         for (int i=0; i < h->graphicsItems.size(); ++i)
02924                                 if ((node = NodeGraphicsItem::cast(h->graphicsItems[i])))
02925                                 {
02926                                         nodesList << node;
02927                                         filenames << file;
02928                                 }
02929 
02930                         if (nodesList.size() > 0)
02931                         {
02932                                 ReplaceNodeGraphicsCommand * command = new ReplaceNodeGraphicsCommand(tr("image changed for ") + h->fullName(),nodesList,filenames);
02933                                 if (currentNetwork())
02934                                         currentNetwork()->history.push(command);
02935                         }
02936                 }
02937 
02938                 if (s)
02939                         s->release();
02940         }
02941 
02942         void C_API_Slots::changeArrowHead(QSemaphore* s,ItemHandle* h,const QString& file)
02943         {
02944                 if (h)
02945                 {
02946                         QStringList filenames;
02947                         QList<NodeGraphicsItem*> nodesList;
02948                         ConnectionGraphicsItem * conn;
02949 
02950                         for (int i=0; i < h->graphicsItems.size(); ++i)
02951                                 if ((conn = ConnectionGraphicsItem::cast(h->graphicsItems[i])))
02952                                 {
02953                                         QList<ArrowHeadItem*> arrows = conn->arrowHeads();
02954 
02955                                         for (int j=0; j < arrows.size(); ++j)
02956                                         {
02957                                                 nodesList << arrows[j];
02958                                                 filenames << file;
02959                                         }
02960                                 }
02961 
02962                         if (nodesList.size() > 0)
02963                         {
02964                                 ReplaceNodeGraphicsCommand * command = new ReplaceNodeGraphicsCommand(tr("arrowheads changed for ") + h->fullName(),nodesList,filenames,false);
02965                                 if (currentNetwork())
02966                                         currentNetwork()->history.push(command);
02967                         }
02968                 }
02969 
02970                 if (s)
02971                         s->release();
02972         }
02973         
02974         void C_API_Slots::_setSize(long o, double w, double h, int p)
02975         {
02976                 fToS->setSize(o,w,h,p);
02977         }
02978 
02979         void Core_FtoS::setSize(long o,double w, double h,int p)
02980         {
02981                 QSemaphore * s = new QSemaphore(1);
02982                 s->acquire();
02983                 emit setSize(s,ConvertValue(o),w,h,p);
02984                 s->acquire();
02985                 s->release();
02986         }
02987         
02988         void C_API_Slots::_setAngle(long o, double t,int p)
02989         {
02990                 fToS->setAngle(o,t,p);
02991         }
02992 
02993         void Core_FtoS::setAngle(long o,double t,int p)
02994         {
02995                 QSemaphore * s = new QSemaphore(1);
02996                 s->acquire();
02997                 emit setAngle(s,ConvertValue(o),t,p);
02998                 s->acquire();
02999                 s->release();
03000         }
03001 
03002         double C_API_Slots::_getWidth(long o)
03003         {
03004                 return fToS->getWidth(o);
03005         }
03006 
03007         double Core_FtoS::getWidth(long o)
03008         {
03009                 double d=1.0;
03010                 QSemaphore * s = new QSemaphore(1);
03011                 s->acquire();
03012                 emit getWidth(s,ConvertValue(o),&d);
03013                 s->acquire();
03014                 s->release();
03015                 return d;
03016         }
03017         
03018         double C_API_Slots::_getHeight(long o)
03019         {
03020                 return fToS->getHeight(o);
03021         }
03022 
03023         double Core_FtoS::getHeight(long o)
03024         {
03025                 double d=1.0;
03026                 QSemaphore * s = new QSemaphore(1);
03027                 s->acquire();
03028                 emit getHeight(s,ConvertValue(o),&d);
03029                 s->acquire();
03030                 s->release();
03031                 return d;
03032         }
03033 
03034         const char* C_API_Slots::_getColor(long o)
03035         {
03036                 return fToS->getColor(o);
03037         }
03038 
03039         const char* Core_FtoS::getColor(long o)
03040         {
03041                 QSemaphore * s = new QSemaphore(1);
03042                 QString name("#000000");
03043                 s->acquire();
03044                 emit getColor(s,&name,ConvertValue(o));
03045                 s->acquire();
03046                 s->release();
03047                 return ConvertValue(name);
03048         }
03049 
03050         void C_API_Slots::_setColor(long o,const char * c, int p)
03051         {
03052                 return fToS->setColor(o,c,p);
03053         }
03054 
03055         void Core_FtoS::setColor(long o,const char * c, int p)
03056         {
03057                 QSemaphore * s = new QSemaphore(1);
03058                 s->acquire();
03059                 emit setColor(s,ConvertValue(o),ConvertValue(c),p);
03060                 s->acquire();
03061                 s->release();
03062                 return;
03063         }
03064 
03065         void C_API_Slots::_changeGraphics(long o,const char* f)
03066         {
03067                 fToS->changeGraphics(o,f);
03068         }
03069 
03070         void Core_FtoS::changeGraphics(long o,const char* f)
03071         {
03072                 QSemaphore * s = new QSemaphore(1);
03073                 s->acquire();
03074                 emit changeGraphics(s,ConvertValue(o),ConvertValue(f));
03075                 s->acquire();
03076                 s->release();
03077                 return;
03078         }
03079 
03080         void C_API_Slots::_changeArrowHead(long o,const char* f)
03081         {
03082                 fToS->changeArrowHead(o,f);
03083         }
03084 
03085         void Core_FtoS::changeArrowHead(long o,const char* f)
03086         {
03087                 QSemaphore * s = new QSemaphore(1);
03088                 s->acquire();
03089                 emit changeArrowHead(s,ConvertValue(o),ConvertValue(f));
03090                 s->acquire();
03091                 s->release();
03092                 return;
03093         }
03094         
03095         void C_API_Slots::_screenshot(const char* s, int w, int h)
03096         {
03097                 fToS->screenshot(s,w,h);
03098         }
03099 
03100         void Core_FtoS::screenshot(const char * file, int w, int h)
03101         {
03102                 QSemaphore * s = new QSemaphore(1);
03103                 s->acquire();
03104                 emit screenshot(s,ConvertValue(file),w,h);
03105                 s->acquire();
03106                 s->release();
03107         }
03108         
03109         int C_API_Slots::_screenHeight()
03110         {
03111                 return fToS->screenHeight();
03112         }
03113 
03114         int Core_FtoS::screenHeight()
03115         {
03116                 int h = 0;
03117                 QSemaphore * s = new QSemaphore(1);
03118                 s->acquire();
03119                 emit screenHeight(s,&h);
03120                 s->acquire();
03121                 s->release();
03122                 return h;
03123         }
03124         
03125         int C_API_Slots::_screenWidth()
03126         {
03127                 return fToS->screenWidth();
03128         }
03129 
03130         int Core_FtoS::screenWidth()
03131         {
03132                 int h = 0;
03133                 QSemaphore * s = new QSemaphore(1);
03134                 s->acquire();
03135                 emit screenWidth(s,&h);
03136                 s->acquire();
03137                 s->release();
03138                 return h;
03139         }
03140         
03141         int C_API_Slots::_screenX()
03142         {
03143                 return fToS->screenX();
03144         }
03145 
03146         int Core_FtoS::screenX()
03147         {
03148                 int h = 0;
03149                 QSemaphore * s = new QSemaphore(1);
03150                 s->acquire();
03151                 emit screenX(s,&h);
03152                 s->acquire();
03153                 s->release();
03154                 return h;
03155         }
03156         
03157         int C_API_Slots::_screenY()
03158         {
03159                 return fToS->screenY();
03160         }
03161 
03162         int Core_FtoS::screenY()
03163         {
03164                 int h = 0;
03165                 QSemaphore * s = new QSemaphore(1);
03166                 s->acquire();
03167                 emit screenY(s,&h);
03168                 s->acquire();
03169                 s->release();
03170                 return h;
03171         }
03172         
03173         void C_API_Slots::getColor(QSemaphore* s,QString* name,ItemHandle* handle)
03174         {
03175                 if (handle && name)
03176                 {
03177                         QGraphicsItem * item = 0;
03178                         for (int i=0; i < handle->graphicsItems.size(); ++i)
03179                         {
03180                                 item = handle->graphicsItems[i];
03181                                 if (item)
03182                                 {
03183                                         NodeGraphicsItem * node = NodeGraphicsItem::topLevelNodeItem(item);
03184                                         if (node)
03185                                         {
03186                                                 if (node->shapes.size() > 0 && node->shapes[0])
03187                                                 {
03188                                                         (*name) = node->shapes[0]->defaultBrush.color().name();
03189                                                         break;
03190                                                 }
03191                                         }
03192                                         else
03193                                         {
03194                                                 ConnectionGraphicsItem * connection = ConnectionGraphicsItem::cast(item);
03195                                                 if (connection)
03196                                                 {
03197                                                         (*name) = connection->defaultPen.color().name();
03198                                                         break;
03199                                                 }
03200                                                 else
03201                                                 {
03202                                                         TextGraphicsItem * text = TextGraphicsItem::cast(item);
03203                                                         if (text)
03204                                                         {
03205                                                                 (*name) = text->defaultTextColor().name();
03206                                                         }
03207                                                         else
03208                                                         {
03209                                                                 ControlPoint * cp = ControlPoint::cast(item);
03210                                                                 if (cp)
03211                                                                 {
03212                                                                         (*name) = cp->defaultBrush.color().name();
03213                                                                 }
03214                                                         }
03215                                                 }
03216                                         }
03217                                 }
03218                         }
03219                 }
03220                 if (s)
03221                         s->release();
03222         }
03223 
03224         void C_API_Slots::setColor(QSemaphore* s,ItemHandle* handle,const QString& name, int permanent)
03225         {
03226                 GraphicsScene * scene = currentScene();
03227                 QGraphicsItem* item;
03228                 if (handle && scene)
03229                         for (int i=0; i < handle->graphicsItems.size(); ++i)
03230                         {
03231                                 item = handle->graphicsItems[i];
03232                                 if (item && scene)
03233                                 {
03234                                         QList<QGraphicsItem*> items;
03235                                         QList<QBrush> brushes;
03236                                         QList<QPen> pens;
03237                                         QColor color(name);
03238                                         NodeGraphicsItem * node = NodeGraphicsItem::topLevelNodeItem(item);
03239                                         if (node != 0)
03240                                         {
03241                                                 for (int j=0; j < node->shapes.size(); ++j)
03242                                                 {
03243                                                         NodeGraphicsItem::Shape * aitem = node->shapes[j];
03244 
03245                                                         if (aitem != 0)
03246                                                         {
03247                                                                 QBrush brush = aitem->defaultBrush;
03248                                                                 if (brush.gradient() != 0)
03249                                                                 {
03250                                                                         QGradient gradient(*brush.gradient() );
03251                                                                         QGradientStops stops = gradient.stops();
03252                                                                         if (stops.size() > 0)
03253                                                                         {
03254                                                                                 color.setAlpha(stops[ stops.size() - 1 ].second.alpha());
03255                                                                                 stops[ stops.size() - 1 ].second = color;
03256                                                                                 gradient.setStops(stops);
03257                                                                                 QBrush newBrush(gradient);
03258                                                                                 if (permanent)
03259                                                                                 {
03260                                                                                         brushes += newBrush;
03261                                                                                         items += aitem;
03262                                                                                 }
03263                                                                                 else
03264                                                                                 {
03265                                                                                         aitem->setBrush(newBrush);
03266                                                                                         if (!temporarilyColorChanged.contains(aitem));
03267                                                                                                 temporarilyColorChanged << aitem;
03268                                                                                 }
03269                                                                         }
03270                                                                 }
03271                                                                 else
03272                                                                 {
03273                                                                         color.setAlpha(brush.color().alpha());
03274                                                                         QBrush newBrush(color);
03275                                                                         if (permanent)
03276                                                                         {
03277                                                                                 if (brush.color().name().toLower() == tr("#ffffff") ||
03278                                                                                         brush.color().name().toLower() == tr("#000000"))
03279                                                                                         brushes += brush;
03280                                                                                 else
03281                                                                                         brushes += newBrush;
03282                                                                                 items += aitem;
03283                                                                         }
03284                                                                         else
03285                                                                         {
03286                                                                                 if (brush.color().name().toLower() == tr("#ffffff") ||
03287                                                                                         brush.color().name().toLower() == tr("#000000"))
03288                                                                                         aitem->setBrush(brush);
03289                                                                                 else
03290                                                                                         aitem->setBrush(newBrush);
03291                                                                                 if (!temporarilyColorChanged.contains(aitem))
03292                                                                                         temporarilyColorChanged << aitem;
03293                                                                         }
03294                                                                 }
03295                                                                 QPen newPen(aitem->defaultPen);
03296                                                                 newPen.setColor(QColor(name));
03297                                                                 if (permanent)
03298                                                                 {
03299                                                                         pens += newPen;
03300                                                                 }
03301                                                                 else
03302                                                                 {
03303                                                                         aitem->setPen(newPen);
03304                                                                         temporarilyColorChanged << aitem;
03305                                                                 }
03306                                                         }
03307                                                 }
03308                                         }
03309                                         else
03310                                         {
03311                                                 ConnectionGraphicsItem * connection = ConnectionGraphicsItem::topLevelConnectionItem(item);
03312                                                 if (connection != 0)
03313                                                 {
03314                                                         QPen newPen(color,connection->defaultPen.widthF());
03315                                                         color.setAlpha(connection->defaultPen.color().alpha());
03316                                                         if (permanent)
03317                                                         {
03318                                                                 pens += newPen;
03319                                                                 brushes += QBrush( newPen.color() );
03320                                                                 items += connection;
03321                                                         }
03322                                                         else
03323                                                         {
03324                                                                 connection->setPen(newPen);
03325                                                                 if (!temporarilyColorChanged.contains(connection))
03326                                                                         temporarilyColorChanged << connection;
03327                                                         }
03328                                                 }
03329                                         }
03330                                         if (permanent)
03331                                                 scene->setBrushAndPen(tr("colors changed"),items,brushes,pens);
03332                                 }
03333                         }
03334                         if (s)
03335                                 s->release();
03336         }
03337         
03338         void C_API_Slots::setSize(QSemaphore* s, ItemHandle* item,double w,double h, int permanent)
03339         {
03340                 if (item)
03341                 {
03342                         QSizeF sz(0,0);
03343                         NodeGraphicsItem * node, * mainNode = 0;
03344                         for (int i=0; i < item->graphicsItems.size(); ++i)
03345                                 if ((node = NodeGraphicsItem::cast(item->graphicsItems[i])) &&
03346                                         node->sceneBoundingRect().width() > sz.width() &&
03347                                         node->sceneBoundingRect().height() > sz.height())
03348                                 {
03349                                         mainNode = node;
03350                                 }
03351                         if (mainNode)
03352                         {
03353                                 if (permanent && currentScene())
03354                                 {
03355                                         QPointF p;
03356                                         p.rx() = w / mainNode->sceneBoundingRect().width();
03357                                         p.ry() = h / mainNode->sceneBoundingRect().height();
03358                                         currentScene()->transform(tr("resize ") + item->fullName(), mainNode, p);
03359                                 }
03360                                 else
03361                                 {
03362                                         QPointF dp1(w/2, h/2);
03363                                         QPointF p = mainNode->scenePos();
03364                                         QRectF rect = mainNode->sceneBoundingRect();
03365                                         QPointF dp0( rect.center() - rect.topLeft() );
03366                                         mainNode->setBoundingRect( p - dp1, p + dp1 );
03367                                         
03368                                         bool found = false;
03369                                         for (int i=0; i < temporarilyChangedSize.size(); ++i)
03370                                                 if (mainNode == temporarilyChangedSize[i].first)
03371                                                 {
03372                                                         temporarilyChangedSize[i].second = dp0;
03373                                                         found = true;
03374                                                 }
03375                                         if (!found)
03376                                                 temporarilyChangedSize << QPair<NodeGraphicsItem*,QPointF>(mainNode,dp0);
03377                                 }
03378                         }
03379                 }
03380                 if (s)
03381                         s->release();
03382         }
03383         
03384         void C_API_Slots::getWidth(QSemaphore* s, ItemHandle* item, double* x)
03385         {
03386                 if (item && x)
03387                 {
03388                         QSizeF sz(0,0);
03389                         NodeGraphicsItem * node, * mainNode = 0;
03390                         for (int i=0; i < item->graphicsItems.size(); ++i)
03391                                 if ((node = NodeGraphicsItem::cast(item->graphicsItems[i])) &&
03392                                         node->sceneBoundingRect().width() > sz.width() &&
03393                                         node->sceneBoundingRect().height() > sz.height())
03394                                 {
03395                                         mainNode = node;
03396                                         sz = node->sceneBoundingRect().size();
03397                                 }
03398                         if (mainNode)
03399                         {
03400                                 (*x) = mainNode->sceneBoundingRect().width();
03401                         }
03402                 }
03403                 if (s)
03404                         s->release();
03405         }
03406         
03407         void C_API_Slots::getHeight(QSemaphore* s, ItemHandle* item,double* x)
03408         {
03409                 if (item && x)
03410                 {
03411                         QSizeF sz(0,0);
03412                         NodeGraphicsItem * node, * mainNode = 0;
03413                         for (int i=0; i < item->graphicsItems.size(); ++i)
03414                                 if ((node = NodeGraphicsItem::cast(item->graphicsItems[i])) &&
03415                                         node->sceneBoundingRect().width() > sz.width() &&
03416                                         node->sceneBoundingRect().height() > sz.height())
03417                                 {
03418                                         mainNode = node;
03419                                         sz = node->sceneBoundingRect().size();
03420                                 }
03421                         if (mainNode)
03422                         {
03423                                 (*x) = mainNode->sceneBoundingRect().height();
03424                         }
03425                 }
03426                 if (s)
03427                         s->release();
03428         }
03429         
03430         void C_API_Slots::setAngle(QSemaphore* s, ItemHandle* item,double angle,int permanent)
03431         {
03432                 if (item)
03433                 {
03434                         QSizeF sz(0,0);
03435                         NodeGraphicsItem * node, * mainNode = 0;
03436                         for (int i=0; i < item->graphicsItems.size(); ++i)
03437                                 if ((node = NodeGraphicsItem::cast(item->graphicsItems[i])) &&
03438                                         node->sceneBoundingRect().width() > sz.width() &&
03439                                         node->sceneBoundingRect().height() > sz.height())
03440                                 {
03441                                         mainNode = node;
03442                                 }
03443                         if (mainNode)
03444                         {
03445                                 if (permanent && currentScene())
03446                                 {
03447                                         currentScene()->transform(tr("rotate ") + item->fullName(), mainNode, QPointF(0,0), angle);
03448                                 }
03449                                 else
03450                                 {
03451                                         mainNode->rotate(angle);
03452                                         temporarilyChangedAngle << QPair<NodeGraphicsItem*,double>(mainNode,angle);
03453                                 }
03454                         }
03455                 }
03456                 if (s)
03457                         s->release();
03458         }
03459         
03460         void C_API_Slots::annotations(QSemaphore * sem, QString * s)
03461         {
03462                 if (currentNetwork() && s)
03463                         (*s) = currentNetwork()->annotations();
03464                 
03465                 if (sem)
03466                         sem->release();
03467         }
03468         
03469         void C_API_Slots::insertAnnotation(QSemaphore * sem, const QString& s, double x, double y)
03470         {
03471                 if (!s.isNull() && !s.isEmpty())
03472                 {
03473                         GraphicsScene * scene = currentScene();
03474                         if (scene)
03475                         {
03476                                 QGraphicsItem * item = new TextGraphicsItem(s);
03477                                 item->setPos(scene->visibleRegion().center());
03478                                 scene->insert(tr("annotation inserted"),item);
03479                         }
03480                 }
03481                 
03482                 if (sem)
03483                         sem->release();
03484         }
03485         
03486         void C_API_Slots::setNumericalValues(QSemaphore* sem, const DataTable<qreal>& data)
03487         {
03488                 NetworkHandle * network = currentNetwork();
03489                 if (network)
03490                         network->setModelValues(data);
03491                 if (sem)
03492                         sem->release();
03493         }
03494         
03495         void C_API_Slots::setNumericalValue(QSemaphore* sem, const QString& s, double x)
03496         {
03497                 NetworkHandle * network = currentNetwork();
03498                 if (network)
03499                         network->setModelValues(QStringList() << s, QList<double>() << x);
03500                 if (sem)
03501                         sem->release();
03502         }
03503 
03504         void C_API_Slots::setTextValues(QSemaphore* sem, const TextDataTable& table)
03505         {
03506                 NetworkHandle * network = currentNetwork();
03507                 if (network)
03508                         network->setModelValues(table);
03509                 if (sem)
03510                         sem->release();
03511         }
03512 
03513         void C_API_Slots::setTextValue(QSemaphore* sem, const QString& s, const QString& x)
03514         {
03515                 NetworkHandle * network = currentNetwork();
03516                 if (network)
03517                         network->setModelValues(QStringList() << s, QStringList() << x);                        
03518                 if (sem)
03519                         sem->release();
03520         }
03521         
03522         void C_API_Slots::getNumericalValue(QSemaphore * sem, const QString& s, double * v)
03523         {
03524                 NetworkHandle * network = currentNetwork();
03525                 if (network && v)
03526                 {
03527                         QList< QPair<ItemHandle*,QString> > pairs = network->findData(s);
03528                         if (!pairs.isEmpty() && pairs[0].first && !pairs[0].second.isEmpty())
03529                         {
03530                                 ItemHandle * h = pairs[0].first;
03531                                 QString id = pairs[0].second;
03532                                 if (h->hasNumericalData(id))
03533                                 {
03534                                         QString s2 = s;
03535                                         if (s2.startsWith(h->fullName(tr("."))))
03536                                                 s2.remove(h->fullName(tr(".")) + tr("."));
03537                                         if (s2.startsWith(h->fullName(tr("_"))))
03538                                                 s2.remove(h->fullName(tr("_")) + tr("_"));
03539                                         (*v) = h->numericalData(id, s2);
03540                                 }
03541                         }
03542                 }
03543                 
03544                 if (sem)
03545                         sem->release();
03546         }
03547 
03548         void C_API_Slots::getNumericalValueUsingRegex(QSemaphore * sem, const QString& s, DataTable<qreal> * v)
03549         {
03550                 NetworkHandle * network = currentNetwork();
03551                 if (network && v)
03552                 {
03553                         QRegExp re(s);
03554                         QList< QPair<ItemHandle*,QString> > pairs = network->findData(re);
03555                         NumericalDataTable dat;
03556                         for (int i=0; i < pairs.size(); ++i)
03557                         {
03558                                 ItemHandle * h = pairs[i].first;
03559                                 QString id = pairs[i].second;
03560                                 if (h && h->hasNumericalData(id))
03561                                 {
03562                                         QString name = h->fullName(tr("_")) + tr("_");
03563                                         if (h->name.isNull() || h->name.isEmpty())
03564                                                 name = tr("");
03565                                         NumericalDataTable & dat2 = h->numericalDataTable(id);
03566                                         for (int j=0; j < dat2.rows(); ++j)
03567                                                 if ((name + dat2.rowName(j)).contains(re))
03568                                                         dat.value(name + dat2.rowName(j), 0) = dat2.value(j,0);
03569                                 }
03570                         }
03571                         (*v) = dat;
03572                 }
03573                 
03574                 if (sem)
03575                         sem->release();
03576         }
03577 
03578         void C_API_Slots::getTextValueUsingRegex(QSemaphore* sem,const QString& s, DataTable<QString>* v)
03579         {
03580                 NetworkHandle * network = currentNetwork();
03581                 if (network && v)
03582                 {
03583                         QRegExp re(s);
03584                         QList< QPair<ItemHandle*,QString> > pairs = network->findData(re);
03585                         TextDataTable dat;
03586                         for (int i=0; i < pairs.size(); ++i)
03587                         {
03588                                 ItemHandle * h = pairs[i].first;
03589                                 QString id = pairs[i].second;
03590                                 if (h && h->hasTextData(id))
03591                                 {
03592                                         QString name = h->fullName(tr("_")) + tr("_");
03593                                         if (h->name.isNull() || h->name.isEmpty())
03594                                                 name = tr("");
03595                                         TextDataTable & dat2 = h->textDataTable(id);
03596                                         for (int j=0; j < dat2.rows(); ++j)
03597                                                 if ((name + dat2.rowName(j)).contains(re))
03598                                                         dat.value(name + dat2.rowName(j), 0) = dat2.value(j,0);
03599                                 }
03600                         }
03601                         (*v) = dat;
03602                 }
03603                 
03604                 if (sem)
03605                         sem->release();
03606         }
03607 
03608         void C_API_Slots::getTextValue(QSemaphore * sem, const QString& s, QString * v)
03609         {
03610                 NetworkHandle * network = currentNetwork();
03611                 if (network && v)
03612                 {
03613                         QList< QPair<ItemHandle*,QString> > pairs = network->findData(s);
03614                         if (!pairs.isEmpty() && pairs[0].first && !pairs[0].second.isEmpty())
03615                         {
03616                                 ItemHandle * h = pairs[0].first;
03617                                 QString id = pairs[0].second;                           
03618                                 if (h->hasTextData(id))
03619                                 {
03620                                         QString s2 = s;
03621                                         if (s2.startsWith(h->fullName(tr("."))))
03622                                                 s2.remove(h->fullName(tr(".")) + tr("."));
03623                                         if (s2.startsWith(h->fullName(tr("_"))))
03624                                                 s2.remove(h->fullName(tr("_")) + tr("_"));
03625                                         (*v) = h->textData(id, s2);
03626                                 }
03627                         }
03628                 }
03629                 
03630                 if (sem)
03631                         sem->release();
03632         }
03633         
03634         void C_API_Slots::_openUrl(const char* file)
03635         {
03636                 QDesktopServices::openUrl(QUrl(QString(file)));
03637         }
03638         
03639         
03640         void C_API_Slots::setStraight(QSemaphore* sem,ItemHandle* h,int value)
03641         {
03642                 if (mainWindow->isValidHandlePointer(h) && !h->graphicsItems.isEmpty() && currentScene())
03643                 {
03644                         LineTypeChanged * command = new LineTypeChanged;
03645                         command->straight = value;
03646                         if (value)
03647                                 command->setText("make straight");
03648                         else
03649                                 command->setText("make curved");
03650 
03651                         for (int j=0; j < h->graphicsItems.size(); ++j)
03652                         {
03653                                 QGraphicsItem * item1 = h->graphicsItems[j];
03654                                 ConnectionGraphicsItem * connection = ConnectionGraphicsItem::cast(item1);
03655                                 if (connection)
03656                                         command->list += connection;
03657                         }
03658 
03659                         if (!command->list.isEmpty())
03660                         {
03661                                 if (currentScene()->network)
03662                                         currentScene()->network->push(command);
03663                                 else
03664                                 {
03665                                         command->redo();
03666                                         delete command;
03667                                 }
03668                         }
03669                 }
03670                 if (sem)
03671                         sem->release();
03672         }
03673 
03674         void C_API_Slots::setAllStraight(QSemaphore* sem,int value)
03675         {
03676                 if (currentScene())
03677                 {
03678                         QList<QGraphicsItem*> items = currentScene()->items();
03679                         LineTypeChanged * command = new LineTypeChanged;
03680                         command->straight = value;
03681                         if (value)
03682                                 command->setText("make straight");
03683                         else
03684                                 command->setText("make curved");
03685 
03686                         for (int j=0; j < items.size(); ++j)
03687                         {
03688                                 QGraphicsItem * item1 = items[j];
03689                                 ConnectionGraphicsItem * connection = ConnectionGraphicsItem::cast(item1);
03690                                 if (connection)
03691                                         command->list += connection;
03692                         }
03693 
03694                         if (!command->list.isEmpty())
03695                         {
03696                                 if (currentScene()->network)
03697                                         currentScene()->network->push(command);
03698                                 else
03699                                 {
03700                                         command->redo();
03701                                         delete command;
03702                                 }
03703                         }
03704                 }
03705                 if (sem)
03706                         sem->release();
03707         }
03708 
03709         void C_API_Slots::setLineWidth(QSemaphore* sem,ItemHandle* h,qreal value,int permanent)
03710         {
03711                 if (mainWindow->isValidHandlePointer(h) && !h->graphicsItems.isEmpty() && currentScene())
03712                 {
03713                         for (int j=0; j < h->graphicsItems.size(); ++j)
03714                         {
03715                                 QGraphicsItem * item1 = h->graphicsItems[j];
03716                                 ConnectionGraphicsItem * connection = ConnectionGraphicsItem::cast(item1);
03717                                 if (connection)
03718                                 {
03719                                         QPen pen;
03720                                         if (currentScene()->selected().contains(connection))
03721                                                 pen = connection->defaultPen;
03722                                         else
03723                                                 pen = connection->pen();
03724                                         pen.setWidthF(value);
03725 
03726                                         if (permanent > 0)
03727                                                 currentScene()->setPen(h->name + tr(" pen changed"),connection,pen);
03728                                         else
03729                                         {
03730                                                 connection->setPen(pen);
03731                                                 temporarilyColorChanged << connection;
03732                                         }
03733                                 }
03734                         }
03735                 }
03736                 if (sem)
03737                         sem->release();
03738         }
03739         
03740         void C_API_Slots::getControlPointX(QSemaphore* sem,qreal* ptr,ItemHandle* h1,ItemHandle* h2,int index)
03741         {
03742                 if (mainWindow->isValidHandlePointer(ptr) && 
03743                         mainWindow->isValidHandlePointer(h1) && 
03744                         mainWindow->isValidHandlePointer(h2) && 
03745                         !h1->graphicsItems.isEmpty() && !h2->graphicsItems.isEmpty())
03746                         for (int j=0; j < h1->graphicsItems.size(); ++j)
03747                         {
03748                                 QGraphicsItem * item1 = h1->graphicsItems[j];
03749                                 ConnectionGraphicsItem * connection = ConnectionGraphicsItem::cast(item1);
03750                                 for (int j2=0; j2 < h2->graphicsItems.size(); ++j2)
03751                                 {
03752                                         NodeGraphicsItem * node = NodeGraphicsItem::cast(h2->graphicsItems[j2]);
03753                                         if (ptr && node && connection)
03754                                         {
03755                                                 int i = connection->indexOf(node);
03756 
03757                                                 if (i > -1 && index > -1 && index < connection->curveSegments[i].size() && connection->curveSegments[i][index])
03758                                                 {
03759                                                         if (ptr)
03760                                                                 (*ptr) = connection->curveSegments[i][index]->x();
03761                                                         if (sem)
03762                                                                 sem->release();
03763                                                         return;
03764                                                 }
03765                                         }
03766                                 }
03767                         }
03768                         if (sem)
03769                                 sem->release();
03770         }
03771 
03772         void C_API_Slots::getControlPointY(QSemaphore* sem,qreal* ptr,ItemHandle* h1,ItemHandle* h2,int index)
03773         {
03774                 if (mainWindow->isValidHandlePointer(ptr) && 
03775                         mainWindow->isValidHandlePointer(h1) && 
03776                         mainWindow->isValidHandlePointer(h2)
03777                         && !h1->graphicsItems.isEmpty() && !h2->graphicsItems.isEmpty())
03778                         for (int j=0; j < h1->graphicsItems.size(); ++j)
03779                         {
03780                                 QGraphicsItem * item1 = h1->graphicsItems[j];
03781                                 ConnectionGraphicsItem * connection = ConnectionGraphicsItem::cast(item1);
03782                                 for (int j2=0; j2 < h2->graphicsItems.size(); ++j2)
03783                                 {
03784                                         NodeGraphicsItem * node = NodeGraphicsItem::cast(h2->graphicsItems[j2]);
03785                                         if (ptr && node && connection)
03786                                         {
03787                                                 int i = connection->indexOf(node);
03788                                                 if (i > -1 && index > -1 && index < connection->curveSegments[i].size() && connection->curveSegments[i][index])
03789                                                 {
03790                                                         (*ptr) = connection->curveSegments[i][index]->y();
03791                                                         if (sem)
03792                                                                 sem->release();
03793                                                         return;
03794                                                 }
03795                                         }
03796                                 }
03797                         }
03798                         if (sem)
03799                                 sem->release();
03800         }
03801 
03802         void C_API_Slots::setControlPoint(QSemaphore* sem,ItemHandle* h1,ItemHandle* h2,int index,qreal x,qreal y)
03803         {
03804                 if (mainWindow->isValidHandlePointer(h1) && 
03805                         mainWindow->isValidHandlePointer(h2) &&
03806                         !h1->graphicsItems.isEmpty() && !h2->graphicsItems.isEmpty())
03807                         for (int j=0; j < h1->graphicsItems.size(); ++j)
03808                         {
03809                                 QGraphicsItem * item1 = h1->graphicsItems[j];
03810                                 ConnectionGraphicsItem * connection = ConnectionGraphicsItem::cast(item1);
03811                                 for (int j2=0; j2 < h2->graphicsItems.size(); ++j2)
03812                                 {
03813                                         NodeGraphicsItem * node = NodeGraphicsItem::cast(h2->graphicsItems[j2]);
03814                                         if (node && connection)
03815                                         {
03816                                                 int i = connection->indexOf(node);
03817                                                 if (i > -1 && index > -1 && index < connection->curveSegments[i].size() && connection->curveSegments[i][index])
03818                                                 {
03819                                                         QPointF diff(x - connection->curveSegments[i][index]->x(),
03820                                                                 y - connection->curveSegments[i][index]->y());
03821 
03822                                                         GraphicsScene * scene = currentScene();
03823                                                         if (scene)
03824                                                                 scene->move(connection->curveSegments[i][index],diff);
03825                                                         else
03826                                                         {
03827                                                                 connection->curveSegments[i][index]->setPos(QPointF(x,y));
03828                                                         }
03829                                                         if (sem)
03830                                                                 sem->release();
03831                                                         return;
03832                                                 }
03833                                         }
03834                                 }
03835                         }
03836                         if (sem)
03837                                 sem->release();
03838         }
03839 
03840         void C_API_Slots::setCenterPoint(QSemaphore* sem,ItemHandle* h1,qreal x,qreal y)
03841         {
03842                 if (mainWindow->isValidHandlePointer(h1))
03843                         for (int i=0; i < h1->graphicsItems.size(); ++i)
03844                         {
03845                                 ConnectionGraphicsItem * connection = ConnectionGraphicsItem::cast(h1->graphicsItems[i]);
03846                                 if (connection)
03847                                 {
03848                                         ControlPoint * cp = connection->centerPoint();
03849                                         if (cp)
03850                                         {
03851                                                 GraphicsScene * scene = currentScene();
03852                                                 if (scene)
03853                                                         scene->move(cp,(QPointF(x,y) - cp->scenePos()));
03854                                                 else
03855                                                         cp->setPos(QPointF(x,y));
03856                                         }
03857                                 }
03858                         }
03859                         if (sem)
03860                                 sem->release();
03861         }
03862 
03863         void C_API_Slots::getCenterPointX(QSemaphore* sem,qreal* ptr, ItemHandle* h1)
03864         {
03865                 if (mainWindow->isValidHandlePointer(ptr) && mainWindow->isValidHandlePointer(h1))
03866                         for (int i=0; i < h1->graphicsItems.size(); ++i)
03867                         {
03868                                 ConnectionGraphicsItem * connection = ConnectionGraphicsItem::cast(h1->graphicsItems[i]);
03869                                 if (connection && ptr)
03870                                 {
03871                                         (*ptr) = connection->centerLocation().x();
03872                                 }
03873                         }
03874                         if (sem)
03875                                 sem->release();
03876         }
03877 
03878         void C_API_Slots::getCenterPointY(QSemaphore* sem,qreal* ptr, ItemHandle* h1)
03879         {
03880                 if (mainWindow->isValidHandlePointer(h1))
03881                         for (int i=0; i < h1->graphicsItems.size(); ++i)
03882                         {
03883                                 ConnectionGraphicsItem * connection = ConnectionGraphicsItem::cast(h1->graphicsItems[i]);
03884                                 if (connection && ptr)
03885                                 {
03886                                         (*ptr) = connection->centerLocation().y();
03887                                 }
03888                         }
03889                         if (sem)
03890                                 sem->release();
03891         }
03892         
03893         double C_API_Slots::_getControlPointX(long a,long b,int c)
03894         {
03895                 return fToS->getControlPointX(a,b,c);
03896         }
03897 
03898         double C_API_Slots::_getControlPointY(long a,long b,int c)
03899         {
03900                 return fToS->getControlPointY(a,b,c);
03901         }
03902 
03903         void C_API_Slots::_setControlPoint(long a,long b,int i, double x,double y)
03904         {
03905                 return fToS->setControlPoint(a,b,i,x,y);
03906         }
03907 
03908         double C_API_Slots::_getCenterPointX(long x)
03909         {
03910                 return fToS->getCenterPointX(x);
03911         }
03912 
03913         double C_API_Slots::_getCenterPointY(long x)
03914         {
03915                 return fToS->getCenterPointY(x);
03916         }
03917 
03918         void C_API_Slots::_setCenterPoint(long a,double x,double y)
03919         {
03920                 return fToS->setCenterPoint(a,x,y);
03921         }
03922 
03923         double Core_FtoS::getControlPointX(long a0,long a1,int a2)
03924         {
03925                 QSemaphore * s = new QSemaphore(1);
03926                 qreal p = 0.0;
03927                 s->acquire();
03928                 emit getControlPointX(s,&p,ConvertValue(a0),ConvertValue(a1),a2);
03929                 s->acquire();
03930                 s->release();
03931                 delete s;
03932                 return (double)p;
03933         }
03934 
03935         double Core_FtoS::getControlPointY(long a0,long a1,int a2)
03936         {
03937                 QSemaphore * s = new QSemaphore(1);
03938                 qreal p = 0.0;
03939                 s->acquire();
03940                 emit getControlPointY(s,&p,ConvertValue(a0),ConvertValue(a1),a2);
03941                 s->acquire();
03942                 s->release();
03943                 delete s;
03944                 return (double)p;
03945         }
03946 
03947 
03948         void Core_FtoS::setControlPoint(long a0,long a1,int i,double a2,double a3)
03949         {
03950                 QSemaphore * s = new QSemaphore(1);
03951                 s->acquire();
03952                 emit setControlPoint(s,ConvertValue(a0),ConvertValue(a1),i,a2,a3);
03953                 s->acquire();
03954                 s->release();
03955                 delete s;
03956         }
03957 
03958         void Core_FtoS::setCenterPoint(long a0,double a1,double a2)
03959         {
03960                 QSemaphore * s = new QSemaphore(1);
03961                 s->acquire();
03962                 emit setCenterPoint(s,ConvertValue(a0),a1,a2);
03963                 s->acquire();
03964                 s->release();
03965                 delete s;
03966         }
03967 
03968 
03969         double Core_FtoS::getCenterPointX(long a0)
03970         {
03971                 QSemaphore * s = new QSemaphore(1);
03972                 qreal x = 0.0;
03973                 s->acquire();
03974                 emit getCenterPointX(s,&x,ConvertValue(a0));
03975                 s->acquire();
03976                 s->release();
03977                 delete s;
03978                 return (double)x;
03979         }
03980 
03981         double Core_FtoS::getCenterPointY(long a0)
03982         {
03983                 QSemaphore * s = new QSemaphore(1);
03984                 qreal x = 0.0;
03985                 s->acquire();
03986                 emit getCenterPointY(s,&x,ConvertValue(a0));
03987                 s->acquire();
03988                 s->release();
03989                 delete s;
03990                 return (double)x;
03991         }
03992 
03993         void C_API_Slots::_setStraight(long o,int v)
03994         {
03995                 return fToS->setStraight(o,v);
03996         }
03997 
03998 
03999         void Core_FtoS::setStraight(long o,int v)
04000         {
04001                 QSemaphore * s = new QSemaphore(1);
04002                 s->acquire();
04003                 emit setStraight(s,ConvertValue(o),v);
04004                 s->acquire();
04005                 s->release();
04006                 return;
04007         }
04008 
04009         void C_API_Slots::_setAllStraight(int v)
04010         {
04011                 return fToS->setAllStraight(v);
04012         }
04013 
04014         void Core_FtoS::setAllStraight(int v)
04015         {
04016                 QSemaphore * s = new QSemaphore(1);
04017                 s->acquire();
04018                 emit setAllStraight(s,v);
04019                 s->acquire();
04020                 s->release();
04021                 return;
04022         }
04023 
04024         void C_API_Slots::_setLineWidth(long o,double v, int b)
04025         {
04026                 return fToS->setLineWidth(o,v,b);
04027         }
04028 
04029         void Core_FtoS::setLineWidth(long o,double v, int b)
04030         {
04031                 QSemaphore * s = new QSemaphore(1);
04032                 s->acquire();
04033                 emit setLineWidth(s,ConvertValue(o),qreal(v),b);
04034                 s->acquire();
04035                 s->release();
04036                 return;
04037         }
04038 
04039                 void C_API_Slots::getConnectedNodes(QSemaphore* sem,QList<ItemHandle*>* list,ItemHandle* item)
04040         {
04041                 if (mainWindow->isValidHandlePointer(item) && list)
04042                 {
04043                         if (item->type == ConnectionHandle::TYPE)
04044                         {
04045                                 QList<NodeHandle*> nodes = (static_cast<ConnectionHandle*>(item))->nodes();
04046                                 for (int i=0; i < nodes.size(); ++i)
04047                                         (*list) += nodes[i];
04048                         }
04049                         else
04050                         if (item->type == NodeHandle::TYPE)
04051                         {
04052                                 QList<ConnectionHandle*> connections = (static_cast<NodeHandle*>(item))->connections();
04053                                 QList<ItemHandle*> & lst = (*list);
04054                                 for (int j=0; j < connections.size(); ++j)
04055                                 {
04056                                         QList<NodeHandle*> nodes = connections[j]->nodes();
04057                                         for (int i=0; i < nodes.size(); ++i)
04058                                                 if (!lst.contains(nodes[i]) && nodes[i] != item)
04059                                                         lst += nodes[i];
04060                                 }
04061                         }
04062                 }
04063 
04064                 if (sem)
04065                         sem->release();
04066         }
04067         
04068         void C_API_Slots::getConnections(QSemaphore* sem,QList<ItemHandle*>* list,ItemHandle* item)
04069         {
04070                 if (mainWindow->isValidHandlePointer(item) && item->type == NodeHandle::TYPE && list)
04071                 {
04072                         QList<ConnectionHandle*> connections = (static_cast<NodeHandle*>(item))->connections();
04073                         for (int i=0; i < connections.size(); ++i)
04074                                 (*list) += connections[i];
04075                 }
04076 
04077                 if (sem)
04078                         sem->release();
04079         }
04080 
04081         void C_API_Slots::insertConnection(QSemaphore* sem,ItemHandle** retitem,const QList<ItemHandle*>& items,const QString& name, const QString& family)
04082         {
04083                 if (!mainWindow)
04084                 {
04085                         if (retitem)
04086                                 (*retitem) = 0;
04087                         if (sem)
04088                                 sem->release();
04089                         return;
04090                 }
04091                 
04092                 GraphicsScene * scene = mainWindow->currentScene();
04093 
04094                 if (!scene || !scene->network)
04095                 {
04096                         if (console())
04097                                 console()->error(tr("Cannot insert without a scene!"));
04098                         if (retitem)
04099                                 (*retitem) = 0;
04100                         if (sem)
04101                                 sem->release();
04102                         return;
04103                 }
04104 
04105                 ConnectionFamily * selectedFamily = 0;
04106                 if (!family.isEmpty())
04107                 {
04108                         selectedFamily = Ontology::connectionFamily(family);
04109                         if (!selectedFamily)
04110                         {
04111                                 selectedFamily = new ConnectionFamily(family.toLower());
04112                                 Ontology::insertConnectionFamily(family.toLower(), selectedFamily);
04113                         }
04114                 }
04115                 
04116                 QList<NodeHandle*> nodes;
04117                 NodeHandle * h1;
04118                 ConnectionHandle * h2;
04119                 for (int i=0; i < items.size(); ++i)
04120                         if (h1 = NodeHandle::cast(items[i]))
04121                                 nodes << h1;
04122                         else
04123                         if (h2 = ConnectionHandle::cast(items[i]))
04124                                 nodes << h2->nodes();
04125                 
04126                 QList<ItemFamily*> subFamilies = selectedFamily->findValidChildFamilies(nodes);
04127                 selectedFamily = 0;
04128                 if (!subFamilies.isEmpty())
04129                         selectedFamily = ConnectionFamily::cast(subFamilies.last());
04130                 
04131                 if (!selectedFamily)
04132                 {
04133                         if (retitem)
04134                                 (*retitem) = 0;
04135                         if (sem)
04136                                 sem->release();
04137                         return;
04138                 }
04139                 
04140                 QList<NodeGraphicsItem*> selectedNodes;
04141                 QList<ConnectionGraphicsItem*> selectedConnections;
04142                 
04143                 ItemHandle * handle;
04144 
04145                 ConnectionGraphicsItem * connection;
04146                 NodeGraphicsItem * node;
04147 
04148                 for (int i=0; i < items.size(); ++i)
04149                         if (items[i])
04150                         {
04151                                 for (int j=0; j < items[i]->graphicsItems.size(); ++j)
04152                                         if (items[i]->graphicsItems[j])
04153                                         {
04154                                                 if ((connection = ConnectionGraphicsItem::cast(items[i]->graphicsItems[j])) &&
04155                                                         !selectedConnections.contains(connection))
04156                                                 {
04157                                                         selectedConnections += connection;
04158                                                         break;
04159                                                 }
04160                                                 if ((node = NodeGraphicsItem::cast(items[i]->graphicsItems[j])))
04161                                                 {
04162                                                         selectedNodes += node;
04163                                                         break;
04164                                                 }
04165                                         }
04166                         }
04167                 
04168                 int numRequiredIn = 0, numRequiredOut = 0;
04169                 QStringList typeOut, typeIn;
04170                 
04171                 if (selectedFamily != 0)
04172                 {
04173                         QList<NodeHandle*> nodes, visited;
04174                         QStringList nodeRoles = selectedFamily->participantRoles(),
04175                                                 nodeFamilies = selectedFamily->participantTypes();
04176 
04177                         for (int i=0; i < nodeFamilies.size() && i < nodeRoles.size(); ++i)
04178                         {
04179                                 QString s = nodeRoles[i];
04180                                 if (!(s.toLower().contains(tr("target")) || 
04181                                           s.toLower().contains(tr("product")) || 
04182                                       s.toLower().contains(tr("output")) || s.toLower().contains(tr("sink"))))
04183                                 {
04184                                         ++numRequiredIn;
04185                                         typeIn += nodeFamilies[i];
04186                                 }
04187                                 else
04188                                 {
04189                                         ++numRequiredOut;
04190                                         typeOut += nodeFamilies[i];
04191                                 }
04192                         }
04193 
04194                         for (int i=0; i < selectedConnections.size(); ++i)
04195                         {
04196                                 ConnectionHandle * h = ConnectionHandle::cast(selectedConnections[i]->handle());
04197                                 for (int j=0; j < h->graphicsItems.size(); ++j)
04198                                 {
04199                                         ConnectionGraphicsItem * c;
04200                                         if (c = ConnectionGraphicsItem::cast(h->graphicsItems[j]))
04201                                         {
04202                                                 nodes += NodeHandle::cast( getHandle(c->nodesAsGraphicsItems()) );
04203                                         }
04204                                 }
04205                                 for (int j=0; j < nodes.size(); ++j)
04206                                 {
04207                                         bool b = false;
04208                                         for (int k=0; k < typeIn.size(); ++k)
04209                                                 if (nodes[j]->family()->isA(typeIn[k]) || nodes[j]->family()->isParentOf(typeIn[k]))
04210                                                 {
04211                                                         b = true;
04212                                                         break;
04213                                                 }
04214                                         if (b && numRequiredIn > 0)
04215                                                 --numRequiredIn;
04216                                         else
04217                                         {
04218                                                 b = false;
04219                                                 for (int k=0; k < typeIn.size(); ++k)
04220                                                         if (nodes[j]->family()->isA(typeIn[k]) || nodes[j]->family()->isParentOf(typeIn[k]))
04221                                                         {
04222                                                                 b = true;
04223                                                                 break;
04224                                                         }
04225                                                 if (b && numRequiredOut > 0)
04226                                                         --numRequiredOut;
04227                                         }
04228                                 }
04229                         }
04230                 }
04231                 else
04232                 {
04233                         numRequiredIn = (int)(selectedNodes.size() / 2);
04234                 }
04235 
04236                 QList<QGraphicsItem*> insertList;
04237                 QList<NodeGraphicsItem*> nodesIn, nodesOut;
04238 
04239                 for (int i=0; i < selectedNodes.size(); ++i)
04240                 {
04241                         if (i >= numRequiredIn)
04242                                 nodesOut << selectedNodes[i];
04243                         else
04244                                 nodesIn << selectedNodes[i];
04245                 }
04246 
04247                 ConnectionGraphicsItem * item = new ConnectionGraphicsItem(nodesIn, nodesOut);
04248                 insertList += item;
04249                 
04250                 //center decorator
04251                 /*if (selectedFamily->graphicsItems.size() > 1 && selectedFamily->graphicsItems.last())
04252                 {
04253                         NodeGraphicsItem * node = NodeGraphicsItem::cast(selectedFamily->graphicsItems.last());
04254                         if (node && ArrowHeadItem::cast(node))
04255                         {
04256                                 item->centerRegionItem = new ArrowHeadItem(*ArrowHeadItem::cast(node));
04257                                 if (node->defaultSize.width() > 0 && node->defaultSize.height() > 0)
04258                                         item->centerRegionItem->scale(node->defaultSize.width()/node->sceneBoundingRect().width(),node->defaultSize.height()/node->sceneBoundingRect().height());
04259                                 insertList += item->centerRegionItem;
04260                         }
04261                 }*/
04262 
04263                 //making new connections
04264                 handle = new ConnectionHandle(selectedFamily,item);
04265                 if (retitem)
04266                         (*retitem) = handle;
04267 
04268                 handle->name = name;
04269                 if (!handle->name[0].isLetter())
04270                         handle->name = tr("p") + handle->name;
04271                 handle->name = scene->network->makeUnique(name);
04272 
04273                 TextGraphicsItem * nameItem = new TextGraphicsItem(handle,0);
04274                 if (item)
04275                         nameItem->relativePosition = QPair<QGraphicsItem*,QPointF>(item,QPointF(0,0));
04276 
04277                 insertList += nameItem;
04278                 nameItem->setPos(item->centerLocation());
04279                 QFont font = nameItem->font();
04280                 font.setPointSize(22);
04281                 nameItem->setFont(font);
04282 
04283                 scene->insert(handle->name + tr(" inserted"), insertList);
04284                 
04285                 selectedFamily = 0;
04286 
04287                 if (sem)
04288                         sem->release();
04289         }
04290 
04291         long C_API_Slots::_insertConnection(tc_items A, const char* a0, const char* a1)
04292         {
04293                 return fToS->insertConnection(A, a0, a1);
04294         }
04295 
04296         long Core_FtoS::insertConnection(tc_items A, const char* a0, const char* a1)
04297         {
04298                 QSemaphore * s = new QSemaphore(1);
04299                 ItemHandle * item = 0;
04300                 s->acquire();
04301                 QList<ItemHandle*> * list = ConvertValue(A);
04302                 emit insertConnection(s,&item,*list,ConvertValue(a0),ConvertValue(a1));
04303                 s->acquire();
04304                 s->release();
04305                 delete s;
04306                 delete list;
04307                 return ConvertValue(item);
04308         }
04309 
04310         tc_items C_API_Slots::_getConnectedNodes(long x)
04311         {
04312                 return fToS->getConnectedNodes(x);
04313         }
04314 
04315         tc_items Core_FtoS::getConnectedNodes(long x)
04316         {
04317                 QSemaphore * s = new QSemaphore(1);
04318                 QList<ItemHandle*>* list = new QList<ItemHandle*>;
04319                 s->acquire();
04320                 emit getConnectedNodes(s,list,ConvertValue(x));
04321                 s->acquire();
04322                 s->release();
04323                 delete s;
04324                 tc_items A = ConvertValue(*list);
04325                 delete list;
04326                 return A;
04327         }
04328 
04329         tc_items C_API_Slots::_getConnections(long x)
04330         {
04331                 return fToS->getConnections(x);
04332         }
04333 
04334         tc_items Core_FtoS::getConnections(long x)
04335         {
04336                 QSemaphore * s = new QSemaphore(1);
04337                 QList<ItemHandle*>* list = new QList<ItemHandle*>;
04338                 s->acquire();
04339                 emit getConnections(s,list,ConvertValue(x));
04340                 s->acquire();
04341                 s->release();
04342                 delete s;
04343                 tc_items A = ConvertValue(*list);
04344                 delete list;
04345                 return A;
04346         }
04347 
04348 }
04349 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines