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

@@ -121,7 +121,6 @@ void DrawView::onChanged(const App::Property* prop)
auto page = findParentPage();
if (ScaleType.isValue("Page")) {
Scale.setStatus(App::Property::ReadOnly,true);
App::GetApplication().signalChangePropertyEditor(Scale);
if (page != nullptr) {
if(std::abs(page->Scale.getValue() - getScale()) > FLT_EPSILON) {
Scale.setValue(page->Scale.getValue());
@@ -131,10 +130,8 @@ void DrawView::onChanged(const App::Property* prop)
} else if ( ScaleType.isValue("Custom") ) {
//don't change Scale
Scale.setStatus(App::Property::ReadOnly,false);
App::GetApplication().signalChangePropertyEditor(Scale);
} else if ( ScaleType.isValue("Automatic") ) {
Scale.setStatus(App::Property::ReadOnly,true);
App::GetApplication().signalChangePropertyEditor(Scale);
if (!checkFit(page)) {
double newScale = autoScale(page->getPageWidth(),page->getPageHeight());
if(std::abs(newScale - getScale()) > FLT_EPSILON) { //stops onChanged/execute loop
@@ -162,23 +159,19 @@ void DrawView::handleXYLock(void)
if (isLocked()) {
if (!X.testStatus(App::Property::ReadOnly)) {
X.setStatus(App::Property::ReadOnly,true);
App::GetApplication().signalChangePropertyEditor(X);
X.purgeTouched();
}
if (!Y.testStatus(App::Property::ReadOnly)) {
Y.setStatus(App::Property::ReadOnly,true);
App::GetApplication().signalChangePropertyEditor(Y);
Y.purgeTouched();
}
} else {
if (X.testStatus(App::Property::ReadOnly)) {
X.setStatus(App::Property::ReadOnly,false);
App::GetApplication().signalChangePropertyEditor(X);
X.purgeTouched();
}
if (Y.testStatus(App::Property::ReadOnly)) {
Y.setStatus(App::Property::ReadOnly,false);
App::GetApplication().signalChangePropertyEditor(Y);
Y.purgeTouched();
}
}
@@ -327,93 +320,46 @@ std::vector<TechDraw::DrawLeaderLine*> DrawView::getLeaders() const
return result;
}
void DrawView::Restore(Base::XMLReader &reader)
void DrawView::handleChangedPropertyType(
Base::XMLReader &reader, const char * TypeName, App::Property * prop)
{
// this is temporary code for backwards compat (within v0.17). can probably be deleted once there are no development
// fcstd files with old property types in use.
reader.readElement("Properties");
int Cnt = reader.getAttributeAsInteger("Count");
for (int i=0 ;i<Cnt ;i++) {
reader.readElement("Property");
const char* PropName = reader.getAttribute("name");
const char* TypeName = reader.getAttribute("type");
App::Property* schemaProp = getPropertyByName(PropName);
try {
if(schemaProp){
if (strcmp(schemaProp->getTypeId().getName(), TypeName) == 0){ //if the property type in obj == type in schema
schemaProp->Restore(reader); //nothing special to do
} else {
if (strcmp(PropName, "Scale") == 0) {
if (schemaProp->isDerivedFrom(App::PropertyFloatConstraint::getClassTypeId())){ //right property type
schemaProp->Restore(reader); //nothing special to do (redundant)
} else { //Scale, but not PropertyFloatConstraint
App::PropertyFloat tmp;
if (strcmp(tmp.getTypeId().getName(),TypeName)) { //property in file is Float
tmp.setContainer(this);
tmp.Restore(reader);
double tmpValue = tmp.getValue();
if (tmpValue > 0.0) {
static_cast<App::PropertyFloatConstraint*>(schemaProp)->setValue(tmpValue);
} else {
static_cast<App::PropertyFloatConstraint*>(schemaProp)->setValue(1.0);
}
} else {
// has Scale prop that isn't Float!
Base::Console().Log("DrawView::Restore - old Document Scale is Not Float!\n");
// no idea
}
}
} else if (strcmp(PropName, "Source") == 0) {
App::PropertyLinkGlobal glink;
App::PropertyLink link;
if (strcmp(glink.getTypeId().getName(),TypeName) == 0) { //property in file is plg
glink.setContainer(this);
glink.Restore(reader);
if (glink.getValue() != nullptr) {
static_cast<App::PropertyLinkList*>(schemaProp)->setScope(App::LinkScope::Global);
static_cast<App::PropertyLinkList*>(schemaProp)->setValue(glink.getValue());
}
} else if (strcmp(link.getTypeId().getName(),TypeName) == 0) { //property in file is pl
link.setContainer(this);
link.Restore(reader);
if (link.getValue() != nullptr) {
static_cast<App::PropertyLinkList*>(schemaProp)->setScope(App::LinkScope::Global);
static_cast<App::PropertyLinkList*>(schemaProp)->setValue(link.getValue());
}
} else {
// has Source prop isn't PropertyLink or PropertyLinkGlobal!
Base::Console().Log("DrawView::Restore - old Document Source is weird: %s\n", TypeName);
// no idea
}
} else {
Base::Console().Log("DrawView::Restore - old Document has unknown Property\n");
}
}
if (prop == &Scale) {
App::PropertyFloat tmp;
if (strcmp(tmp.getTypeId().getName(),TypeName)==0) { //property in file is Float
tmp.setContainer(this);
tmp.Restore(reader);
double tmpValue = tmp.getValue();
if (tmpValue > 0.0) {
Scale.setValue(tmpValue);
} else {
Scale.setValue(1.0);
}
} else {
// has Scale prop that isn't Float!
Base::Console().Log("DrawPage::Restore - old Document Scale is Not Float!\n");
// no idea
}
} else if (prop->isDerivedFrom(App::PropertyLinkList::getClassTypeId())
&& strcmp(prop->getName(),"Source")==0)
{
App::PropertyLinkGlobal glink;
App::PropertyLink link;
if (strcmp(glink.getTypeId().getName(),TypeName) == 0) { //property in file is plg
glink.setContainer(this);
glink.Restore(reader);
if (glink.getValue() != nullptr) {
static_cast<App::PropertyLinkList*>(prop)->setScope(App::LinkScope::Global);
static_cast<App::PropertyLinkList*>(prop)->setValue(glink.getValue());
}
} else if (strcmp(link.getTypeId().getName(),TypeName) == 0) { //property in file is pl
link.setContainer(this);
link.Restore(reader);
if (link.getValue() != nullptr) {
static_cast<App::PropertyLinkList*>(prop)->setScope(App::LinkScope::Global);
static_cast<App::PropertyLinkList*>(prop)->setValue(link.getValue());
}
}
catch (const Base::XMLParseException&) {
throw; // re-throw
}
catch (const Base::Exception &e) {
Base::Console().Error("%s\n", e.what());
}
catch (const std::exception &e) {
Base::Console().Error("%s\n", e.what());
}
catch (const char* e) {
Base::Console().Error("%s\n", e);
}
#ifndef FC_DEBUG
catch (...) {
Base::Console().Error("PropertyContainer::Restore: Unknown C++ exception thrown\n");
}
#endif
reader.readEndElement("Property");
}
reader.readEndElement("Properties");
}
bool DrawView::keepUpdated(void)