void Serializer::applyStateToComponent(const Component::Ptr &theComponent, const std::string &theState, const PropertyIO &theIO) { Json::Reader myReader; Json::Value myRoot; bool myParsingSuccessful = myReader.parse(theState, myRoot); if (!myParsingSuccessful) { throw ParsingException(theState); } for (unsigned int i=0; i<myRoot.size(); i++) { Json::Value myComponentNode = myRoot[i]; if(myComponentNode[PropertyIO::PROPERTY_NAME] != theComponent->getName()){continue;} for (unsigned int i=0; i < myComponentNode[PropertyIO::PROPERTIES].size(); i++) { try { std::string myName = myComponentNode[PropertyIO::PROPERTIES][i][PropertyIO::PROPERTY_NAME].asString(); Property::Ptr myProperty = theComponent->getPropertyByName(myName); theIO.writePropertyValue(myProperty, myComponentNode[PropertyIO::PROPERTIES][i]); } catch (PropertyNotFoundException &myException) { LOG_WARNING << myException.what(); } } } }
Component::Ptr Component::remove_component ( const std::string& name ) { // find the component exists Component::CompStorage_t::iterator itr = m_dynamic_components.find(name); if ( itr != m_dynamic_components.end() ) // if exists { Component::Ptr comp = itr->second; // get the component // remove the component from the root if( !m_root.expired() ) m_root.lock()->remove_component_path(comp->uri()); m_dynamic_components.erase(itr); // remove it from the storage // remove from the list of all components Component::CompStorage_t::iterator citr = m_components.find(name); m_components.erase(citr); comp->change_parent( NULL ); // set parent to invalid raise_path_changed(); return comp; // return it to client } else // if does not exist { throw ValueNotFound(FromHere(), "Dynamic component with name '" + name + "' does not exist in component '" + this->name() + "' with path [" + m_path.path() + "]"); } }
void GLFW_App::create_tweakbar_from_component(const Component::Ptr &the_component) { if(!the_component) return; m_tweakBars.push_back(TwNewBar(the_component->getName().c_str())); setBarColor(glm::vec4(0, 0, 0, .5), m_tweakBars.back()); setBarSize(glm::ivec2(250, 500)); glm::ivec2 offset(10); setBarPosition(glm::ivec2(offset.x + 260 * (m_tweakBars.size() - 1), offset.y), m_tweakBars.back()); addPropertyListToTweakBar(the_component->getPropertyList(), "", m_tweakBars.back()); }
Size StackLayout::layout(Component::Ptr component, const std::list<Component::Ptr>& children, const Size& innerSize) { Size preferred = Size::ZERO; for (std::list<Component::Ptr>::const_iterator child = children.begin(); child != children.end(); ++child) { Component::Ptr childComp = *child; childComp->setSize(innerSize); childComp->setPosition(Point(0, 0)); preferred = Size::max(preferred, childComp->getPreferredSize()); } return preferred.grow(component->getInsets()); }
void Container::pack(Component::Ptr component) { mChildren.push_back(component); if (!hasSelection() && component->isSelectable()) select(mChildren.size() - 1); }
void drimi::Gui::Container::Pack ( Component::Ptr pComponent ) { m_oChildren.push_back (pComponent); // If container has no selection and the component // is selectable then select it. if (!HasSelection () && pComponent->IsSelectable ()) Select (m_oChildren.size ()-1); }
void Container::Pack( Component::Ptr component ) { pImpl->mChildren.push_back( component ); if( !pImpl->HasSelection() && component->IsSelectable() ) { pImpl->Select( pImpl->mChildren.size() - 1 ); } }
void TpMzScheme::evalDesign(Design::Ptr d){ DesignStore::Ptr ds = Game::getGame()->getDesignStore(); if (scheme_setjmp(scheme_error_buf)) { Logger::getLogger()->warning("MzScheme Error"); } else { Scheme_Object* temp; std::ostringstream formater; formater.str(""); formater << "(define-values (struct:designType make-designType designType? designType-ref designType-set!)(make-design-type " << ds->getMaxPropertyId() << "))"; temp = scheme_eval_string(formater.str().c_str(), env); temp = scheme_eval_string("(define property-designType-set! (lambda (design id val) (designType-set! design (- id 1) val)))", env); std::set<uint32_t> propids = ds->getPropertyIds(); for(std::set<uint32_t>::iterator propit = propids.begin(); propit != propids.end(); ++propit){ // for each property type Property::Ptr p = ds->getProperty(*propit); if(p){ formater.str(""); formater << "(define designType." << p->getName() << " (make-property-accessor designType-ref " << p->getPropertyId() << " \"" << p->getName() << "\" ))"; temp = scheme_eval_string(formater.str().c_str(), env); } } propids.clear(); IdMap complist = d->getComponents(); temp = scheme_eval_string("(define design (make-designType))", env); for(std::set<uint32_t>::iterator propit = propids.begin(); propit != propids.end(); ++propit){ formater.str(""); formater << "(property-designType-set! design " << *propit << " 0.0)"; temp = scheme_eval_string(formater.str().c_str(), env); } std::map<uint32_t, std::map<uint32_t, std::list<std::string> > > propranking; for(IdMap::iterator compit = complist.begin(); compit != complist.end(); ++compit){ Component::Ptr c = ds->getComponent(compit->first); std::map<uint32_t, std::string> pilist = c->getPropertyList(); for(std::map<uint32_t, std::string>::iterator piit = pilist.begin(); piit != pilist.end(); ++piit){ Property::Ptr p = ds->getProperty(piit->first); for(uint32_t i = 0; i < compit->second; i++){ propranking[p->getRank()][p->getPropertyId()].push_back(piit->second); } } } std::map<uint32_t, PropertyValue> propertyvalues; for(std::map<uint32_t, std::map<uint32_t, std::list<std::string> > >::iterator rpiit = propranking.begin(); rpiit != propranking.end(); ++rpiit){ std::map<uint32_t, std::list<std::string> > pilist = rpiit->second; std::set<PropertyValue> localvalues; for(std::map<uint32_t, std::list<std::string> >::iterator piit = pilist.begin(); piit != pilist.end(); ++piit){ PropertyValue propval(piit->first,0.0); std::list<double> listvals; std::list<std::string> lambdas = piit->second; for(std::list<std::string>::iterator itlamb = lambdas.begin(); itlamb != lambdas.end(); ++itlamb){ temp = scheme_eval_string((std::string("(") + (*itlamb) + " design)").c_str(), env); if(!SCHEME_NUMBERP(temp)){ Logger::getLogger()->warning("MzScheme: Return not a number"); }else{ listvals.push_back(scheme_real_to_double(temp)); } } Property::Ptr p = ds->getProperty(piit->first); formater.str(""); formater << "(" << p->getTpclDisplayFunction() << " design '("; for(std::list<double>::iterator itvals = listvals.begin(); itvals != listvals.end(); ++itvals){ formater << *itvals << " "; } formater << "))"; temp = scheme_eval_string(formater.str().c_str(), env); #ifdef HAVE_MZSCHEME20X if(!SCHEME_PAIRP(temp) || !SCHEME_NUMBERP(SCHEME_CAR(temp)) || !SCHEME_STRINGP(SCHEME_CDR(temp))){ #else if(!SCHEME_PAIRP(temp) || !SCHEME_NUMBERP(SCHEME_CAR(temp)) || !SCHEME_CHAR_STRINGP(SCHEME_CDR(temp))){ #endif Logger::getLogger()->warning("MzScheme: Return not a pair, or the wrong time in the pair"); }else{ propval.setValue(scheme_real_to_double(SCHEME_CAR(temp))); #ifdef HAVE_MZSCHEME20X propval.setDisplayString(std::string(SCHEME_STR_VAL(SCHEME_CDR(temp)))); #else propval.setDisplayString(std::string((char*)SCHEME_CHAR_STR_VAL(SCHEME_CDR(temp)))); #endif localvalues.insert(propval); } } for(std::set<PropertyValue>::iterator pvit = localvalues.begin(); pvit != localvalues.end(); ++pvit){ PropertyValue pv = *pvit; formater.str(""); formater << "(property-designType-set! design " << pv.getPropertyId() << " " << pv.getValue() << ")"; temp = scheme_eval_string(formater.str().c_str(), env); propertyvalues[pv.getPropertyId()] = pv; } } d->setPropertyValues(propertyvalues); // now check if the design is valid bool valid = true; std::string feedback = ""; Logger::getLogger()->debug("About to process requirement functions"); for(IdMap::iterator compit = complist.begin(); compit != complist.end(); ++compit){ uint32_t curval = compit->first; //for each component in the design temp = scheme_eval_string((std::string("(") + ds->getComponent(curval)->getTpclRequirementsFunction() + " design)").c_str(), env); #ifdef HAVE_MZSCHEME20X if(!SCHEME_PAIRP(temp) || !SCHEME_STRINGP(SCHEME_CDR(temp))){ #else if(!SCHEME_PAIRP(temp) || !SCHEME_CHAR_STRINGP(SCHEME_CDR(temp))){ #endif Logger::getLogger()->warning("MzScheme: (a) Return not a pair, or the wrong time in the pair"); }else{ valid &= SCHEME_TRUEP(SCHEME_CAR(temp)); #ifdef HAVE_MZSCHEME20X std::string strtemp = SCHEME_STR_VAL(SCHEME_CDR(temp)); #else std::string strtemp = (char*)SCHEME_CHAR_STR_VAL(SCHEME_CDR(temp)); #endif if(strtemp.length() > 0) feedback += strtemp + " "; } } for(std::map<uint32_t, std::map<uint32_t, std::list<std::string> > >::iterator rpiit = propranking.begin(); rpiit != propranking.end(); ++rpiit){ std::map<uint32_t, std::list<std::string> > pilist = rpiit->second; for(std::map<uint32_t, std::list<std::string> >::iterator piit = pilist.begin(); piit != pilist.end(); ++piit){ temp = scheme_eval_string((std::string("(") + ds->getProperty(piit->first)->getTpclRequirementsFunction() + " design)").c_str(), env); #ifdef HAVE_MZSCHEME20X if(!SCHEME_PAIRP(temp) || !SCHEME_STRINGP(SCHEME_CDR(temp))){ #else if(!SCHEME_PAIRP(temp) || !SCHEME_CHAR_STRINGP(SCHEME_CDR(temp))){ #endif Logger::getLogger()->warning("MzScheme: (a) Return not a pair, or the wrong time in the pair"); }else{ valid &= SCHEME_TRUEP(SCHEME_CAR(temp)); #ifdef HAVE_MZSCHEME20X std::string strtemp = SCHEME_STR_VAL(SCHEME_CDR(temp)); #else std::string strtemp = (char*)SCHEME_CHAR_STR_VAL(SCHEME_CDR(temp)); #endif if(strtemp.length() > 0) feedback += strtemp + " "; } } } propranking.clear(); d->setValid(valid, feedback); Logger::getLogger()->debug("Eval'ed design"); if(!valid){ Logger::getLogger()->debug("Design %s is not valid, reason: %s", d->getName().c_str(), feedback.c_str()); } } } TpMzScheme::TpMzScheme(){ //scheme_set_stack_base(NULL, 1); /* required for OS X, only. WILL NOT WORK HERE */ bool loaded = false; env = scheme_basic_env(); if (scheme_setjmp(scheme_error_buf)) { Logger::getLogger()->warning("MzScheme warning: could not load local file, trying installed file"); } else { scheme_eval_string("(load \"../modules/tpcl/mzscheme/designstruct.scm\")",env); loaded = true; } if(loaded == false){ if (scheme_setjmp(scheme_error_buf)) { Logger::getLogger()->warning("MzScheme warning: could not load installed file"); } else { scheme_eval_string("(load \"" DATADIR "/tpserver/tpscheme/mzscheme/designstruct.scm\")", env); loaded = true; } } if(loaded == false){ Logger::getLogger()->error("MzScheme Error: failed to load designstruct.scm file"); //throw exception? } }
Size GridLayout::layout(Component::Ptr component, const std::list<Component::Ptr>& children, const Size& innerSize) { unsigned int actualRows = rows; unsigned int actualColumns = columns; if (actualRows < 1 && actualColumns < 1) { actualRows = actualColumns = (unsigned int) ceil(sqrt(children.size())); } else if (actualRows < 1) { actualRows = (unsigned int) ceil((float) children.size() / (float) actualColumns); } else if (actualColumns < 1) { actualColumns = (unsigned int) ceil((float) children.size() / (float) actualRows); } Size childSize = innerSize.resize(-(actualColumns - 1) * hPadding, -(actualRows - 1) * vPadding).scale(1.0 / actualColumns, 1.0 / actualRows); unsigned int row = 0; unsigned int column = 0; for (std::list<Component::Ptr>::const_iterator child = children.begin(); child != children.end(); ++child) { Component::Ptr childComp = *child; childComp->setSize(Size::min(childSize, childComp->getMaximumSize())); Point position(column * (childSize.width + hPadding), row * (childSize.height + vPadding)); switch (defaultHAlignment) { default: case Component::ALIGN_LEFT: position = position.move(0, 0); break; case Component::ALIGN_CENTER: position = position.move((childSize.width - childComp->getWidth()) / 2, 0); break; case Component::ALIGN_RIGHT: position = position.move(childSize.width - childComp->getWidth(), 0); break; } switch (defaultVAlignment) { default: case Component::ALIGN_TOP: position = position.move(0, 0); break; case Component::ALIGN_CENTER: position = position.move(0, (childSize.height - childComp->getHeight()) / 2); break; case Component::ALIGN_BOTTOM: position = position.move(0, childSize.height - childComp->getHeight()); break; } childComp->setPosition(position); if (order == LEFT_TO_RIGHT) { column += 1; if (column >= actualColumns) { column = 0; row += 1; } } else { row += 1; if (row >= actualRows) { row = 0; column += 1; } } } Size preferredChildSize = Size::ZERO; for (std::list<Component::Ptr>::const_iterator child = children.begin(); child != children.end(); ++child) { preferredChildSize = Size::max(preferredChildSize, (*child)->getPreferredSize()); } return preferredChildSize.scale(actualColumns, actualRows).resize((actualColumns - 1) * hPadding, (actualRows - 1) * vPadding).grow( component->getInsets()); }
void DesignStore::addComponent(Component::Ptr c){ c->setComponentId(next_componentid++); components[c->getId()] = c; componentIndex[c->getName()] = c->getId(); Game::getGame()->getPersistence()->saveComponent(c); }
Size BorderLayout::layout(Component::Ptr component, const std::list<Component::Ptr>& children, const Size& innerSize) { Component::Ptr top; Component::Ptr bottom; Component::Ptr left; Component::Ptr right; Component::Ptr center; for (std::list<Component::Ptr>::const_iterator child = children.begin(); child != children.end(); ++child) { Component::Alignment alignment = (*child)->getAlignment(); switch (alignment) { case Component::ALIGN_LEFT: if (left) { throw Exception("BorderLayout supports only one component with ALIGN_LEFT"); } left = (*child); break; case Component::ALIGN_TOP: if (top) { throw Exception("BorderLayout supports only one component with ALIGN_TOP"); } top = (*child); break; case Component::ALIGN_RIGHT: if (right) { throw Exception("BorderLayout supports only one component with ALIGN_RIGHT"); } right = (*child); break; case Component::ALIGN_BOTTOM: if (bottom) { throw Exception("BorderLayout supports only one component with ALIGN_BOTTOM"); } bottom = (*child); break; default: case Component::ALIGN_DEFAULT: case Component::ALIGN_CENTER: if (center) { throw Exception("BorderLayout supports only one component with ALIGN_CENTER/ALIGN_DEFAULT"); } center = (*child); break; } } Insets centerInsets; if (top) { top->setWidth(innerSize.width); top->setHeight(top->getPreferredSize().height); top->setPosition(Point(0, 0)); centerInsets.top += top->getHeight(); } if (bottom) { bottom->setWidth(innerSize.width); bottom->setHeight(bottom->getPreferredSize().height); bottom->setPosition(Point(0, innerSize.height - bottom->getHeight())); centerInsets.bottom += bottom->getHeight(); } if (left) { left->setHeight(innerSize.shrink(centerInsets).height); left->setWidth(left->getPreferredSize().width); left->setPosition(Point(0, centerInsets.top)); centerInsets.left += left->getWidth(); } if (right) { right->setHeight(innerSize.shrink(centerInsets).height); right->setWidth(right->getPreferredSize().width); right->setPosition(Point(innerSize.width - right->getWidth(), centerInsets.top)); centerInsets.right += right->getWidth(); } if (center) { center->setSize(innerSize.shrink(centerInsets)); center->setPosition(centerInsets.getTopLeft()); } Size preferred; if (left) { const Size& size = left->getPreferredSize(); preferred.width += size.width; preferred.height = std::max(preferred.height, size.height); } if (center) { const Size& size = center->getPreferredSize(); preferred.width += size.width; preferred.height = std::max(preferred.height, size.height); } if (right) { const Size& size = right->getPreferredSize(); preferred.width += size.width; preferred.height = std::max(preferred.height, size.height); } if (top) { const Size& size = top->getPreferredSize(); preferred.width = std::max(preferred.width, size.width); preferred.height += size.height; } if (bottom) { const Size& size = bottom->getPreferredSize(); preferred.width = std::max(preferred.width, size.width); preferred.height += size.height; } return preferred.grow(component->getInsets()); }