Skip to content

Commit

Permalink
Section directions from rotated DPGI's
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan authored and wwmayer committed Dec 29, 2016
1 parent 139edb2 commit 16ce8d4
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 91 deletions.
35 changes: 0 additions & 35 deletions src/Mod/TechDraw/App/Cube.cpp
Expand Up @@ -100,7 +100,6 @@ void Cube::rotateUp()

updateIsoDirs(); //calculatge iso directions from ortho dirs
updateRotsToConfig(getCurrConfig()); //update rotations for ortho views from config table
updateIsoRots(); //calculate iso rotations from iso/ortho dirs
}

void Cube::rotateDown()
Expand All @@ -114,7 +113,6 @@ void Cube::rotateDown()

updateIsoDirs();
updateRotsToConfig(getCurrConfig());
updateIsoRots();
}

void Cube::rotateRight()
Expand All @@ -128,7 +126,6 @@ void Cube::rotateRight()

updateIsoDirs();
updateRotsToConfig(getCurrConfig());
updateIsoRots();
}

void Cube::rotateLeft()
Expand All @@ -142,7 +139,6 @@ void Cube::rotateLeft()

updateIsoDirs();
updateRotsToConfig(getCurrConfig());
updateIsoRots();
}

void Cube::spinCCW()
Expand All @@ -156,7 +152,6 @@ void Cube::spinCCW()

updateIsoDirs();
updateRotsToConfig(getCurrConfig());
updateIsoRots();
}

void Cube::spinCW()
Expand All @@ -170,7 +165,6 @@ void Cube::spinCW()

updateIsoDirs();
updateRotsToConfig(getCurrConfig());
updateIsoRots();
}

void Cube::updateIsoDirs()
Expand All @@ -185,18 +179,6 @@ void Cube::updateIsoDirs()
m_mapFrameDir.at("FrontTopRight") = frt;
}

void Cube::updateIsoRots()
{
// Base::Vector3d flb = getFrontRot() + getLeftRot() + getBottomRot();
// Base::Vector3d frb = getFrontRot() + getRightRot() + getBottomRot();
// Base::Vector3d flt = getFrontRot() + getLeftRot() + getTopRot();
//// Base::Vector3d frt = getFrontRot() + getRightRot() + getTopRot();
// m_mapFrameRot.at("FrontBottomLeft") = flb;
// m_mapFrameRot.at("FrontBottomRight") = frb;
// m_mapFrameRot.at("FrontTopLeft") = flt;
//// m_mapFrameRot.at("FrontTopRight") = frt;
}

std::string Cube::dirToView(Base::Vector3d v)
{
std::string result;
Expand Down Expand Up @@ -273,18 +255,6 @@ bool Cube::validateBoard(std::string cfg)
return result;
}

//dupl!!
std::string Cube::getBoardKey()
{
std::string result;
// Base::Vector3d frontDir = m_mapFrameDir.at("Front");
// std::string frontView = dirToView(frontDir);
// Base::Vector3d rightDir = m_mapFrameDir.at("Right");
// std::string rightView = dirToView(rightDir);
// result = frontView + rightView;
return result;
}

