Skip to content

Commit

Permalink
Fix Section arrows,xDir,label
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan committed Sep 1, 2016
1 parent b47eff7 commit 34644e9
Show file tree
Hide file tree
Showing 12 changed files with 179 additions and 146 deletions.
26 changes: 19 additions & 7 deletions src/Mod/TechDraw/App/DrawView.cpp
Expand Up @@ -79,6 +79,7 @@ DrawView::~DrawView()

App::DocumentObjectExecReturn *DrawView::execute(void)
{
Base::Console().Message("TRACE - DV::execute\n");
TechDraw::DrawPage *page = findParentPage();
if(page) {
if (ScaleType.isValue("Document")) {
Expand All @@ -101,9 +102,7 @@ App::DocumentObjectExecReturn *DrawView::execute(void)
void DrawView::onChanged(const App::Property* prop)
{
if (!isRestoring()) {
if (prop == &Scale) {
execute();
} else if (prop == &ScaleType) {
if (prop == &ScaleType) {
if (ScaleType.isValue("Document")) {
Scale.setStatus(App::Property::ReadOnly,true);
App::GetApplication().signalChangePropertyEditor(Scale);
Expand All @@ -114,21 +113,34 @@ void DrawView::onChanged(const App::Property* prop)
Scale.setStatus(App::Property::ReadOnly,true);
App::GetApplication().signalChangePropertyEditor(Scale);
}
execute();
} else if (prop == &X ||
prop == &Y) {
if (isMouseMove()) {
setAutoPos(false); //should only be for manual changes? not programmatic changes?
}
execute();
} else if (prop == &Rotation) {
execute();
}
}

App::DocumentObject::onChanged(prop);
}

short DrawView::mustExecute() const
{
short result = 0;
if (!isRestoring()) {
result = (X.isTouched() ||
Y.isTouched() ||
Rotation.isTouched() ||
Scale.isTouched() ||
ScaleType.isTouched() );
}
if (result) {
return result;
} else {
return App::DocumentObject::mustExecute();
}
}

////you must override this in derived class
QRectF DrawView::getRect() const
{
Expand Down
1 change: 1 addition & 0 deletions src/Mod/TechDraw/App/DrawView.h
Expand Up @@ -58,6 +58,7 @@ class TechDrawExport DrawView : public App::DocumentObject
/// recalculate the Feature
virtual App::DocumentObjectExecReturn *execute(void);
virtual void onDocumentRestored();
virtual short mustExecute() const;
//@}

bool isInClip();
Expand Down
74 changes: 52 additions & 22 deletions src/Mod/TechDraw/App/DrawViewPart.cpp
Expand Up @@ -118,7 +118,7 @@ DrawViewPart::DrawViewPart(void) : geometryObject(0)

ADD_PROPERTY_TYPE(ShowSectionLine ,(true) ,lgroup,App::Prop_None,"Show/hide section line if applicable");
ADD_PROPERTY_TYPE(HorizSectionLine ,(true) ,lgroup,App::Prop_None,"Section line is horizontal");
ADD_PROPERTY_TYPE(ArrowUpSection ,(true) ,lgroup,App::Prop_None,"Section line arrows point up");
ADD_PROPERTY_TYPE(ArrowUpSection ,(false) ,lgroup,App::Prop_None,"Section line arrows point up");
ADD_PROPERTY_TYPE(SymbolSection,("A") ,lgroup,App::Prop_None,"Section identifier");


Expand All @@ -133,6 +133,7 @@ DrawViewPart::~DrawViewPart()

App::DocumentObjectExecReturn *DrawViewPart::execute(void)
{
//Base::Console().Message("TRACE - DVP::execute: %s\n",getNameInDocument());
App::DocumentObject *link = Source.getValue();
if (!link) {
return new App::DocumentObjectExecReturn("FVP - No Source object linked");
Expand Down Expand Up @@ -175,7 +176,7 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void)
}

// There is a guaranteed change so check any references linked to this and touch
// We need to update all views pointing at this (ProjectionGroup, ClipGroup, etc)
// We need to update all views pointing at this (ProjectionGroup, ClipGroup, Section, etc)
std::vector<App::DocumentObject*> parent = getInList();
for (std::vector<App::DocumentObject*>::iterator it = parent.begin(); it != parent.end(); ++it) {
if ((*it)->getTypeId().isDerivedFrom(DrawView::getClassTypeId())) {
Expand All @@ -188,18 +189,33 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void)

short DrawViewPart::mustExecute() const
{
short result = (Direction.isTouched() ||
XAxisDirection.isTouched() ||
Source.isTouched() ||
Scale.isTouched() ||
ScaleType.isTouched() ||
ShowHiddenLines.isTouched() ||
ShowSmoothLines.isTouched() ||
ShowSeamLines.isTouched() ||
LineWidth.isTouched() ||
Tolerance.isTouched() ||
HiddenWidth.isTouched());
return result;
short result = 0;
if (!isRestoring()) {
result = (Direction.isTouched() ||
XAxisDirection.isTouched() ||
Source.isTouched() ||
Scale.isTouched() ||
ScaleType.isTouched() ||
Tolerance.isTouched() ||
ShowHiddenLines.isTouched() ||
ShowSmoothLines.isTouched() ||
ShowSeamLines.isTouched() ||
LineWidth.isTouched() ||
HiddenWidth.isTouched() ||
ShowCenters.isTouched() ||
CenterScale.isTouched() ||
ShowSectionLine.isTouched() ||
HorizSectionLine.isTouched() ||
ArrowUpSection.isTouched() ||
SymbolSection.isTouched() ||
HorizCenterLine.isTouched() ||
VertCenterLine.isTouched());
}

if (result) {
return result;
}
return TechDraw::DrawView::mustExecute();
}

void DrawViewPart::onChanged(const App::Property* prop)
Expand Down Expand Up @@ -545,22 +561,36 @@ Base::Vector3d DrawViewPart::getValidXDir() const
{
Base::Vector3d X(1.0,0.0,0.0);
Base::Vector3d Y(0.0,1.0,0.0);
Base::Vector3d Z(0.0,0.0,1.0);
Base::Vector3d xDir = XAxisDirection.getValue();
if (xDir.Length() < Precision::Confusion()) {
Base::Console().Warning("XAxisDirection has zero length - using (1,0,0)\n");
xDir = X;
}
double xLength = xDir.Length();
xDir.Normalize();
Base::Vector3d viewDir = Direction.getValue();
if ((xDir - viewDir).Length() < Precision::Confusion()) {
if (xDir == X) {
xDir = Y;
}else{
xDir = X;
viewDir.Normalize();
Base::Vector3d randomDir(0.0,0.0,0.0);
if (xDir == viewDir) {
randomDir = Y;
if (randomDir == xDir) {
randomDir = X;
}
xDir = randomDir;
Base::Console().Warning("XAxisDirection cannot equal +/- Direction - using (%.3f,%.3f%.3f)\n",
xDir.x,xDir.y,xDir.z);
} else if (xDir == (-1.0 * viewDir)) {
randomDir = Y;
if ((xDir == randomDir) ||
(xDir == (-1.0 * randomDir))) {
randomDir = X;
}
Base::Console().Warning("XAxisDirection cannot equal Direction - using (%.3f,%.3f%.3f)\n",
xDir.x,xDir.y,xDir.z);
xDir = randomDir;
Base::Console().Warning("XAxisDirection cannot equal +/- Direction - using (%.3f,%.3f%.3f)\n",
xDir.x,xDir.y,xDir.z);
}
return xDir;
return xLength * xDir;
}

void DrawViewPart::saveParamSpace(const Base::Vector3d& direction,
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/TechDraw/App/DrawViewPart.h
Expand Up @@ -107,7 +107,7 @@ class TechDrawExport DrawViewPart : public DrawView
Base::Vector3d getValidXDir() const;
Base::Vector3d projectPoint(const Base::Vector3d& pt) const;

short mustExecute() const;
virtual short mustExecute() const;

/** @name methods overide Feature */
//@{
Expand Down
76 changes: 30 additions & 46 deletions src/Mod/TechDraw/App/DrawViewSection.cpp
Expand Up @@ -52,6 +52,7 @@

#endif

#include <chrono>

#include <App/Application.h>
#include <App/Material.h>
Expand Down Expand Up @@ -101,18 +102,29 @@ DrawViewSection::~DrawViewSection()

short DrawViewSection::mustExecute() const
{
// If Tolerance Property is touched
if(SectionNormal.isTouched() ||
SectionOrigin.isTouched() ||
ShowCutSurface.isTouched() ||
CutSurfaceColor.isTouched() )
return 1;

short result = 0;
if (!isRestoring()) {
result = (Scale.isTouched() ||
ScaleType.isTouched() ||
BaseView.isTouched() ||
SectionNormal.isTouched() ||
Direction.isTouched() ||
SectionOrigin.isTouched() ||
XAxisDirection.isTouched() ||
ShowCutSurface.isTouched() ||
CutSurfaceColor.isTouched() );
}
if (result) {
return result;
}
return TechDraw::DrawViewPart::mustExecute();
}

App::DocumentObjectExecReturn *DrawViewSection::execute(void)
{
//Base::Console().Message("TRACE - DVS::execute: %s\n",getNameInDocument());
//auto system_start = chrono::high_resolution_clock::now();

App::DocumentObject* link = Source.getValue();
App::DocumentObject* base = BaseView.getValue();
if (!link || !base) {
Expand All @@ -126,7 +138,7 @@ App::DocumentObjectExecReturn *DrawViewSection::execute(void)
return new App::DocumentObjectExecReturn("BaseView object is not a DrawViewPart object");

const Part::TopoShape &partTopo = static_cast<Part::Feature*>(link)->Shape.getShape();
const TechDraw::DrawViewPart* dvp = static_cast<TechDraw::DrawViewPart*>(base);
//const TechDraw::DrawViewPart* dvp = static_cast<TechDraw::DrawViewPart*>(base);

if (partTopo.getShape().IsNull())
return new App::DocumentObjectExecReturn("Linked shape object is empty");
Expand All @@ -142,45 +154,19 @@ App::DocumentObjectExecReturn *DrawViewSection::execute(void)

Base::Vector3d tmp1 = SectionOrigin.getValue();
Base::Vector3d plnPnt(tmp1.x, tmp1.y, tmp1.z);
//Base::Vector3d tmp2 = SectionNormal.getValue();
Base::Vector3d plnNorm(plnNormal.X(), plnNormal.Y(), plnNormal.Z());

// if(!bb.IsCutPlane(plnPnt, plnNorm)) { //this test doesn't work if plane is coincident with bb!
if(!isReallyInBox(plnPnt, bb)) {
Base::Console().Warning("DVS: Section Plane doesn't intersect part in %s\n",getNameInDocument());
Base::Console().Warning("DVS: Using center of bounding box.\n");
plnPnt = bb.GetCenter();
SectionOrigin.setValue(plnPnt);
//SectionOrigin.setValue(plnPnt);
}

// Gather the corner points of bbox
std::vector<Base::Vector3d> pnts;
pnts.push_back(Base::Vector3d(bb.MinX,bb.MinY,bb.MinZ));
pnts.push_back(Base::Vector3d(bb.MaxX,bb.MinY,bb.MinZ));
pnts.push_back(Base::Vector3d(bb.MinX,bb.MaxY,bb.MinZ));
pnts.push_back(Base::Vector3d(bb.MaxX,bb.MaxY,bb.MinZ));
pnts.push_back(Base::Vector3d(bb.MinX,bb.MinY,bb.MaxZ));
pnts.push_back(Base::Vector3d(bb.MaxX,bb.MinY,bb.MaxZ));
pnts.push_back(Base::Vector3d(bb.MinX,bb.MaxY,bb.MaxZ));
pnts.push_back(Base::Vector3d(bb.MaxX,bb.MaxY,bb.MaxZ));

double uMax = 0, vMax = 0, wMax = 0., dMax = 0;
for(std::vector<Base::Vector3d>::const_iterator it = pnts.begin(); it != pnts.end(); ++it) {
// Project each bounding box point onto projection plane and find largest u,v,w values
Base::Vector3d pnt = (*it);
pnt.ProjectToPlane(plnPnt, plnNorm);
uMax = std::max(uMax, std::abs(plnPnt.x - pnt.x)); //one will be zero
vMax = std::max(vMax, std::abs(plnPnt.y - pnt.y));
wMax = std::max(wMax, std::abs(plnPnt.z - pnt.z));

//dMax is the bounding box point furthest away from plane. used for determining extrusion length
double dist = (*it).DistanceToPlane(plnPnt, plnNorm);
dMax = std::max(dMax, dist);
}
double dMax = bb.CalcDiagonalLength();

//use largest of u,v,w to make cutting face that covers whole shape
double maxParm = std::max(uMax,vMax);
maxParm = std::max(maxParm,wMax);
double maxParm = dMax;
BRepBuilderAPI_MakePolygon mkPoly;
gp_Pnt pn1(origin + xAxis * maxParm + yAxis * maxParm);
gp_Pnt pn2(origin + xAxis * maxParm + yAxis * -maxParm);
Expand Down Expand Up @@ -212,10 +198,11 @@ App::DocumentObjectExecReturn *DrawViewSection::execute(void)

geometryObject->setTolerance(Tolerance.getValue());
geometryObject->setScale(Scale.getValue());
Base::Vector3d validXDir = getValidXDir();
try {
gp_Pnt inputCenter = TechDrawGeometry::findCentroid(rawShape,
Direction.getValue(),
getValidXDir());
validXDir);
TopoDS_Shape mirroredShape = TechDrawGeometry::mirrorShape(rawShape,
inputCenter,
Scale.getValue());
Expand All @@ -239,7 +226,7 @@ App::DocumentObjectExecReturn *DrawViewSection::execute(void)
TopoDS_Face pFace = projectFace(face,
inputCenter,
Direction.getValue(),
getValidXDir());
validXDir);
builder.Add(newFaces,pFace);

}
Expand All @@ -251,14 +238,10 @@ App::DocumentObjectExecReturn *DrawViewSection::execute(void)
std::string(e1->GetMessageString()));
}

std::string symbol = dvp->SymbolSection.getValue();
std::string symbolText = "Section " + symbol + "-" + symbol;
if (symbolText.compare(Label.getValue())) {
Label.setValue(symbolText.c_str());
}

//auto diff = chrono::system_clock::now() - system_start;
//auto dur = chrono::duration_cast<std::chrono::milliseconds>(diff);
//Base::Console().Message("TRACE - DVS::execute - took %.3f millisecs\n",dur.count());

touch();
return DrawView::execute();
}

Expand Down Expand Up @@ -366,6 +349,7 @@ TopoDS_Face DrawViewSection::projectFace(const TopoDS_Shape &face,
}
faceEdges.push_back(edge);
}
//TODO: verify that outline edges aren't required
//if edge is both hard & outline, it will be duplicated? are hard edges enough?
// TopExp_Explorer expl2(outEdges, TopAbs_EDGE);
// for (i = 1 ; expl2.More(); expl2.Next(),i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/TechDraw/App/DrawViewSection.h
Expand Up @@ -61,7 +61,7 @@ class TechDrawExport DrawViewSection : public DrawViewPart
App::PropertyBool ShowCutSurface;
App::PropertyColor CutSurfaceColor;

short mustExecute() const;
virtual short mustExecute() const;
bool isReallyInBox (const Base::Vector3d v, const Base::BoundBox3d bb) const;
/** @name methods overide Feature */
//@{
Expand Down
27 changes: 6 additions & 21 deletions src/Mod/TechDraw/Gui/QGISectionLine.cpp
Expand Up @@ -86,27 +86,12 @@ void QGISectionLine::makeLine()
void QGISectionLine::makeArrows()
{
double arrowRotation = 0.0;
// m_arrowDir.normalize();
// double angle = atan2f(m_arrowDir.y,m_arrowDir.x);
// if (angle < 0.0) {
// angle = 2 * M_PI + angle;
// }

Base::Vector3d up(0,1,0);
Base::Vector3d down(0,-1,0);
Base::Vector3d right(1,0,0);
Base::Vector3d left(-1,0,0);
if (m_arrowDir == up) {
arrowRotation = 270.0;
} else if (m_arrowDir == down) {
arrowRotation = 90.0;
} else if (m_arrowDir == right) {
arrowRotation = 0.0;
} else if (m_arrowDir == left) {
arrowRotation = 180.0;
} else {
Base::Console().Message("Please make feature request for oblique section lines\n");
m_arrowDir.Normalize();
double angle = atan2f(m_arrowDir.y,m_arrowDir.x);
if (angle < 0.0) {
angle = 2 * M_PI + angle;
}
arrowRotation = 360.0 - angle * (180.0/M_PI); //convert to Qt rotation (clockwise degrees)

QPointF extLineStart,extLineEnd;
QPointF offset(m_arrowDir.x,-m_arrowDir.y); //remember Y dir is flipped
Expand All @@ -117,7 +102,7 @@ void QGISectionLine::makeArrows()
m_arrow1->setPos(extLineStart);
//m_arrow1->flip(true);
m_arrow1->draw();
m_arrow1->setRotation(arrowRotation);
m_arrow1->setRotation(arrowRotation); //rotation = 0 ==> -> horizontal, pointing right
m_arrow2->setPos(extLineEnd);
m_arrow2->draw();
m_arrow2->setRotation(arrowRotation);
Expand Down

0 comments on commit 34644e9

Please sign in to comment.