getViewAxis -> DVP virtual method

This commit is contained in:
WandererFan
2016-12-15 09:01:45 -05:00
committed by wmayer
parent 3d824dd8dc
commit d14cfa415f
11 changed files with 861 additions and 698 deletions

View File

@@ -26,9 +26,12 @@
# include <sstream>
#endif
#include <gp_Ax2.hxx>
#include <Base/Console.h>
#include <Base/Writer.h>
#include "GeometryObject.h"
#include "DrawUtil.h"
#include "DrawProjGroup.h"
#include "DrawProjGroupItem.h"
@@ -56,28 +59,52 @@ 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. ");
//projection group controls these
Direction.setStatus(App::Property::ReadOnly,true);
//OrientBasis.setStatus(App::Property::ReadOnly,true);
Scale.setStatus(App::Property::ReadOnly,true);
ScaleType.setStatus(App::Property::ReadOnly,true);
}
short DrawProjGroupItem::mustExecute() const
{
if (Type.isTouched())
return 1;
short result = 0;
if (!isRestoring()) {
result = (Direction.isTouched() ||
OrientBasis.isTouched() ||
Source.isTouched() ||
Scale.isTouched() ||
ScaleType.isTouched());
}
if (result) {
return result;
}
return TechDraw::DrawViewPart::mustExecute();
}
void DrawProjGroupItem::onChanged(const App::Property *prop)
{
//TODO: Should we allow changes to the Type here? Seems that should be handled through DrawProjGroup
if (prop == &Type && Type.isTouched()) {
if (!isRestoring()) {
execute();
}
}
// //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);
@@ -96,7 +123,7 @@ void DrawProjGroupItem::onDocumentRestored()
}
}
DrawProjGroup* DrawProjGroupItem::getGroup()
DrawProjGroup* DrawProjGroupItem::getGroup() const
{
DrawProjGroup* result = nullptr;
std::vector<App::DocumentObject*> parent = getInList();
@@ -108,6 +135,71 @@ DrawProjGroup* DrawProjGroupItem::getGroup()
}
return result;
}
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);
viewAxis = TechDrawGeometry::getViewAxis(pt,axis,x,flip);
}
// if (Type.isValue("Front")) {
// viewAxis = TechDrawGeometry::getViewAxis(pt,axis,flip); //show front in upright stance
// } else {
// const char *viewProjType = Type.getValueAsString();
// DrawProjGroup* grp = getGroup();
// if (grp == nullptr) {
// Base::Console().Message("TRACE - DPGI::getViewAxis - NO GROUP!!!\n");
// return TechDrawGeometry::getViewAxis(pt,axis,flip); //too early
// } else {
// getGroup()->dumpViewDir("viewDir map"); //<<<<
// getGroup()->dumpXAxisDir("xAxisDir map");
// Base::Vector3d x = getGroup()->getXAxisDir(viewProjType);
// Base::Vector3d x = OrientBasis.getValue();
// 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;
}
PyObject *DrawProjGroupItem::getPyObject(void)
{