fix independent copy and cross reference

This commit is contained in:
Stefan Tröger 2015-07-16 22:14:48 +02:00
parent a35c231d2a
commit 318c65eafd
2 changed files with 27 additions and 21 deletions

View File

@ -930,13 +930,27 @@ void finishFeature(const Gui::Command* cmd, const std::string& FeatName, const b
const unsigned validateSketches(std::vector<App::DocumentObject*>& sketches,
std::vector<PartDesignGui::TaskFeaturePick::featureStatus>& status,
std::vector<App::DocumentObject*>::iterator& firstValidSketch)
{
{
PartDesign::Body* pcActiveBody = PartDesignGui::getBody(false);
App::Part* pcActivePart = PartDesignGui::getPartFor(pcActiveBody, false);
// TODO: If the user previously opted to allow multiple use of sketches or use of sketches from other bodies,
// then count these as valid sketches!
unsigned validSketches = 0;
firstValidSketch = sketches.end();
for (std::vector<App::DocumentObject*>::iterator s = sketches.begin(); s != sketches.end(); s++) {
// Check whether this plane belongs to the active body
if (!pcActiveBody->hasFeature(*s)) {
if(pcActivePart->hasObject(*s, true))
status.push_back(PartDesignGui::TaskFeaturePick::otherBody);
else
status.push_back(PartDesignGui::TaskFeaturePick::otherPart);
continue;
}
//Base::Console().Error("Checking sketch %s\n", (*s)->getNameInDocument());
// Check whether this sketch is already being used by another feature
// Body features don't count...
@ -955,11 +969,9 @@ void finishFeature(const Gui::Command* cmd, const std::string& FeatName, const b
status.push_back(PartDesignGui::TaskFeaturePick::isUsed);
continue;
}
// Check whether this sketch belongs to the active body
PartDesign::Body* body = PartDesignGui::getBody(/*messageIfNot = */false);
if (!body->hasFeature(*s)) {
status.push_back(PartDesignGui::TaskFeaturePick::otherBody);
if (pcActiveBody->isAfterTip(*s)){
status.push_back(PartDesignGui::TaskFeaturePick::afterTip);
continue;
}

View File

@ -229,7 +229,7 @@ App::DocumentObject* TaskFeaturePick::makeCopy(App::DocumentObject* obj, bool in
//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 = App::GetApplication().getActiveDocument()->getUniqueObjectName(obj->getNameInDocument());
auto name = std::string("Copy") + std::string(obj->getNameInDocument());
auto copy = App::GetApplication().getActiveDocument()->addObject(obj->getTypeId().getName(), name.c_str());
if(copy) {
@ -237,7 +237,7 @@ App::DocumentObject* TaskFeaturePick::makeCopy(App::DocumentObject* obj, bool in
std::vector<App::Property*> props;
std::vector<App::Property*> cprops;
obj->getPropertyList(props);
obj->getPropertyList(cprops);
copy->getPropertyList(cprops);
try{
auto it = cprops.begin();
for( App::Property* prop : props ) {
@ -253,21 +253,15 @@ App::DocumentObject* TaskFeaturePick::makeCopy(App::DocumentObject* obj, bool in
++it;
continue;
}
Base::StringWriter writer;
//the properties xml tag is often not correctly cosed and only has "</>". This leads
//to a end of document exception. To prevent this we add a dummy tag arround.
writer.Stream() << writer.ind() << "<Prop>" << std::endl;
writer.ind();
prop->Save(writer);
writer.decInd();
writer.Stream() << writer.ind() << "</Prop>" << std::endl;
std::stringstream stream(writer.getString());
Base::XMLReader reader("test", stream);
reader.readElement("Prop");
App::Property* cprop = *it++;
cprop->Restore(reader);
if( strcmp(prop->getName(), "Label") == 0 ) {
static_cast<App::PropertyString*>(cprop)->setValue("wuhahahahah");
continue;
}
cprop->Paste(*prop);
}
}
catch(const Base::Exception& e) {