Skip to content

Commit

Permalink
Fix ProjectionGroup Automatic scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan authored and yorikvanhavre committed Oct 31, 2016
1 parent a912ccd commit a5a2070
Show file tree
Hide file tree
Showing 11 changed files with 196 additions and 139 deletions.
215 changes: 116 additions & 99 deletions src/Mod/TechDraw/App/DrawProjGroup.cpp

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/Mod/TechDraw/App/DrawProjGroup.h
Expand Up @@ -65,7 +65,7 @@ class TechDrawExport DrawProjGroup : public TechDraw::DrawViewCollection
Base::BoundBox3d getBoundingBox() const;
double calculateAutomaticScale() const;
virtual QRectF getRect(void) const;

virtual bool checkFit(TechDraw::DrawPage* p) const override;
/// Check if container has a view of a specific type
bool hasProjection(const char *viewProjType) const;

Expand Down Expand Up @@ -172,6 +172,8 @@ class TechDrawExport DrawProjGroup : public TechDraw::DrawViewCollection

/// Returns pointer to our page, or NULL if it couldn't be located
TechDraw::DrawPage * getPage(void) const;
void updateChildren(double scale);

};

} //namespace TechDraw
Expand Down
18 changes: 13 additions & 5 deletions src/Mod/TechDraw/App/DrawView.cpp
Expand Up @@ -40,6 +40,8 @@
#include "DrawPage.h"
#include "DrawViewCollection.h"
#include "DrawViewClip.h"
#include "DrawProjGroup.h"
#include "DrawProjGroupItem.h"

#include <Mod/TechDraw/App/DrawViewPy.h> // generated from DrawViewPy.xml

Expand Down Expand Up @@ -83,7 +85,6 @@ DrawView::~DrawView()

App::DocumentObjectExecReturn *DrawView::execute(void)
{
//Base::Console().Message("TRACE - DV::execute - %s\n",Label.getValue());
TechDraw::DrawPage *page = findParentPage();
if(page) {
if (ScaleType.isValue("Document")) {
Expand All @@ -92,12 +93,19 @@ App::DocumentObjectExecReturn *DrawView::execute(void)
}
} else if (ScaleType.isValue("Automatic")) {
//check fit. if too big, rescale
if (!checkFit(page)) {
double newScale = autoScale(page->getPageWidth(),page->getPageHeight());
if(std::abs(newScale - Scale.getValue()) > FLT_EPSILON) { //stops onChanged/execute loop
Scale.setValue(newScale);
//if (dpg) { leave alone } else {
if (this->isDerivedFrom(TechDraw::DrawProjGroup::getClassTypeId())) {
//do nothing
} else {
if (!checkFit(page)) {
double newScale = autoScale(page->getPageWidth(),page->getPageHeight());
if(std::abs(newScale - Scale.getValue()) > FLT_EPSILON) { //stops onChanged/execute loop
Scale.setValue(newScale);
}
}
}
} else if (ScaleType.isValue("Custom")) {
//Base::Console().Message("TRACE - DV::execute - custom %s Scale: %.3f\n",getNameInDocument(),Scale.getValue());
}
}
return App::DocumentObject::StdReturn; //DO::execute returns 0
Expand Down
5 changes: 3 additions & 2 deletions src/Mod/TechDraw/App/DrawViewPart.cpp
Expand Up @@ -162,7 +162,7 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void)
return new App::DocumentObjectExecReturn("FVP - Linked shape object is empty");
}

//Base::Console().Message("TRACE - DVP::execute - %s \n",Label.getValue());
//Base::Console().Message("TRACE - DVP::execute - %s/%s ScaleType: %s\n",getNameInDocument(),Label.getValue(),ScaleType.getValueAsString());

(void) DrawView::execute(); //make sure Scale is up to date

Expand Down Expand Up @@ -226,7 +226,8 @@ short DrawViewPart::mustExecute() const
if (!isRestoring()) {
result = (Direction.isTouched() ||
Source.isTouched() ||
Scale.isTouched() );
Scale.isTouched() ||
ScaleType.isTouched());
}

if (result) {
Expand Down
2 changes: 0 additions & 2 deletions src/Mod/TechDraw/Gui/Command.cpp
Expand Up @@ -422,8 +422,6 @@ void CmdTechDrawProjGroup::activated(int iMsg)
// set the anchor
std::string anchor = "Front";
doCommand(Doc,"App.activeDocument().%s.addProjection('%s')",multiViewName.c_str(),anchor.c_str());
doCommand(Doc,"App.activeDocument().%s.Anchor = App.activeDocument().%s.getItemByLabel('%s')",
multiViewName.c_str(),multiViewName.c_str(),anchor.c_str());
// add the multiView to the page
doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),multiViewName.c_str());

