Section directions from rotated DPGI's

This commit is contained in:
WandererFan 2016-12-27 19:38:47 -05:00 committed by wmayer
parent 139edb2415
commit 16ce8d40f5
12 changed files with 113 additions and 91 deletions

View File

@ -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()
@ -114,7 +113,6 @@ void Cube::rotateDown()
updateIsoDirs();
updateRotsToConfig(getCurrConfig());
updateIsoRots();
}
void Cube::rotateRight()
@ -128,7 +126,6 @@ void Cube::rotateRight()
updateIsoDirs();
updateRotsToConfig(getCurrConfig());
updateIsoRots();
}
void Cube::rotateLeft()
@ -142,7 +139,6 @@ void Cube::rotateLeft()
updateIsoDirs();
updateRotsToConfig(getCurrConfig());
updateIsoRots();
}
void Cube::spinCCW()
@ -156,7 +152,6 @@ void Cube::spinCCW()
updateIsoDirs();
updateRotsToConfig(getCurrConfig());
updateIsoRots();
}
void Cube::spinCW()
@ -170,7 +165,6 @@ void Cube::spinCW()
updateIsoDirs();
updateRotsToConfig(getCurrConfig());
updateIsoRots();
}
void Cube::updateIsoDirs()
@ -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;
@ -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)
{
@ -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();
@ -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);
@ -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) );
@ -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) );

View File

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

View File

@ -464,7 +464,7 @@ 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
@ -472,7 +472,7 @@ App::DocumentObject * DrawProjGroup::addProjection(const char *viewProjType)
//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
@ -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();
}
}
@ -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;
@ -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());
@ -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

View File

@ -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);
}
@ -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());
@ -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();
viewAxis = TechDrawGeometry::getViewAxis(pt,axis,flip); //default orientation
if (DrawUtil::checkParallel(nx,na)) { //parallel/antiparallel
viewAxis = TechDrawGeometry::getViewAxis(pt,axis,flip); //use default orientation
} else {
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)

View File

@ -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>
@ -54,7 +56,7 @@ public:
~DrawProjGroupItem();
App::PropertyEnumeration Type;
App::PropertyVector OrientBasis;
App::PropertyVector RotationVector;
short mustExecute() const;
/** @name methods overide Feature */
@ -65,6 +67,7 @@ public:
//@}
DrawProjGroup* getGroup(void) const;
double getRotateAngle();
/// returns the type name of the ViewProvider
virtual const char* getViewProviderName(void) const {
@ -72,15 +75,14 @@ public:
}
//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[];
};

View File

@ -355,6 +355,16 @@ Base::Vector3d DrawUtil::closestBasis(Base::Vector3d v)
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);

View File