//get the current configuration on the board
std::string Cube::getCurrConfig(void)
{
Expand Down Expand Up @@ -484,7 +454,6 @@ Base::Vector3d Cube::getFBLRot()
{
Base::Vector3d result;
double magic1 = 157.5 * M_PI / 180.0; // 90 + 45 + magic1
// double magic1 = -22.5 * M_PI / 180.0; //45*/2
double magic2 = -17.632 * M_PI / 180.0; //±35.264° / 2 "magic angle"??
// <<https://en.wikipedia.org/wiki/Isometric_projection#Overview
Base::Vector3d up = getTop();
Expand Down Expand Up @@ -526,8 +495,6 @@ Base::Vector3d Cube::getFTLRot()
double magic1 = -157.5 * M_PI / 180.0;
double magic2 = -17.632 * M_PI / 180.0;

//+45? not quite
//-18?
Base::Vector3d up = getTop();
Base::Vector3d view = getFTL();
Base::Vector3d cross = up.Cross(view);
Expand Down Expand Up @@ -676,7 +643,6 @@ void configTable::initialize(void)
configLine cl;

//Rotations
//#include "rots.cpp"
// Rots - b/f/l/k/r/t
cl = configLine( 1 , "AB", Base::Vector3d(0,0,1), Base::Vector3d(0,0,1), Base::Vector3d(0,1,0),
Base::Vector3d(0,0,-1), Base::Vector3d(0,-1,0), Base::Vector3d(0,0,1) );
Expand Down Expand Up @@ -753,7 +719,6 @@ void configTable::initialize(void)


//Directions items
//#include "dirs.cpp"
// Dirs - b/f/l/k/r/t
cl = configLine( 1 , "AB", Base::Vector3d(1,0,0), Base::Vector3d(0,-1,0), Base::Vector3d(0,0,-1),
Base::Vector3d(0,1,0), Base::Vector3d(0,0,1), Base::Vector3d(-1,0,0) );
Expand Down
2 changes: 0 additions & 2 deletions src/Mod/TechDraw/App/Cube.h
Expand Up @@ -98,7 +98,6 @@ void initialize(Base::Vector3d r, Base::Vector3d rr, Base::Vector3d l, Base::Vec
void spinCW();

void updateIsoDirs();
void updateIsoRots();

Base::Vector3d getRight();
Base::Vector3d getFront();
Expand All @@ -123,7 +122,6 @@ void initialize(Base::Vector3d r, Base::Vector3d rr, Base::Vector3d l, Base::Vec
Base::Vector3d getFTRRot();

static std::string dirToView(Base::Vector3d v);
std::string getBoardKey(void);
void updateDirsToConfig(std::string cfg);
void updateRotsToConfig(std::string cfg);
bool validateBoard(std::string cfg);
Expand Down
14 changes: 7 additions & 7 deletions src/Mod/TechDraw/App/DrawProjGroup.cpp
Expand Up @@ -464,15 +464,15 @@ App::DocumentObject * DrawProjGroup::addProjection(const char *viewProjType)

Anchor.setValue(docObj);
view->Direction.setValue(m_frameToStdDir.at("Front")); //just (Base::Vector3d(0.0,-1.0,0.0))
view->OrientBasis.setValue(m_frameToStdRot.at("Front"));
view->RotationVector.setValue(m_frameToStdRot.at("Front"));
} else {
//TODO: really need to check with Cube to get current dir & rot this uses initial values from table
//if (DPGI(front) and DPGI(right) exist) config = front.face + right.face
//
//else
// use start up values (m_frameToStdDir/m_frameToStdRot)
view->Direction.setValue(m_frameToStdDir.at(viewProjType));
view->OrientBasis.setValue(m_frameToStdRot.at(viewProjType));
view->RotationVector.setValue(m_frameToStdRot.at(viewProjType));
}

addView(view); //from DrawViewCollection - add to ProjGroup Views
Expand Down Expand Up @@ -899,11 +899,11 @@ void DrawProjGroup::updateSecondaryDirs()
//TARFU invalid secondary type
Base::Console().Message("ERROR - DPG::updateSecondaryDirs - invalid projection type\n");
newDir = v->Direction.getValue();
newAxis = v->OrientBasis.getValue();
newAxis = v->RotationVector.getValue();
}
}
v->Direction.setValue(newDir);
v->OrientBasis.setValue(newAxis);
v->RotationVector.setValue(newAxis);
v->recomputeFeature();
}
}
Expand Down Expand Up @@ -955,7 +955,7 @@ void DrawProjGroup::spinCCW()
// used in setting view to match OpenInventor
void DrawProjGroup::setTable(Base::Vector3d dir, Base::Vector3d up)
{
std::string viewFront = Cube::dirToView(dir); //convert to closest basis vector
std::string viewFront = Cube::dirToView(dir); //convert to closest basis vector?
std::string viewUp = Cube::dirToView(up); //convert to closest basis vector
std::string altKey = viewFront + viewUp;
std::string config;
Expand Down Expand Up @@ -1002,7 +1002,7 @@ void DrawProjGroup::dumpISO(char * title)
DrawProjGroupItem* v = static_cast<DrawProjGroupItem*>(docObj);
std::string t = v->Type.getValueAsString();
dir = v->Direction.getValue();
axis = v->OrientBasis.getValue();
axis = v->RotationVector.getValue();

Base::Console().Message("%s: %s/%s\n",
t.c_str(),DrawUtil::formatVector(dir).c_str(),DrawUtil::formatVector(axis).c_str());
Expand All @@ -1023,7 +1023,7 @@ void DrawProjGroup::onDocumentRestored()
} else if (hasProjection("Front")) {
Base::Vector3d dirFront = getProjItem("Front")->Direction.getValue();
std::string viewDir = Cube::dirToView(dirFront);
Base::Vector3d rotFront = getProjItem("Rot")->OrientBasis.getValue();
Base::Vector3d rotFront = getProjItem("Rot")->RotationVector.getValue();
std::string viewRot = Cube::dirToView(rotFront);
std::string config = viewDir + viewRot;
//find(config) or try/catch
Expand Down
47 changes: 29 additions & 18 deletions src/Mod/TechDraw/App/DrawProjGroupItem.cpp
Expand Up @@ -59,11 +59,11 @@ DrawProjGroupItem::DrawProjGroupItem(void)
{
Type.setEnums(TypeEnums);
ADD_PROPERTY(Type, ((long)0));
ADD_PROPERTY_TYPE(OrientBasis ,(1.0,0.0,0.0) ,"Base",App::Prop_None,"Controls rotary orientation of item in view. ");
ADD_PROPERTY_TYPE(RotationVector ,(1.0,0.0,0.0) ,"Base",App::Prop_None,"Controls rotation of item in view. ");

//projection group controls these
Direction.setStatus(App::Property::ReadOnly,true);
//OrientBasis.setStatus(App::Property::ReadOnly,true);
RotationVector.setStatus(App::Property::ReadOnly,true);
Scale.setStatus(App::Property::ReadOnly,true);
ScaleType.setStatus(App::Property::ReadOnly,true);
}
Expand All @@ -73,7 +73,7 @@ short DrawProjGroupItem::mustExecute() const
short result = 0;
if (!isRestoring()) {
result = (Direction.isTouched() ||
OrientBasis.isTouched() ||
RotationVector.isTouched() ||
Source.isTouched() ||
Scale.isTouched() ||
ScaleType.isTouched());
Expand Down Expand Up @@ -121,32 +121,43 @@ gp_Ax2 DrawProjGroupItem::getViewAxis(const Base::Vector3d& pt,
const bool flip) const
{
gp_Ax2 viewAxis;
Base::Vector3d x = OrientBasis.getValue();
Base::Vector3d x = RotationVector.getValue();
Base::Vector3d nx = x;
x.Normalize();
Base::Vector3d na = axis;
na.Normalize();

if (DrawUtil::checkParallel(nx,na)) { //parallel/antiparallel
viewAxis = TechDrawGeometry::getViewAxis(pt,axis,flip); //use default orientation
} else {
viewAxis = TechDrawGeometry::getViewAxis(pt,axis,flip); //default orientation

if (!DrawUtil::checkParallel(nx,na)) { //!parallel/antiparallel
viewAxis = TechDrawGeometry::getViewAxis(pt,axis,x,flip);
}

return viewAxis;
}

//! rotate OrientBasis by angle radians around view Direction
Base::Vector3d DrawProjGroupItem::rotated(const double angle)
//get the angle between the current RotationVector vector and the original X dir angle
double DrawProjGroupItem::getRotateAngle()
{
Base::Vector3d line = Direction.getValue();
Base::Vector3d oldBasis = OrientBasis.getValue();
Base::Vector3d newBasis;
gp_Ax2 viewAxis;
Base::Vector3d x = RotationVector.getValue(); //current rotation
Base::Vector3d nx = x;
x.Normalize();
Base::Vector3d na = Direction.getValue();
na.Normalize();
Base::Vector3d org(0.0,0.0,0.0);
Base::Matrix4D xForm;
xForm.rotLine(line,angle);
newBasis = xForm * (oldBasis);
return newBasis;

viewAxis = TechDrawGeometry::getViewAxis(org,na,true); //default orientation

gp_Dir gxDir = viewAxis.XDirection();
Base::Vector3d origX(gxDir.X(),gxDir.Y(),gxDir.Z());
origX.Normalize();
double dot = fabs(origX.Dot(nx));
double angle = acos(dot);

Base::Vector3d rotAxis = origX.Cross(nx);
if (rotAxis == Direction.getValue()) {
angle *= -1.0;
}
return angle;
}

PyObject *DrawProjGroupItem::getPyObject(void)
Expand Down
10 changes: 6 additions & 4 deletions src/Mod/TechDraw/App/DrawProjGroupItem.h
Expand Up @@ -23,6 +23,8 @@
#ifndef _DrawProjGroupItem_h_
#define _DrawProjGroupItem_h_

#include <gp_Ax2.hxx>

#include <App/DocumentObject.h>
#include <App/PropertyStandard.h>
#include <App/FeaturePython.h>
Expand Down Expand Up @@ -54,7 +56,7 @@ class TechDrawExport DrawProjGroupItem : public TechDraw::DrawViewPart
~DrawProjGroupItem();

App::PropertyEnumeration Type;
App::PropertyVector OrientBasis;
App::PropertyVector RotationVector;

short mustExecute() const;
/** @name methods overide Feature */
Expand All @@ -65,22 +67,22 @@ class TechDrawExport DrawProjGroupItem : public TechDraw::DrawViewPart
//@}

DrawProjGroup* getGroup(void) const;
double getRotateAngle();

/// returns the type name of the ViewProvider
virtual const char* getViewProviderName(void) const {
return "TechDrawGui::ViewProviderProjGroupItem";
}
//return PyObject as DrawProjGroupItemPy
virtual PyObject *getPyObject(void);
//************************************
Base::Vector3d rotated(const double angle) ;

virtual gp_Ax2 getViewAxis(const Base::Vector3d& pt,
const Base::Vector3d& direction,
const bool flip=true) const override;

protected:
/// Called by the container when a Property was changed
void onChanged(const App::Property* prop);

private:
static const char* TypeEnums[];
};
Expand Down
12 changes: 11 additions & 1 deletion src/Mod/TechDraw/App/DrawUtil.cpp
Expand Up @@ -354,7 +354,17 @@ Base::Vector3d DrawUtil::closestBasis(Base::Vector3d v)
Base::Vector3d stdYr(0.0,-1.0,0.0);
Base::Vector3d stdZr(0.0,0.0,-1.0);
double angleX,angleY,angleZ,angleXr,angleYr,angleZr, angleMin;


//first check if already a basis
if (checkParallel(v,stdZ)) {
return v;
} else if (checkParallel(v,stdY)) {
return v;
} else if (checkParallel(v,stdX)) {
return v;
}

//not a basis. find smallest angle with a basis.
angleX = stdX.GetAngle(v);
angleY = stdY.GetAngle(v);
angleZ = stdZ.GetAngle(v);
Expand Down
7 changes: 5 additions & 2 deletions src/Mod/TechDraw/App/DrawViewPart.cpp
Expand Up @@ -156,7 +156,7 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void)
if (shape.IsNull()) {
return new App::DocumentObjectExecReturn("FVP - Linked shape object is empty");
}
// Base::Console().Message("TRACE - DVP::execute() - %s - %s - dir: %s\n",getNameInDocument(), Label.getValue(),DrawUtil::formatVector(Direction.getValue()).c_str());
//Base::Console().Message("TRACE - DVP::execute() - %s - %s - dir: %s\n",getNameInDocument(), Label.getValue(),DrawUtil::formatVector(Direction.getValue()).c_str());


(void) DrawView::execute(); //make sure Scale is up to date
Expand All @@ -173,6 +173,9 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void)

gp_Ax2 viewAxis = getViewAxis(shapeCentroid,Direction.getValue());
geometryObject = buildGeometryObject(mirroredShape,viewAxis);

//Base::Console().Message("TRACE - DVP::execute - u: %s v: %s w: %s\n",
// DrawUtil::formatVector(getUDir()).c_str(), DrawUtil::formatVector(getVDir()).c_str(), DrawUtil::formatVector(getWDir()).c_str());

#if MOD_TECHDRAW_HANDLE_FACES
if (handleFaces()) {
Expand Down Expand Up @@ -523,9 +526,9 @@ gp_Ax2 DrawViewPart::getViewAxis(const Base::Vector3d& pt,
return viewAxis;
}

//this might have to be virtual for dpgi?
void DrawViewPart::saveParamSpace(const Base::Vector3d& direction, const Base::Vector3d& xAxis)
{
//Base::Console().Message("TRACE - DVP::saveParamSpace()\n");
(void)xAxis;
Base::Vector3d origin(0.0,0.0,0.0);
gp_Ax2 viewAxis = getViewAxis(origin,direction);
Expand Down

0 comments on commit 16ce8d4

Please sign in to comment.