void Sheet::updateAlias(CellAddress key) { std::string alias; Property * prop = props.getDynamicPropertyByName(key.toString().c_str()); if (!prop) return; Cell * cell = getCell(key); if (cell && cell->getAlias(alias)) { App::Property * aliasProp = props.getDynamicPropertyByName(alias.c_str()); /* Update or create alias? */ if (aliasProp) { // Type of alias and property must always be the same if (aliasProp->getTypeId() != prop->getTypeId()) { props.removeDynamicProperty(alias.c_str()); aliasProp = 0; } } if (!aliasProp) aliasProp = props.addDynamicProperty(prop->getTypeId().getName(), alias.c_str(), 0, 0, Prop_ReadOnly | Prop_Transient, true, true); aliasProp->Paste(*prop); } }
void customEvent(QEvent* e) { PropertyEvent* pe = static_cast<PropertyEvent*>(e); std::set<const Gui::ViewProvider*>::iterator it = viewMap.find(pe->view); // Make sure that the object hasn't been deleted in the meantime (#0001522) if (it != viewMap.end()) { viewMap.erase(it); App::Property* prop = pe->view->getPropertyByName("Proxy"); if (prop && prop->isDerivedFrom(App::PropertyPythonObject::getClassTypeId())) { prop->Paste(*pe->prop); } } delete pe->prop; }
App::DocumentObject* TaskFeaturePick::makeCopy(App::DocumentObject* obj, std::string sub, bool independent) { App::DocumentObject* copy = nullptr; // Check for null to avoid segfault if (!obj) return copy; if( independent && (obj->isDerivedFrom(Sketcher::SketchObject::getClassTypeId()) || obj->isDerivedFrom(PartDesign::FeaturePrimitive::getClassTypeId()))) { //we do know that the created instance is a document object, as obj is one. But we do not know which //exact type auto name = std::string("Copy") + std::string(obj->getNameInDocument()); copy = App::GetApplication().getActiveDocument()->addObject(obj->getTypeId().getName(), name.c_str()); //copy over all properties std::vector<App::Property*> props; std::vector<App::Property*> cprops; obj->getPropertyList(props); copy->getPropertyList(cprops); auto it = cprops.begin(); for( App::Property* prop : props ) { //independent copies don't have links and are not attached if(independent && ( prop->getTypeId().isDerivedFrom(App::PropertyLink::getClassTypeId()) || prop->getTypeId().isDerivedFrom(App::PropertyLinkList::getClassTypeId()) || prop->getTypeId().isDerivedFrom(App::PropertyLinkSub::getClassTypeId()) || prop->getTypeId().isDerivedFrom(App::PropertyLinkSubList::getClassTypeId())|| ( prop->getGroup() && strcmp(prop->getGroup(),"Attachment")==0) )) { ++it; continue; } App::Property* cprop = *it++; if( strcmp(prop->getName(), "Label") == 0 ) { static_cast<App::PropertyString*>(cprop)->setValue(name.c_str()); continue; } cprop->Paste(*prop); //we are a independent copy, therefore no external geometry was copied. WE therefore can delete all //constraints if(obj->isDerivedFrom(Sketcher::SketchObject::getClassTypeId())) static_cast<Sketcher::SketchObject*>(copy)->delConstraintsToExternal(); } } else { std::string name; if(!independent) name = std::string("Reference"); else name = std::string("Copy"); name += std::string(obj->getNameInDocument()); std::string entity; if(!sub.empty()) entity = sub; Part::PropertyPartShape* shapeProp = nullptr; // TODO Replace it with commands (2015-09-11, Fat-Zer) if(obj->isDerivedFrom(Part::Datum::getClassTypeId())) { copy = App::GetApplication().getActiveDocument()->addObject( obj->getClassTypeId().getName(), name.c_str() ); //we need to reference the individual datums and make again datums. This is important as //datum adjust their size dependent on the part size, hence simply copying the shape is //not enough long int mode = mmDeactivated; Part::Datum *datumCopy = static_cast<Part::Datum*>(copy); if(obj->getTypeId() == PartDesign::Point::getClassTypeId()) { mode = mm0Vertex; } else if(obj->getTypeId() == PartDesign::Line::getClassTypeId()) { mode = mm1TwoPoints; } else if(obj->getTypeId() == PartDesign::Plane::getClassTypeId()) { mode = mmFlatFace; } else return copy; // TODO Recheck this. This looks strange in case of independent copy (2015-10-31, Fat-Zer) if(!independent) { datumCopy->Support.setValue(obj, entity.c_str()); datumCopy->MapMode.setValue(mode); } else if(!entity.empty()) { datumCopy->Shape.setValue(static_cast<Part::Datum*>(obj)->Shape.getShape().getSubShape(entity.c_str())); } else { datumCopy->Shape.setValue(static_cast<Part::Datum*>(obj)->Shape.getValue()); } } else if(obj->getTypeId() == PartDesign::ShapeBinder::getClassTypeId() || obj->isDerivedFrom(Part::Feature::getClassTypeId())) { copy = App::GetApplication().getActiveDocument()->addObject("PartDesign::ShapeBinder", name.c_str()); if(!independent) static_cast<PartDesign::ShapeBinder*>(copy)->Support.setValue(obj, entity.c_str()); else shapeProp = &static_cast<PartDesign::ShapeBinder*>(copy)->Shape; } if(independent && shapeProp) { if(entity.empty()) shapeProp->setValue(static_cast<Part::Feature*>(obj)->Shape.getValue()); else shapeProp->setValue(static_cast<Part::Feature*>(obj)->Shape.getShape().getSubShape(entity.c_str())); } } return copy; }