#include #include #include #include #include "GWt_abstractElement.h" #include "GWt_elementLigneFaisceau.h" #include "GWt_draggableImage.h" #include "GWt_ligneFaisceau.h" #include "mixedTools.h" #include "nomdElements.h" #include "nomDeLogiciel.h" #include #include #include #include #include GWt_abstractElement::GWt_abstractElement(abstractElement* elem) : WContainerWidget() { abstractElement_ = elem; } void GWt_abstractElement::initialize() { image_ = new WImage(getBigImageURL(),this); // make image addWidget(image_); updateLabelAndToolTipWidget(); } string* GWt_abstractElement::beginDialog() { string* param = abstractElement_->getParametersString(); if ( param == NULL ) { if ( static_cast (wApp->findWidget ("console"))) { GWt_console* console = static_cast (wApp->findWidget ("console")); console->addConsoleMessage(" GWt_abstractElement::beginDialog : empty parameter set for element " + abstractElement_->getNomdElement().getExpandedName()); } } int nbparam = atoi(param->c_str()); if ( nbparam != abstractElement_->getNbParams()) { if ( static_cast (wApp->findWidget ("console"))) { GWt_console* console = static_cast (wApp->findWidget ("console")); console->addConsoleMessage(" element seems not to be a " + abstractElement_->getNomdElement().getExpandedName()); } } dialog_ = new WDialog("element "+abstractElement_->getNomdElement().getExpandedName()); new WText(" label of the element : ",dialog_->contents()); labelEdit_ = new WLineEdit( (++param)->c_str(),dialog_->contents()); new WBreak(dialog_->contents()); return ++param; } void GWt_abstractElement::updateLabelAndToolTipWidget() { if (abstractElement_ != NULL) { elementLigneFaiseauContainer_->setElementLabel(abstractElement_->getLabel()); setToolTip(print()); } } void GWt_abstractElement::showParameters() { initilializeDialog(); dialog_->show(); } void GWt_abstractElement::deleteElement() { StandardButton result = WMessageBox::show("PSPA : Delete element", WString("Delete '")+WString(getAbstractElement()->getLabel())+"' ?", Ok | Cancel); if (result == Cancel) { return; } // get LigneFaiseau widget and add new elementLigneFaiseau GWt_ligneFaisceau* ligneFaisceau = NULL; if ( static_cast (wApp->findWidget ("ligneFaisceau"))) { ligneFaisceau = static_cast (wApp->findWidget ("ligneFaisceau")); } else { return; } ligneFaisceau->removeElement(this); } void GWt_abstractElement::createDragImage(WContainerWidget* w) { unsigned k; GWt_draggableImage *result= new GWt_draggableImage(getBigImageURL(),w); /* * Set the image to be draggable, showing the other image (dragImage) * to be used as the widget that is visually dragged. */ result->setDraggable(getMimeType(),new WImage(getSmallImageURL(),w),true); vector acceptes; vector ignores; for ( k=0; k < nomDeLogiciel::getNumberOfSoftwares() ; k++) { trivaluedBool tb = nomDeLogiciel(k).doAcceptElement(nomdElements::getTypeFromLabel(getName()) ); if (tb == TBoolOk ) { acceptes.push_back(nomDeLogiciel(k).getString()); } else if (tb == TBoolIgnore ) { ignores.push_back(nomDeLogiciel(k).getString()); } } string textToolTip = getName(); if ( acceptes.size() ) textToolTip += string("\n") + "accepted by softwares : "; for (k=0; k < acceptes.size(); k++) textToolTip += string("\n") + acceptes.at(k); if ( ignores.size() ) textToolTip += string("\n") + "ignored by softwares : "; for (k=0; k < ignores.size(); k++) textToolTip += string("\n") + ignores.at(k); // result->setToolTip(getName()); result->setToolTip(textToolTip); } // void GWt_abstractElement::FileInput(ifstream& ifs) // { // getAbstractElement()->FileInput(ifs); // initilializeDialog(); // updateLabelAndToolTipWidget(); // // update parameters // GWt_ligneFaisceau* ligneFaisceau = NULL; // if ( static_cast (wApp->findWidget ("ligneFaisceau"))) { // ligneFaisceau = static_cast (wApp->findWidget ("ligneFaisceau")); // ligneFaisceau->update(); // } // } abstractElement* GWt_abstractElement::getAbstractElement() { return abstractElement_; } WContainerWidget* GWt_abstractElement::getWidget() { return wc_; } WImage* GWt_abstractElement::getImage() { return image_; } variant GWt_abstractElement::getParamValue(string elem) { if(parameterMapValue.find(elem) == parameterMapValue.end()) { return new NullType(); } std::map >::iterator it; it = parameterMapValue.find(elem); variant value = it->second; try { int pi = boost::get(value); printf("%s Type is int\n",elem.c_str()); return pi; } catch (boost::bad_get v) { try { string si = boost::get(value); printf("%s Type is string\n",elem.c_str()); return si; } catch (boost::bad_get v) { try { bool bi = boost::get(value); printf("%s Type is bool\n",elem.c_str()); return bi; } catch (boost::bad_get v) { printf("%s Type is NULL\n",elem.c_str()); return new NullType(); } } } printf("%s Type is NULL NULL\n",elem.c_str()); return new NullType(); } string GWt_abstractElement::getParamDescription(string elem) { if(parameterMapDescription.find(elem) == parameterMapDescription.end() ) { printf("%s Descr is NULL NULL\n",elem.c_str()); return ""; } else { printf("%s Descr is %s\n",elem.c_str(),parameterMapDescription.find(elem)->second.c_str()); return parameterMapDescription.find(elem)->second; } }