#include #include #include #include #include "GWt_abstractElement.h" #include "GWt_elementLigneFaisceau.h" #include "GWt_rfgun.h" #include "GWt_drift.h" #include "GWt_cell.h" #include "GWt_bend.h" #include "GWt_soleno.h" #include "GWt_beam.h" #include "GWt_fit.h" #include "GWt_snapshot.h" #include "GWt_draggableImage.h" #include "GWt_ligneFaisceau.h" #include "mixedTools.h" #include "nomdElements.h" #include #include #include #include #include GWt_abstractElement::GWt_abstractElement(abstractElement* elem) : WContainerWidget() { abstractElement_ = elem; } void GWt_abstractElement::initialize() { // make image image_ = new WImage(getBigImageURL(),this); 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().getElementName()); } } // int compteur = -1; // int nbparam = atoi(param[++compteur].c_str()); 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().getElementName()); } } dialog_ = new WDialog("element " + abstractElement_->getNomdElement().getElementName()); new WText(" label of the element : ",dialog_->contents()); // labelEdit_ = new WLineEdit(param[++compteur].c_str(), 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); } WContainerWidget* GWt_abstractElement::getWidget() { return wc_; } abstractElement* GWt_abstractElement::getAbstractElement() { return abstractElement_; } void GWt_abstractElement::createDragImage(WContainerWidget* w){ 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); result->setToolTip(getName()); } WImage* GWt_abstractElement::getImage() { return image_; } 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(); } } 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; } }