TechDraw: Link related changes

* Support link and group objects

* Support view sync by implementing view provider API getMDIView()

* Use handleChangedPropertyType() for object migration instead of
  reimplementing Restore() because of a lots of changes in
  PropertyContainer::Restore().

* Various other small fixes.
This commit is contained in:
Zheng, Lei
2019-07-12 11:28:07 +08:00
committed by wmayer
parent f028ba42ff
commit e90d09dc40
30 changed files with 204 additions and 412 deletions

View File

@@ -256,40 +256,36 @@ void CmdTechDrawNewView::activated(int iMsg)
return;
}
std::string PageName = page->getNameInDocument();
auto inlist = page->getInListEx(true);
inlist.insert(page);
std::vector<App::DocumentObject*> shapes = getSelection().getObjectsOfType(App::GeoFeature::getClassTypeId());
std::vector<App::DocumentObject*> groups = getSelection().getObjectsOfType(App::DocumentObjectGroup::getClassTypeId());
if ((shapes.empty()) &&
(groups.empty())) {
std::vector<App::DocumentObject*> shapes;
//set projection direction from selected Face
//use first object with a face selected
App::DocumentObject* partObj = 0;
std::string subName;
for(auto &sel : getSelection().getSelectionEx(0,App::DocumentObject::getClassTypeId(),false)) {
auto obj = sel.getObject();
if(!obj || inlist.count(obj))
continue;
shapes.push_back(obj);
if(partObj)
continue;
for(auto &sub : sel.getSubNames()) {
if (TechDraw::DrawUtil::getGeomTypeFromName(sub) == "Face") {
subName = sub;
partObj = obj;
break;
}
}
}
if ((shapes.empty())) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("No Shapes or Groups in this selection"));
return;
}
if (!groups.empty()) {
shapes.insert(shapes.end(),groups.begin(),groups.end());
}
//set projection direction from selected Face
//use first object with a face selected
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
Part::Feature* partFeat = 0;
std::vector<std::string> SubNames;
std::string faceName;
bool subFound = false;
std::vector<Gui::SelectionObject>::iterator itSel = selection.begin();
for (; itSel != selection.end(); itSel++) {
if ((*itSel).getObject()->isDerivedFrom(Part::Feature::getClassTypeId())) {
partFeat = static_cast<Part::Feature*> ((*itSel).getObject());
SubNames = (*itSel).getSubNames();
if (!SubNames.empty()) {
faceName = SubNames.front();
if (TechDraw::DrawUtil::getGeomTypeFromName(faceName) == "Face") {
subFound = true;
break;
}
}
}
}
Base::Vector3d projDir;
Gui::WaitCursor wc;
@@ -303,8 +299,8 @@ void CmdTechDrawNewView::activated(int iMsg)
}
dvp->Source.setValues(shapes);
doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str());
if (subFound) {
std::pair<Base::Vector3d,Base::Vector3d> dirs = DrawGuiUtil::getProjDirFromFace(partFeat,faceName);
if (subName.size()) {
std::pair<Base::Vector3d,Base::Vector3d> dirs = DrawGuiUtil::getProjDirFromFace(partObj,subName);
projDir = dirs.first;
getDocument()->setStatus(App::Document::Status::SkipRecompute, true);
doCommand(Doc,"App.activeDocument().%s.Direction = FreeCAD.Vector(%.3f,%.3f,%.3f)",
@@ -493,40 +489,35 @@ void CmdTechDrawProjGroup::activated(int iMsg)
return;
}
std::string PageName = page->getNameInDocument();
std::vector<App::DocumentObject*> shapes = getSelection().getObjectsOfType(App::GeoFeature::getClassTypeId());
std::vector<App::DocumentObject*> groups = getSelection().getObjectsOfType(App::DocumentObjectGroup::getClassTypeId());
if ((shapes.empty()) &&
(groups.empty())) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("No Shapes or Groups in this selection"));
return;
}
if (!groups.empty()) {
shapes.insert(shapes.end(),groups.begin(),groups.end());
}
auto inlist = page->getInListEx(true);
inlist.insert(page);
//set projection direction from selected Face
//use first object with a face selected
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
Part::Feature* partFeat = 0;
std::vector<std::string> SubNames;
std::string faceName;
bool subFound = false;
std::vector<Gui::SelectionObject>::iterator itSel = selection.begin();
for (; itSel != selection.end(); itSel++) {
if ((*itSel).getObject()->isDerivedFrom(Part::Feature::getClassTypeId())) {
partFeat = static_cast<Part::Feature*> ((*itSel).getObject());
SubNames = (*itSel).getSubNames();
if (!SubNames.empty()) {
faceName = SubNames.front();
if (TechDraw::DrawUtil::getGeomTypeFromName(faceName) == "Face") {
subFound = true;
break;
}
std::vector<App::DocumentObject*> shapes;
App::DocumentObject* partObj = 0;
std::string subName;
for(auto &sel : getSelection().getSelectionEx(0,App::DocumentObject::getClassTypeId(),false)) {
auto obj = sel.getObject();
if(inlist.count(obj))
continue;
shapes.push_back(obj);
if(partObj)
continue;
for(auto &sub : sel.getSubNames()) {
if (TechDraw::DrawUtil::getGeomTypeFromName(sub) == "Face") {
subName = sub;
partObj = obj;
break;
}
}
}
if (shapes.empty()) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("No Shapes or Groups in this selection"));
return;
}
Base::Vector3d projDir;
Gui::WaitCursor wc;
@@ -541,8 +532,8 @@ void CmdTechDrawProjGroup::activated(int iMsg)
multiView->Source.setValues(shapes);
doCommand(Doc,"App.activeDocument().%s.addProjection('Front')",multiViewName.c_str());
if (subFound) {
std::pair<Base::Vector3d,Base::Vector3d> dirs = DrawGuiUtil::getProjDirFromFace(partFeat,faceName);
if (subName.size()) {
std::pair<Base::Vector3d,Base::Vector3d> dirs = DrawGuiUtil::getProjDirFromFace(partObj,subName);
getDocument()->setStatus(App::Document::Status::SkipRecompute, true);
doCommand(Doc,"App.activeDocument().%s.Anchor.Direction = FreeCAD.Vector(%.3f,%.3f,%.3f)",
multiViewName.c_str(), dirs.first.x,dirs.first.y,dirs.first.z);