Expand Down
54 changes: 26 additions & 28 deletions src/Mod/TechDraw/Gui/TaskProjGroup.cpp
Expand Up @@ -111,6 +111,7 @@ TaskProjGroup::~TaskProjGroup()

void TaskProjGroup::viewToggled(bool toggle)
{
bool changed = false;
// Obtain name of checkbox
QString viewName = sender()->objectName();
int index = viewName.mid(7).toInt();
Expand All @@ -121,9 +122,19 @@ void TaskProjGroup::viewToggled(bool toggle)
newObj = multiView->addProjection( viewNameCStr );
newView = static_cast<TechDraw::DrawView*>(newObj);
m_mdi->redraw1View(newView);
changed = true;
} else if ( !toggle && multiView->hasProjection( viewNameCStr ) ) {
multiView->removeProjection( viewNameCStr );
changed = true;
}
if (changed) {
multiView->recompute();
if (multiView->ScaleType.isValue("Automatic")) {
double scale = multiView->Scale.getValue();
setFractionalScale(scale);
}
}

}

void TaskProjGroup::rotateButtonClicked(void)
Expand Down Expand Up @@ -165,7 +176,6 @@ void TaskProjGroup::projectionTypeChanged(int index)
if(blockUpdate)
return;

//Gui::Command::openCommand("Update projection type");
if(index == 0) {
//layout per Page (Document)
Gui::Command::doCommand(Gui::Command::Doc,
Expand All @@ -182,7 +192,6 @@ void TaskProjGroup::projectionTypeChanged(int index)
"App.activeDocument().%s.ProjectionType = '%s'",
multiView->getNameInDocument(), "Third Angle");
} else {
//Gui::Command::abortCommand();
Base::Console().Log("Error - TaskProjGroup::projectionTypeChanged - unknown projection layout: %d\n",
index);
return;
Expand All @@ -191,35 +200,37 @@ void TaskProjGroup::projectionTypeChanged(int index)
// Update checkboxes so checked state matches the drawing
setupViewCheckboxes();

//Gui::Command::commitCommand();
//Gui::Command::updateActive();
}

void TaskProjGroup::scaleTypeChanged(int index)
{
if(blockUpdate)
return;

//Gui::Command::openCommand("Update projection scale type");
if(index == 0) {
//Automatic Scale Type
// Document Scale Type
Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().%s.ScaleType = '%s'", multiView->getNameInDocument()
, "Document");
} else if(index == 1) {
// Document Scale Type
// Automatic Scale Type
Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().%s.ScaleType = '%s'", multiView->getNameInDocument()
, "Automatic");
} else if(index == 2) {
// Custom Scale Type
Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().%s.ScaleType = '%s'", multiView->getNameInDocument()
, "Custom");
int a = ui->sbScaleNum->value();
int b = ui->sbScaleDen->value();
double scale = (double) a / (double) b;
Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().%s.Scale = %f", multiView->getNameInDocument()
, scale);
} else {
//Gui::Command::abortCommand();
Base::Console().Log("Error - TaskProjGroup::scaleTypeChanged - unknown scale type: %d\n",index);
return;
}
//Gui::Command::commitCommand();
//Gui::Command::updateActive();

multiView->recompute();
Gui::Command::updateActive();
}

// ** David Eppstein / UC Irvine / 8 Aug 1993
Expand Down Expand Up @@ -281,33 +292,20 @@ void TaskProjGroup::setFractionalScale(double newScale)
void TaskProjGroup::scaleManuallyChanged(int i)
{
Q_UNUSED(i);
//TODO: See what this is about - shouldn't be simplifying the scale ratio while it's being edited... IR
if(blockUpdate)
return;
if (!multiView->ScaleType.isValue("Custom")) { //ignore if not custom!
return;
}

int a = ui->sbScaleNum->value();
int b = ui->sbScaleDen->value();

double scale = (double) a / (double) b;
// If we were not in Custom, switch to Custom in two steps
bool switchToCustom = (strcmp(multiView->ScaleType.getValueAsString(), "Custom") != 0);
if(switchToCustom) {
// First, send out command to put us into custom scale
scaleTypeChanged(ui->cmbScaleType->findText(QString::fromLatin1("Custom")));
switchToCustom = true;
}

//Gui::Command::openCommand("Update custom scale");
Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().%s.Scale = %f", multiView->getNameInDocument()
, scale);
//Gui::Command::commitCommand();
//Gui::Command::updateActive();

