Skip to content

Commit

Permalink
Consolidate Section logic in DrawViewSection
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan authored and wwmayer committed Dec 4, 2016
1 parent edab34c commit f036438
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 40 deletions.
45 changes: 45 additions & 0 deletions src/Mod/TechDraw/App/DrawViewSection.cpp
Expand Up @@ -74,6 +74,7 @@
#include "Geometry.h"
#include "GeometryObject.h"
#include "EdgeWalker.h"
#include "DrawUtil.h"
#include "DrawProjectSplit.h"
#include "DrawViewSection.h"

Expand Down Expand Up @@ -449,6 +450,50 @@ bool DrawViewSection::isReallyInBox (const Base::Vector3d v, const Base::BoundBo
return true;
}

//! calculate the section Normal/Projection Direction given baseView projection direction and section name
/*static*/
Base::Vector3d DrawViewSection::getSectionVector (const Base::Vector3d baseViewDir, const std::string sectionName)
{
Base::Vector3d result;
Base::Vector3d stdX(1.0,0.0,0.0);
Base::Vector3d stdY(0.0,1.0,0.0);
Base::Vector3d stdZ(0.0,0.0,1.0);
Base::Vector3d view = baseViewDir;
view.Normalize();
Base::Vector3d left = view.Cross(stdZ);
left.Normalize(); //redundent?
Base::Vector3d down = view.Cross(left);
down.Normalize(); //redundent?
double dot = view.Dot(stdZ);

if (sectionName == "Up") {
result = down;
if (DrawUtil::fpCompare(fabs(dot),1.0)) {
result = (-1.0 * stdY);
}
} else if (sectionName == "Down") {
result = down * -1.0;
if (DrawUtil::fpCompare(fabs(dot),1.0)) {
result = stdY;
}
} else if (sectionName == "Left") {
result = left * -1.0;
if (DrawUtil::fpCompare(fabs(dot),1.0)) {
result = stdX;
}
} else if (sectionName == "Right") {
result = left;
if (DrawUtil::fpCompare(fabs(dot),1.0)) {
result = -1.0 * stdX;
}
} else {
Base::Console().Log("Error - DVS::getSectionVector - bad sectionName: %s\n",sectionName.c_str());
result = stdZ;
}

return result;
}

void DrawViewSection::getParameters()
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/TechDraw/App/DrawViewSection.h
Expand Up @@ -84,6 +84,8 @@ class TechDrawExport DrawViewSection : public DrawViewPart

public:
std::vector<TechDrawGeometry::Face*> getFaceGeometry();
static Base::Vector3d getSectionVector (const Base::Vector3d baseViewDir, const std::string sectionName);

static const char* SectionDirEnums[];

protected:
Expand Down
47 changes: 7 additions & 40 deletions src/Mod/TechDraw/Gui/TaskSectionView.cpp
Expand Up @@ -43,11 +43,13 @@
#include <Mod/Part/App/PartFeature.h>

#include <Mod/TechDraw/App/DrawPage.h>
#include <Mod/TechDraw/App/DrawUtil.h>

#include "TaskSectionView.h"
#include <Mod/TechDraw/Gui/ui_TaskSectionView.h>

using namespace Gui;
using namespace TechDraw;
using namespace TechDrawGui;

void _printVect(char* label, Base::Vector3d v);
Expand Down Expand Up @@ -119,61 +121,26 @@ void TaskSectionView::resetValues()
bool TaskSectionView::calcValues()
{
bool result = true;
Base::Vector3d stdX(1.0,0.0,0.0);
Base::Vector3d stdY(0.0,1.0,0.0);
Base::Vector3d stdZ(0.0,0.0,1.0);
Base::Vector3d view = m_base->Direction.getValue();
sectionDir = "unset";

if (ui->pb_Up->isChecked()) {
sectionDir = "Up";
sectionProjDir = view;
sectionNormal = Base::Vector3d(view.x,view.z,-view.y);
if (view == stdZ) {
sectionProjDir = (-1.0 * stdY);
sectionNormal = (-1.0 * stdY);
} else if (view == (-1.0 * stdZ)) {
sectionProjDir = (-1.0 * stdY);
sectionNormal = (-1.0 * stdY);
}
sectionProjDir = DrawViewSection::getSectionVector(view,sectionDir);
} else if (ui->pb_Down->isChecked()) {
sectionDir = "Down";
sectionProjDir = view;
sectionNormal = Base::Vector3d(-view.x,-view.z,view.y);
if (view == stdZ) {
sectionProjDir = stdY;
sectionNormal = stdY;
} else if (view == (-1.0 * stdZ)) {
sectionProjDir = stdY;
sectionNormal = stdY;
}
sectionProjDir = DrawViewSection::getSectionVector(view,sectionDir);
} else if (ui->pb_Left->isChecked()) {
sectionDir = "Left";
sectionProjDir = Base::Vector3d(-view.y,view.x,view.z);
sectionNormal = Base::Vector3d(-view.y,view.x,0.0);
if (view == stdZ) {
sectionProjDir = stdX;
sectionNormal = stdX;
} else if (view == (-1.0 * stdZ)) {
sectionProjDir = stdX;
sectionNormal = stdX;
}
sectionProjDir = DrawViewSection::getSectionVector(view,sectionDir);
} else if (ui->pb_Right->isChecked()) {
sectionDir = "Right";
sectionProjDir = Base::Vector3d(view.y,-view.x,view.z);
sectionNormal = Base::Vector3d(view.y,-view.x,0.0);
if (view == stdZ) {
sectionProjDir = -1.0 * stdX;
sectionNormal = -1.0 * stdX;
} else if (view == (-1.0 * stdZ)) {
sectionProjDir = -1.0 * stdX;
sectionNormal = -1.0 * stdX;
}
sectionProjDir = DrawViewSection::getSectionVector(view,sectionDir);
} else {
Base::Console().Message("Select a direction\n");
result = false;
}

sectionNormal = sectionProjDir;
if (result) {
ui->leNormal->setText(formatVector(sectionNormal));
ui->leProjDir->setText(formatVector(sectionProjDir));
Expand Down

0 comments on commit f036438

Please sign in to comment.