Skip to content

Commit

Permalink
TechDraw: Link related changes
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
realthunder committed Jul 16, 2019
1 parent 4612190 commit 572d5e0
Show file tree
Hide file tree
Showing 30 changed files with 202 additions and 409 deletions.
30 changes: 10 additions & 20 deletions src/Mod/Measure/App/Measurement.cpp
Expand Up @@ -127,17 +127,16 @@ MeasureType Measurement::getType()

for (;obj != objects.end(); ++obj, ++subEl) {

const Part::Feature *refObj = static_cast<const Part::Feature*>((*obj));
const Part::TopoShape& refShape = refObj->Shape.getShape();

// Check if solid object
if(strcmp((*subEl).c_str(), "") == 0) {
vols++;
} else {

TopoDS_Shape refSubShape;
try {
refSubShape = refShape.getSubShape((*subEl).c_str());
refSubShape = Part::Feature::getShape(*obj,(*subEl).c_str(),true);
if(refSubShape.IsNull())
return Invalid;
}
catch (Standard_Failure& e) {
std::stringstream errorMsg;
Expand Down Expand Up @@ -210,22 +209,13 @@ MeasureType Measurement::getType()

TopoDS_Shape Measurement::getShape(App::DocumentObject *obj , const char *subName) const
{
const Part::Feature *refObj = static_cast<const Part::Feature*>(obj);
const Part::TopoShape& refShape = refObj->Shape.getShape();

// Check if selecting whol object
if(strcmp(subName, "") == 0) {
return refShape.getShape();
} else {

TopoDS_Shape refSubShape;
try {
refSubShape = refShape.getSubShape(subName);
}
catch (Standard_Failure& e) {
throw Base::CADKernelError(e.GetMessageString());
}
return refSubShape;
try {
auto shape = Part::Feature::getShape(obj,subName,true);
if(shape.IsNull())
throw Part::NullShapeException("null shape");
return shape;
} catch (Standard_Failure& e) {
throw Base::CADKernelError(e.GetMessageString());
}
}

Expand Down
10 changes: 7 additions & 3 deletions src/Mod/TechDraw/App/AppTechDrawPy.cpp
Expand Up @@ -308,11 +308,13 @@ class Module : public Py::ExtensionModule<Module>
try {
EdgeWalker ew;
ew.loadEdges(edgeList);
success = ew.perform();
if (success) {
if(ew.perform()) {
std::vector<TopoDS_Wire> rw = ew.getResultNoDups();
std::vector<TopoDS_Wire> sortedWires = ew.sortStrip(rw,true);
outerWire = new TopoShapeWirePy(new TopoShape(*sortedWires.begin()));
if(sortedWires.size()) {
outerWire = new TopoShapeWirePy(new TopoShape(*sortedWires.begin()));
success = true;
}
} else {
Base::Console().Warning("ATDP::findShapeOutline: input is not planar graph. Wire detection not done\n");
}
Expand Down Expand Up @@ -461,6 +463,8 @@ class Module : public Py::ExtensionModule<Module>

void write1ViewDxf( ImpExpDxfWrite& writer, TechDraw::DrawViewPart* dvp, bool alignPage)
{
if(!dvp->hasGeometry())
return;
TechDraw::GeometryObject* go = dvp->getGeometryObject();
TopoDS_Shape s = TechDraw::mirrorShape(go->getVisHard());
double offX = 0.0;
Expand Down
76 changes: 17 additions & 59 deletions src/Mod/TechDraw/App/DrawPage.cpp
Expand Up @@ -80,7 +80,7 @@ DrawPage::DrawPage(void)
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/General");
bool autoUpdate = hGrp->GetBool("KeepPagesUpToDate", 1l);

ADD_PROPERTY_TYPE(KeepUpdated, (autoUpdate), group, (App::PropertyType)(App::Prop_None), "Keep page in sync with model");
ADD_PROPERTY_TYPE(KeepUpdated, (autoUpdate), group, (App::PropertyType)(App::Prop_Output), "Keep page in sync with model");
ADD_PROPERTY_TYPE(Template, (0), group, (App::PropertyType)(App::Prop_None), "Attached Template");
Template.setScope(App::LinkScope::Global);
ADD_PROPERTY_TYPE(Views, (0), group, (App::PropertyType)(App::Prop_None), "Attached Views");
Expand Down Expand Up @@ -417,68 +417,26 @@ int DrawPage::getNextBalloonIndex(void)
return result;
}

void DrawPage::Restore(Base::XMLReader &reader)
void DrawPage::handleChangedPropertyType(
Base::XMLReader &reader, const char * TypeName, App::Property * prop)
{
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
} 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("DrawPage::Restore - old Document Scale is Not Float!\n");
// no idea
}
}
} else {
Base::Console().Log("DrawPage::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
}
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");
}

// Python Drawing feature ---------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion src/Mod/TechDraw/App/DrawPage.h
Expand Up @@ -57,7 +57,8 @@ class TechDrawExport DrawPage: public App::DocumentObject
/// recalculate the Feature
virtual App::DocumentObjectExecReturn *execute(void);
//@}
void Restore(Base::XMLReader &reader);
virtual void handleChangedPropertyType(
Base::XMLReader &reader, const char * TypeName, App::Property * prop) override;

int addView(App::DocumentObject *docObj);
int removeView(App::DocumentObject* docObj);
Expand Down
4 changes: 3 additions & 1 deletion src/Mod/TechDraw/App/DrawProjGroup.cpp
Expand Up @@ -174,7 +174,10 @@ App::DocumentObjectExecReturn *DrawProjGroup::execute(void)
// }

for (auto& item: getViewsAsDPGI()) {
bool touched = item->isTouched();
item->autoPosition();
if(!touched)
item->purgeTouched();
}

return DrawViewCollection::execute();
Expand Down Expand Up @@ -427,7 +430,6 @@ App::DocumentObject * DrawProjGroup::addProjection(const char *viewProjType)
Anchor.purgeTouched();
view->LockPosition.setValue(true); //lock "Front" position within DPG (note not Page!).
view->LockPosition.setStatus(App::Property::ReadOnly,true); //Front should stay locked.
App::GetApplication().signalChangePropertyEditor(view->LockPosition);
view->LockPosition.purgeTouched();
requestPaint(); //make sure the group object is on the Gui page
}
Expand Down
6 changes: 6 additions & 0 deletions src/Mod/TechDraw/App/DrawUtil.cpp
Expand Up @@ -83,6 +83,9 @@ using namespace TechDraw;
boost::match_flag_type flags = boost::match_default;
// char* endChar;
std::string::const_iterator begin = geomName.begin();
auto pos = geomName.rfind('.');
if(pos!=std::string::npos)
begin += pos+1;
std::string::const_iterator end = geomName.end();
std::stringstream ErrorMsg;

Expand All @@ -105,6 +108,9 @@ std::string DrawUtil::getGeomTypeFromName(std::string geomName)
boost::match_results<std::string::const_iterator> what;
boost::match_flag_type flags = boost::match_default;
std::string::const_iterator begin = geomName.begin();
auto pos = geomName.rfind('.');
if(pos!=std::string::npos)
begin += pos+1;
std::string::const_iterator end = geomName.end();
std::stringstream ErrorMsg;

Expand Down
124 changes: 35 additions & 89 deletions src/Mod/TechDraw/App/DrawView.cpp
Expand Up @@ -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());
Expand All @@ -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
Expand Down Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -326,93 +319,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
}
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");
} 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());
}
}
#endif

reader.readEndElement("Property");
}
reader.readEndElement("Properties");
}

bool DrawView::keepUpdated(void)
Expand Down

0 comments on commit 572d5e0

Please sign in to comment.