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

@@ -308,11 +308,13 @@ private:
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");
}
@@ -461,6 +463,8 @@ private:
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;

View File

@@ -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");
@@ -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 ---------------------------------------------------------

View File

@@ -57,7 +57,8 @@ public:
/// 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);

View File

@@ -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();
@@ -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
}

View File

@@ -84,6 +84,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;
@@ -106,6 +109,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;

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)

View File

@@ -67,7 +67,8 @@ public:
virtual void onDocumentRestored() override;
virtual short mustExecute() const override;
//@}
void Restore(Base::XMLReader &reader) override;
virtual void handleChangedPropertyType(
Base::XMLReader &reader, const char * TypeName, App::Property * prop) override;
bool isInClip();
DrawViewClip* getClipGroup(void);

View File

@@ -146,72 +146,3 @@ std::string DrawViewArch::getSVGTail(void)
std::string tail = "\\n</svg>";
return tail;
}
//DVA is still Source PropertyLink so needs different logic vs DV::Restore
void DrawViewArch::Restore(Base::XMLReader &reader)
{
// 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, "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::PropertyLink*>(schemaProp)->setScope(App::LinkScope::Global);
static_cast<App::PropertyLink*>(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::PropertyLink*>(schemaProp)->setScope(App::LinkScope::Global);
static_cast<App::PropertyLink*>(schemaProp)->setValue(link.getValue());
}
} else {
// has Source prop isn't PropertyLink or PropertyLinkGlobal!
Base::Console().Log("DrawViewArch::Restore - old Document Source is weird: %s\n", TypeName);
// no idea
}
} else {
Base::Console().Log("DrawViewArch::Restore - old Document has unknown Property\n");
}
}
}
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");
}

View File

@@ -66,8 +66,6 @@ public:
virtual short mustExecute() const override;
void Restore(Base::XMLReader &reader) override;
protected:
/* virtual void onChanged(const App::Property* prop) override;*/

View File

@@ -143,75 +143,6 @@ std::string DrawViewDraft::getSVGTail(void)
return tail;
}
//DVD is still compatible with old Source PropertyLink so doesn't need DV::Restore logic
void DrawViewDraft::Restore(Base::XMLReader &reader)
{
// 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, "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::PropertyLink*>(schemaProp)->setScope(App::LinkScope::Global);
static_cast<App::PropertyLink*>(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::PropertyLink*>(schemaProp)->setScope(App::LinkScope::Global);
static_cast<App::PropertyLink*>(schemaProp)->setValue(link.getValue());
}
} else {
// has Source prop isn't PropertyLink or PropertyLinkGlobal!
Base::Console().Log("DrawViewDraft::Restore - old Document Source is weird: %s\n", TypeName);
// no idea
}
} else {
Base::Console().Log("DrawViewDraft::Restore - old Document has unknown Property\n");
}
}
}
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 ---------------------------------------------------------
namespace App {

View File

@@ -64,9 +64,6 @@ public:
virtual short mustExecute() const override;
void Restore(Base::XMLReader &reader) override;
protected:
/* virtual void onChanged(const App::Property* prop) override;*/
Base::BoundBox3d bbox;

View File

@@ -179,8 +179,13 @@ TopoDS_Shape DrawViewPart::getSourceShape(void) const
} else {
std::vector<TopoDS_Shape> sourceShapes;
for (auto& l:links) {
std::vector<TopoDS_Shape> shapeList = getShapesFromObject(l);
sourceShapes.insert(sourceShapes.end(),shapeList.begin(),shapeList.end());
auto shape = Part::Feature::getShape(l);
if(!shape.IsNull())
sourceShapes.push_back(shape);
else {
std::vector<TopoDS_Shape> shapeList = getShapesFromObject(l);
sourceShapes.insert(sourceShapes.end(),shapeList.begin(),shapeList.end());
}
}
BRep_Builder builder;
@@ -330,7 +335,7 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void)
geometryObject = buildGeometryObject(mirroredShape,viewAxis);
#if MOD_TECHDRAW_HANDLE_FACES
auto start = chrono::high_resolution_clock::now();
auto start = std::chrono::high_resolution_clock::now();
if (handleFaces() && !geometryObject->usePolygonHLR()) {
try {
extractFaces();
@@ -348,9 +353,9 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void)
//add centerlines to geometry edges list
addCenterLinesToGeom();
auto end = chrono::high_resolution_clock::now();
auto end = std::chrono::high_resolution_clock::now();
auto diff = end - start;
double diffOut = chrono::duration <double, milli> (diff).count();
double diffOut = std::chrono::duration <double, std::milli> (diff).count();
Base::Console().Log("TIMING - %s DVP spent: %.3f millisecs handling Faces\n",
getNameInDocument(),diffOut);
@@ -415,7 +420,7 @@ TechDraw::GeometryObject* DrawViewPart::buildGeometryObject(TopoDS_Shape shape,
viewAxis);
}
auto start = chrono::high_resolution_clock::now();
auto start = std::chrono::high_resolution_clock::now();
go->extractGeometry(TechDraw::ecHARD, //always show the hard&outline visible lines
true);
@@ -451,9 +456,9 @@ TechDraw::GeometryObject* DrawViewPart::buildGeometryObject(TopoDS_Shape shape,
go->extractGeometry(TechDraw::ecUVISO,
false);
}
auto end = chrono::high_resolution_clock::now();
auto end = std::chrono::high_resolution_clock::now();
auto diff = end - start;
double diffOut = chrono::duration <double, milli> (diff).count();
double diffOut = std::chrono::duration <double, std::milli> (diff).count();
Base::Console().Log("TIMING - %s DVP spent: %.3f millisecs in GO::extractGeometry\n",getNameInDocument(),diffOut);
const std::vector<TechDraw::BaseGeom *> & edges = go->getEdgeGeometry();

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);