@ -174,6 +174,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()) {
try {
@ -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);

View File

@ -75,6 +75,7 @@
#include "GeometryObject.h"
#include "EdgeWalker.h"
#include "DrawUtil.h"
#include "DrawProjGroupItem.h"
#include "DrawProjectSplit.h"
#include "DrawViewSection.h"
@ -452,34 +453,43 @@ bool DrawViewSection::isReallyInBox (const Base::Vector3d v, const Base::BoundBo
}
//! 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 DrawViewSection::getSectionVector (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;
double adjustAngle = 0.0;
if (getBaseDPGI() != nullptr) {
adjustAngle = getBaseDPGI()->getRotateAngle();
}
Base::Vector3d view = getBaseDVP()->Direction.getValue();
view.Normalize();
Base::Vector3d left = view.Cross(stdZ);
left.Normalize(); //redundent?
Base::Vector3d down = view.Cross(left);
down.Normalize(); //redundent?
left.Normalize();
Base::Vector3d up = view.Cross(left);
up.Normalize();
double dot = view.Dot(stdZ);
if (sectionName == "Up") {
result = down;
if (DrawUtil::fpCompare(fabs(dot),1.0)) {
result = up;
if (DrawUtil::fpCompare(dot,1.0)) { //view = stdZ
result = (-1.0 * stdY);
} else if (DrawUtil::fpCompare(dot,-1.0)) { //view = -stdZ
result = stdY;
}
} else if (sectionName == "Down") {
result = down * -1.0;
if (DrawUtil::fpCompare(fabs(dot),1.0)) {
result = up * -1.0;
if (DrawUtil::fpCompare(dot,1.0)) { //view = stdZ
result = stdY;
} else if (DrawUtil::fpCompare(dot, -1.0)) { //view = -stdZ
result = (-1.0 * stdY);
}
} else if (sectionName == "Left") {
result = left * -1.0;
if (DrawUtil::fpCompare(fabs(dot),1.0)) {
if (DrawUtil::fpCompare(fabs(dot),1.0)) { //view = +/- stdZ
result = stdX;
}
} else if (sectionName == "Right") {
@ -491,8 +501,28 @@ Base::Vector3d DrawViewSection::getSectionVector (const Base::Vector3d baseViewD
Base::Console().Log("Error - DVS::getSectionVector - bad sectionName: %s\n",sectionName.c_str());
result = stdZ;
}
Base::Vector3d adjResult = DrawUtil::vecRotate(result,adjustAngle,view);
return adjResult;
}
return result;
TechDraw::DrawViewPart* DrawViewSection::getBaseDVP()
{
TechDraw::DrawViewPart* baseDVP = nullptr;
App::DocumentObject* base = BaseView.getValue();
if (base->getTypeId().isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
baseDVP = static_cast<TechDraw::DrawViewPart*>(base);
}
return baseDVP;
}
TechDraw::DrawProjGroupItem* DrawViewSection::getBaseDPGI()
{
TechDraw::DrawProjGroupItem* baseDPGI = nullptr;
App::DocumentObject* base = BaseView.getValue();
if (base->getTypeId().isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId())) {
baseDPGI = static_cast<TechDraw::DrawProjGroupItem*>(base);
}
return baseDPGI;
}
void DrawViewSection::getParameters()

View File

@ -44,6 +44,7 @@ class Face;
namespace TechDraw
{
class DrawProjGroupItem;
/** Base class of all View Features in the drawing module
@ -84,7 +85,9 @@ public:
public:
std::vector<TechDrawGeometry::Face*> getFaceGeometry();
static Base::Vector3d getSectionVector (const Base::Vector3d baseViewDir, const std::string sectionName);
Base::Vector3d getSectionVector (const std::string sectionName);
TechDraw::DrawViewPart* getBaseDVP();
TechDraw::DrawProjGroupItem* getBaseDPGI();
static const char* SectionDirEnums[];

View File

@ -178,8 +178,9 @@ void TaskProjGroup::on3DClicked(void)
{
std::pair<Base::Vector3d,Base::Vector3d> dir3D = get3DViewDir();
Base::Vector3d dir = dir3D.first;
dir = DrawUtil::closestBasis(dir);
Base::Vector3d up = dir3D.second;
up = DrawUtil::closestBasis(up);
TechDraw::DrawProjGroupItem* front = multiView->getProjItem("Front");
if (front) { //why "if front"???
multiView->setTable(dir,up);

View File

@ -312,7 +312,7 @@
<bool>true</bool>
</property>
<property name="toolTip">
<string>Set Primary Direction to match 3D</string>
<string>Try to match Primary Direction to 3D view</string>
</property>
<property name="text">
<string>Match 3D</string>

View File

@ -121,20 +121,19 @@ void TaskSectionView::resetValues()
bool TaskSectionView::calcValues()
{
bool result = true;
Base::Vector3d view = m_base->Direction.getValue();
if (ui->pb_Up->isChecked()) {
sectionDir = "Up";
sectionProjDir = DrawViewSection::getSectionVector(view,sectionDir);
sectionProjDir = m_section->getSectionVector(sectionDir);
} else if (ui->pb_Down->isChecked()) {
sectionDir = "Down";
sectionProjDir = DrawViewSection::getSectionVector(view,sectionDir);
sectionProjDir = m_section->getSectionVector(sectionDir);
} else if (ui->pb_Left->isChecked()) {
sectionDir = "Left";
sectionProjDir = DrawViewSection::getSectionVector(view,sectionDir);
sectionProjDir = m_section->getSectionVector(sectionDir);
} else if (ui->pb_Right->isChecked()) {
sectionDir = "Right";
sectionProjDir = DrawViewSection::getSectionVector(view,sectionDir);
sectionProjDir = m_section->getSectionVector(sectionDir);
} else {
Base::Console().Message("Select a direction\n");
result = false;