Skip to content

Commit

Permalink
Working revolving part DPG
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan authored and wwmayer committed Dec 29, 2016
1 parent 90935d0 commit 139edb2
Show file tree
Hide file tree
Showing 9 changed files with 400 additions and 420 deletions.
331 changes: 228 additions & 103 deletions src/Mod/TechDraw/App/Cube.cpp

Large diffs are not rendered by default.

243 changes: 122 additions & 121 deletions src/Mod/TechDraw/App/DrawProjGroup.cpp

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/Mod/TechDraw/App/DrawProjGroup.h
Expand Up @@ -127,7 +127,9 @@ class TechDrawExport DrawProjGroup : public TechDraw::DrawViewCollection
void spinCCW(void);

void setTable(Base::Vector3d dir, Base::Vector3d rot);
void setConfig(std::string cfg);
void resetTable(void);
void dumpISO(char * title);

protected:
void onChanged(const App::Property* prop);
Expand Down
42 changes: 1 addition & 41 deletions src/Mod/TechDraw/App/DrawProjGroupItem.cpp
Expand Up @@ -87,25 +87,6 @@ short DrawProjGroupItem::mustExecute() const

void DrawProjGroupItem::onChanged(const App::Property *prop)
{
// //TODO: too many executes!
// //TODO: Should we allow changes to the Type here? Seems that should be handled through DrawProjGroup
// if (!isRestoring()) {
//// //Base::Console().Message("TRACE - DPGI::onChanged(%s) - %s/%s\n",prop->getName(),getNameInDocument(),Label.getValue());
// if (prop == &Type && Type.isTouched()) {
//// //Base::Console().Message("TRACE - DPGI::onChanged(%s) - Type: %s\n",prop->getName(),Type.getValueAsString());
//// execute();
// } else if (prop == &Direction) {
// if (getGroup() != nullptr) {
// OrientBasis.setValue(getGroup()->getXAxisDir(Type.getValueAsString()));
// Base::Console().Message("TRACE - DPGI::onChanged(%s) - Direction: %s Orient: %s\n",
// prop->getName(),DrawUtil::formatVector(Direction.getValue()).c_str(),
// DrawUtil::formatVector(OrientBasis.getValue()).c_str());
// }
// }
//// execute();
//// } //else if (prop == &OrientBasis) { //don't want to do twice though!
// }

TechDraw::DrawViewPart::onChanged(prop);

}
Expand Down Expand Up @@ -139,53 +120,32 @@ gp_Ax2 DrawProjGroupItem::getViewAxis(const Base::Vector3d& pt,
const Base::Vector3d& axis,
const bool flip) const
{
// Base::Console().Message("TRACE - DPGI::getViewAxis - %s/%s - Type: %s\n",getNameInDocument(),Label.getValue(),Type.getValueAsString());
gp_Ax2 viewAxis;
Base::Vector3d x = OrientBasis.getValue();
Base::Vector3d nx = x;
x.Normalize();
Base::Vector3d na = axis;
na.Normalize();
// Base::Console().Message("TRACE - DPGI::getViewAxis - axis: %s orient: %s\n",
// DrawUtil::formatVector(axis).c_str(),DrawUtil::formatVector(x).c_str());

if (DrawUtil::checkParallel(nx,na)) { //parallel/antiparallel
// Base::Console().Message("TRACE - DPGI::getViewAxis - parallel flip: %d\n",flip);
viewAxis = TechDrawGeometry::getViewAxis(pt,axis,flip); //use default orientation
} else {
//Base::Console().Message("TRACE - DPGI::getViewAxis - skew flip: %d\n",flip);
// if (Type.isValue("Right") || Type.isValue("Left")) { //no difference with incorrect initial axis
// viewAxis = TechDrawGeometry::getViewAxis(pt,axis,x,!flip); //no difference with correct initial axis!!
// } else {
viewAxis = TechDrawGeometry::getViewAxis(pt,axis,x,flip);
// }
viewAxis = TechDrawGeometry::getViewAxis(pt,axis,x,flip);
}

//Base::Console().Message("TRACE - DPGI::getViewAxis exits\n");
return viewAxis;
}