View File

@@ -1023,7 +1023,8 @@ void CmdTechDrawLinkDimension::activated(int iMsg)
if (!result)
return;
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx(0,
App::DocumentObject::getClassTypeId(),0);
App::DocumentObject* obj3D = 0;
std::vector<App::DocumentObject*> parts;
@@ -1031,13 +1032,11 @@ void CmdTechDrawLinkDimension::activated(int iMsg)
std::vector<Gui::SelectionObject>::iterator itSel = selection.begin();
for (; itSel != selection.end(); itSel++) {
if ((*itSel).getObject()->isDerivedFrom(Part::Feature::getClassTypeId())) {
obj3D = ((*itSel).getObject());
std::vector<std::string> subList = (*itSel).getSubNames();
for (auto& s:subList) {
parts.push_back(obj3D);
subs.push_back(s);
}
obj3D = ((*itSel).getObject());
std::vector<std::string> subList = (*itSel).getSubNames();
for (auto& s:subList) {
parts.push_back(obj3D);
subs.push_back(s);
}
}

View File

@@ -237,7 +237,7 @@ std::pair<Base::Vector3d,Base::Vector3d> DrawGuiUtil::get3DDirAndRot()
return result;
}
std::pair<Base::Vector3d,Base::Vector3d> DrawGuiUtil::getProjDirFromFace(Part::Feature* obj, std::string faceName)
std::pair<Base::Vector3d,Base::Vector3d> DrawGuiUtil::getProjDirFromFace(App::DocumentObject* obj, std::string faceName)
{
std::pair<Base::Vector3d,Base::Vector3d> d3Dirs = get3DDirAndRot();
Base::Vector3d d3Up = (d3Dirs.first).Cross(d3Dirs.second);
@@ -248,15 +248,13 @@ std::pair<Base::Vector3d,Base::Vector3d> DrawGuiUtil::getProjDirFromFace(Part::F
projDir = d3Dirs.first;
rotVec = d3Dirs.second;
if (DrawUtil::getGeomTypeFromName(faceName) != "Face") {
auto ts = Part::Feature::getShape(obj,faceName.c_str());
if(ts.IsNull() || ts.ShapeType()!=TopAbs_FACE) {
Base::Console().Warning("getProjDirFromFace(%s) is not a Face\n",faceName.c_str());
return dirs;
}
Part::TopoShape ts = obj->Shape.getShape();
ts.setPlacement(obj->globalPlacement());
TopoDS_Shape subShape = ts.getSubShape(faceName.c_str());
const TopoDS_Face& face = TopoDS::Face(subShape);
const TopoDS_Face& face = TopoDS::Face(ts);
TopAbs_Orientation orient = face.Orientation();
BRepAdaptor_Surface adapt(face);

View File

@@ -51,7 +51,7 @@ class TechDrawGuiExport DrawGuiUtil {
static void dumpRectF(const char* text, const QRectF& r);
static void dumpPointF(const char* text, const QPointF& p);
static std::pair<Base::Vector3d,Base::Vector3d> get3DDirAndRot();
static std::pair<Base::Vector3d,Base::Vector3d> getProjDirFromFace(Part::Feature* obj, std::string faceName);
static std::pair<Base::Vector3d,Base::Vector3d> getProjDirFromFace(App::DocumentObject* obj, std::string faceName);
};

View File

@@ -843,7 +843,6 @@ void MDIViewPage::toggleKeepUpdated(void)
{
bool state = m_vpPage->getDrawPage()->KeepUpdated.getValue();
m_vpPage->getDrawPage()->KeepUpdated.setValue(!state);
App::GetApplication().signalChangePropertyEditor(m_vpPage->getDrawPage()->KeepUpdated);
}
void MDIViewPage::viewAll()

View File

@@ -84,7 +84,7 @@ bool QGIProjGroup::sceneEventFilter(QGraphicsItem* watched, QEvent *event)
switch(event->type()) {
case QEvent::GraphicsSceneMousePress:
// TODO - Perhaps just pass the mouse event on to the anchor somehow?
if (scene()) {
if (scene() && !qAnchor->isSelected()) {
scene()->clearSelection();
qAnchor->setSelected(true);
}

View File

@@ -154,13 +154,7 @@ bool TaskLinkDim::dimReferencesSelection(const TechDraw::DrawViewDimension* dim)
return result;
}
//Part::Feature* refPart = static_cast<Part::Feature*>(dim->References3D.getValues().at(0));
std::vector<Part::Feature*> refParts;
std::vector<App::DocumentObject*> docObjs = dim->References3D.getValues();
for (auto& d: docObjs) {
Part::Feature* part = static_cast<Part::Feature*>(d);
refParts.push_back(part);
}
std::vector<App::DocumentObject*> refParts = dim->References3D.getValues();
std::vector<std::string> refSubs = dim->References3D.getSubValues();
if (refParts.size() == m_parts.size()) {
if(refParts.size() == 0) {

View File

@@ -240,6 +240,10 @@ MDIViewPage* ViewProviderDrawingView::getMDIViewPage() const
return result;
}
Gui::MDIView *ViewProviderDrawingView::getMDIView() {
return getMDIViewPage();
}
void ViewProviderDrawingView::onGuiRepaint(const TechDraw::DrawView* dv)
{
// Base::Console().Message("VPDV::onGuiRepaint(%s)\n", dv->getNameInDocument());

View File

@@ -70,6 +70,7 @@ public:
QGIView* getQView(void);
MDIViewPage* getMDIViewPage() const;
virtual Gui::MDIView *getMDIView() override;
/** @name Restoring view provider from document load */
//@{

View File

@@ -202,3 +202,11 @@ TechDraw::DrawGeomHatch* ViewProviderGeomHatch::getViewObject() const
{
return dynamic_cast<TechDraw::DrawGeomHatch*>(pcObject);
}
Gui::MDIView *ViewProviderGeomHatch::getMDIView() {
auto obj = getViewObject();
if(!obj) return 0;
auto vp = Gui::Application::Instance->getViewProvider(obj->getSourceView());
if(!vp) return 0;
return vp->getMDIView();
}

View File

@@ -67,6 +67,8 @@ public:
void getParameters(void);
TechDraw::DrawGeomHatch* getViewObject() const;
virtual Gui::MDIView *getMDIView() override;
};
} // namespace TechDrawGui

View File

@@ -38,6 +38,7 @@
#include <App/Application.h>
#include <App/Document.h>
#include <App/DocumentObject.h>
#include <Gui/Application.h>
//#include <Gui/SoFCSelection.h>
//#include <Gui/Selection.h>
@@ -121,3 +122,12 @@ TechDraw::DrawHatch* ViewProviderHatch::getViewObject() const
{
return dynamic_cast<TechDraw::DrawHatch*>(pcObject);
}
Gui::MDIView *ViewProviderHatch::getMDIView() {
auto obj = getViewObject();
if(!obj) return 0;
auto vp = Gui::Application::Instance->getViewProvider(obj->getSourceView());
if(!vp) return 0;
return vp->getMDIView();
}

View File

@@ -56,6 +56,8 @@ public:
virtual void updateData(const App::Property*);
TechDraw::DrawHatch* getViewObject() const;
virtual Gui::MDIView *getMDIView() override;
private:
static App::PropertyFloatConstraint::Constraints scaleRange;

View File

@@ -164,6 +164,7 @@ void ViewProviderPage::updateData(const App::Property* prop)
} else {
sPixmap = "TechDraw_Tree_Page_Unsync";
}
signalChangeIcon();
//if the template is changed, rebuild the visual
} else if (prop == &(getDrawPage()->Template)) {
if(m_mdiView &&
@@ -218,8 +219,7 @@ bool ViewProviderPage::setEdit(int ModNum)
bool ViewProviderPage::doubleClicked(void)
{
Visibility.setValue(true);
showMDIViewPage();
show();
Gui::getMainWindow()->setActiveWindow(m_mdiView);
return true;
}
@@ -249,6 +249,8 @@ bool ViewProviderPage::showMDIViewPage()
Gui::getMainWindow()->addWindow(m_mdiView);
m_mdiView->viewAll(); //this is empty function
m_mdiView->showMaximized();
if(!getDrawPage()->KeepUpdated.getValue())
getDrawPage()->KeepUpdated.setValue(true);
} else {
m_mdiView->updateDrawing();
m_mdiView->redrawAllViews();
@@ -429,3 +431,8 @@ TechDraw::DrawPage* ViewProviderPage::getDrawPage() const
}
return dynamic_cast<TechDraw::DrawPage*>(pcObject);
}
Gui::MDIView *ViewProviderPage::getMDIView() {
showMDIViewPage();
return m_mdiView.data();
}

View File

@@ -85,6 +85,8 @@ public:
bool showMDIViewPage();
void removeMDIView(void);
virtual Gui::MDIView *getMDIView() override;
bool getFrameState(void);
void setFrameState(bool state);
void toggleFrameState(void);

View File

@@ -195,6 +195,10 @@ MDIViewPage* ViewProviderTemplate::getMDIViewPage(void)
return myMdi;
}
Gui::MDIView *ViewProviderTemplate::getMDIView() {
return getMDIViewPage();
}
TechDraw::DrawTemplate* ViewProviderTemplate::getTemplate() const
{
return dynamic_cast<TechDraw::DrawTemplate*>(pcObject);

View File

@@ -57,6 +57,7 @@ public:
QGITemplate* getQTemplate(void);
TechDraw::DrawTemplate* getTemplate() const;
MDIViewPage* getMDIViewPage(void);
virtual Gui::MDIView *getMDIView() override;
void setMarkers(bool state);
};