if(switchToCustom) {
// Second, update the GUI
ui->cmbScaleType->setCurrentIndex(ui->cmbScaleType->findText(QString::fromLatin1("Custom")));
}

multiView->recompute();
Gui::Command::updateActive();
}

void TaskProjGroup::changeEvent(QEvent *e)
Expand Down
6 changes: 6 additions & 0 deletions src/Mod/TechDraw/Gui/TaskProjGroup.ui
Expand Up @@ -133,6 +133,9 @@
</item>
<item>
<widget class="QSpinBox" name="sbScaleNum">
<property name="minimum">
<number>1</number>
</property>
<property name="value">
<number>1</number>
</property>
Expand All @@ -147,6 +150,9 @@
</item>
<item>
<widget class="QSpinBox" name="sbScaleDen">
<property name="minimum">
<number>1</number>
</property>
<property name="value">
<number>1</number>
</property>
Expand Down
12 changes: 12 additions & 0 deletions src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp
Expand Up @@ -190,6 +190,18 @@ void ViewProviderDrawingView::updateData(const App::Property* prop)
Gui::ViewProviderDocumentObject::updateData(prop);
}

MDIViewPage* ViewProviderDrawingView::getMDIViewPage() const
{
MDIViewPage* result = nullptr;
Gui::Document* guiDoc = Gui::Application::Instance->getDocument(getViewObject()->getDocument());
Gui::ViewProvider* vp = guiDoc->getViewProvider(getViewObject()->findParentPage());
ViewProviderPage* dvp = dynamic_cast<ViewProviderPage*>(vp);
if (dvp) {
result = dvp->getMDIViewPage();
}
return result;
}

TechDraw::DrawView* ViewProviderDrawingView::getViewObject() const
{
return dynamic_cast<TechDraw::DrawView*>(pcObject);
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/TechDraw/Gui/ViewProviderDrawingView.h
Expand Up @@ -33,6 +33,7 @@

namespace TechDrawGui {
class QGIView;
class MDIViewPage;

class TechDrawGuiExport ViewProviderDrawingView : public Gui::ViewProviderDocumentObject
{
Expand Down Expand Up @@ -60,6 +61,7 @@ class TechDrawGuiExport ViewProviderDrawingView : public Gui::ViewProviderDocume
virtual void updateData(const App::Property*);

QGIView* getQView(void);
MDIViewPage* getMDIViewPage() const;

/** @name Restoring view provider from document load */
//@{
Expand Down
15 changes: 13 additions & 2 deletions src/Mod/TechDraw/Gui/ViewProviderProjGroup.cpp
Expand Up @@ -47,6 +47,8 @@
#include <Gui/SoFCSelection.h>
#include <Gui/ViewProviderDocumentObject.h>

#include <Mod/TechDraw/App/DrawProjGroupItem.h>


#include "TaskProjGroup.h"
#include "ViewProviderProjGroup.h"
Expand Down Expand Up @@ -106,14 +108,23 @@ void ViewProviderProjGroup::updateData(const App::Property* prop)

}

void ViewProviderProjGroup::onChanged(const App::Property *prop)
{
Base::Console().Message("TRACE - VPPG::onChanged(%s) \n",prop->getName());
if (prop == &(getViewObject()->Scale)) {
if (getViewObject()->ScaleType.isValue("Automatic")) {
getMDIViewPage()->redraw1View(getViewObject());
}
} else if (prop == &(getViewObject()->ScaleType)) {
getMDIViewPage()->redraw1View(getViewObject());
}
}

void ViewProviderProjGroup::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
{
Q_UNUSED(menu);
Q_UNUSED(receiver);
Q_UNUSED(member);
//QAction* act;
//act = menu->addAction(QObject::tr("Show drawing"), receiver, member);
}

bool ViewProviderProjGroup::setEdit(int ModNum)
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/TechDraw/Gui/ViewProviderProjGroup.h
Expand Up @@ -59,6 +59,8 @@ class TechDrawGuiExport ViewProviderProjGroup : public ViewProviderDrawingView
TechDraw::DrawProjGroup* getObject() const;
virtual TechDraw::DrawProjGroup* getViewObject() const;
void unsetEdit(int ModNum);
virtual void onChanged(const App::Property *prop);


protected:
bool setEdit(int ModNum);
Expand Down

0 comments on commit a5a2070

Please sign in to comment.