//! rotate OrientBasis by angle radians around view Direction
Base::Vector3d DrawProjGroupItem::rotated(const double angle)
{
Base::Console().Message("TRACE - DPGI::rotated - %s/%s angle: %.3f\n",Label.getValue(),Type.getValueAsString(),angle);
Base::Vector3d line = Direction.getValue();
Base::Vector3d oldBasis = OrientBasis.getValue();
Base::Vector3d newBasis;
Base::Vector3d org(0.0,0.0,0.0);
Base::Matrix4D xForm;
xForm.rotLine(line,angle);
newBasis = xForm * (oldBasis);
Base::Console().Message("TRACE - DPGI::rotated - line: %s old: %s new: %s\n",
DrawUtil::formatVector(line).c_str(),
DrawUtil::formatVector(oldBasis).c_str(),
DrawUtil::formatVector(newBasis).c_str());
// if (getGroup() != nullptr) {
// if (getGroup()->getException(Type.getValueAsString())) {
// newBasis = newBasis * -1.0;
// Base::Console().Message("TRACE - DPGI::rotated - EXCEPTION\n");
// }
// }
return newBasis;
}

Expand Down
43 changes: 43 additions & 0 deletions src/Mod/TechDraw/App/DrawUtil.cpp
Expand Up @@ -344,6 +344,49 @@ Base::Vector3d DrawUtil::vecRotate(Base::Vector3d vec,
return result;
}

Base::Vector3d DrawUtil::closestBasis(Base::Vector3d v)
{
Base::Vector3d result(0.0,-1,0);
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 stdXr(-1.0,0.0,0.0);
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;

angleX = stdX.GetAngle(v);
angleY = stdY.GetAngle(v);
angleZ = stdZ.GetAngle(v);
angleXr = stdXr.GetAngle(v);
angleYr = stdYr.GetAngle(v);
angleZr = stdZr.GetAngle(v);

angleMin = angleX;
result = stdX;
if (angleY < angleMin) {
angleMin = angleY;
result = stdY;
}
if (angleZ < angleMin) {
angleMin = angleZ;
result = stdZ;
}
if (angleXr < angleMin) {
angleMin = angleXr;
result = stdXr;
}
if (angleYr < angleMin) {
angleMin = angleYr;
result = stdYr;
}
if (angleZr < angleMin) {
angleMin = angleZr;
result = stdZr;
}
return result;
}

//based on Function provided by Joe Dowsett, 2014
double DrawUtil::sensibleScale(double working_scale)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/TechDraw/App/DrawUtil.h
Expand Up @@ -67,6 +67,8 @@ class TechDrawExport DrawUtil {
double angle,
Base::Vector3d axis,
Base::Vector3d org = Base::Vector3d(0.0,0.0,0.0));
static Base::Vector3d closestBasis(Base::Vector3d v);



//debugging routines
Expand Down
75 changes: 0 additions & 75 deletions src/Mod/TechDraw/App/dirs.cpp

This file was deleted.

73 changes: 0 additions & 73 deletions src/Mod/TechDraw/App/rots.cpp

This file was deleted.

9 changes: 2 additions & 7 deletions src/Mod/TechDraw/Gui/TaskProjGroup.cpp
Expand Up @@ -179,12 +179,9 @@ void TaskProjGroup::on3DClicked(void)
std::pair<Base::Vector3d,Base::Vector3d> dir3D = get3DViewDir();
Base::Vector3d dir = dir3D.first;
Base::Vector3d up = dir3D.second;
Base::Console().Message("TRACE - TPG::on3DClicked - dir: %s up: %s\n",
DrawUtil::formatVector(dir).c_str(),DrawUtil::formatVector(up).c_str());

TechDraw::DrawProjGroupItem* front = multiView->getProjItem("Front");
if (front) { //why "if front"???
Base::Console().Message("TRACE - TPG::on3DClicked - front found\n");
multiView->setTable(dir,up);
setUiPrimary();
Gui::Command::updateActive();
Expand Down Expand Up @@ -438,11 +435,9 @@ std::pair<Base::Vector3d,Base::Vector3d> TaskProjGroup::get3DViewDir()

viewDir = Base::Vector3d(dvec[0], dvec[1], dvec[2]);
viewUp = Base::Vector3d(upvec[0],upvec[1],upvec[2]);
Base::Console().Message("TRACE - TPG::get3dview - Viewer dir: %s Viewer Up: %s \n",
DrawUtil::formatVector(viewDir).c_str(),DrawUtil::formatVector(viewUp).c_str());
viewDir *= -1.0; //Inventor dir is opposite TD dir, Inventor up is same as TD up
Base::Console().Message("TRACE - TPG::get3dview - (adjusted) Viewer dir: %s Viewer Up: %s \n",
DrawUtil::formatVector(viewDir).c_str(),DrawUtil::formatVector(viewUp).c_str());
viewDir = DrawUtil::closestBasis(viewDir);
viewUp = DrawUtil::closestBasis(viewUp);
result = std::make_pair(viewDir,viewUp);
return result;
}
Expand Down

0 comments on commit 139edb2

Please sign in to comment.