[TD]Transition to on demand page updates ph1

This commit is contained in:
wandererfan
2019-10-21 08:36:50 -04:00
committed by WandererFan
parent 820ad876cb
commit 5bb659e7e2
18 changed files with 344 additions and 226 deletions

View File

@@ -130,6 +130,7 @@ void DrawPage::onChanged(const App::Property* prop)
//would be nice if this message was displayed immediately instead of after the recomputeFeature
Base::Console().Message("Rebuilding Views for: %s/%s\n",getNameInDocument(),Label.getValue());
updateAllViews();
purgeTouched();
}
} else if (prop == &Template) {
if (!isRestoring() &&
@@ -176,6 +177,16 @@ App::DocumentObjectExecReturn *DrawPage::execute(void)
// this is now irrelevant, b/c DP::execute doesn't do anything.
short DrawPage::mustExecute() const
{
short result = 0;
if (!isRestoring()) {
result = (Views.isTouched() ||
Scale.isTouched() ||
ProjectionType.isTouched() ||
Template.isTouched());
if (result) {
return result;
}
}
return App::DocumentObject::mustExecute();
}
@@ -331,17 +342,27 @@ void DrawPage::onDocumentRestored()
App::DocumentObject::onDocumentRestored();
}
void DrawPage::redrawCommand()
{
// Base::Console().Message("DP::redrawCommand()\n");
forceRedraw(true);
updateAllViews();
forceRedraw(false);
}
//should really be called "updateMostViews". can still be problems to due execution order.
void DrawPage::updateAllViews()
{
// Base::Console().Message("DP::updateAllViews()\n");
std::vector<App::DocumentObject*> featViews = getAllViews();
std::vector<App::DocumentObject*>::const_iterator it = featViews.begin();
std::vector<App::DocumentObject*>::iterator it = featViews.begin();
//first, make sure all the Parts have been executed so GeometryObjects exist
for(; it != featViews.end(); ++it) {
TechDraw::DrawViewPart *part = dynamic_cast<TechDraw::DrawViewPart *>(*it);
if (part != nullptr &&
!part->hasGeometry()) {
TechDraw::DrawViewCollection *collect = dynamic_cast<TechDraw::DrawViewCollection*>(*it);
if (part != nullptr) {
part->recomputeFeature();
} else if (collect != nullptr) {
collect->recomputeFeature();
}
}
//second, make sure all the Dimensions have been executed so Measurements have References
@@ -448,6 +469,7 @@ void DrawPage::handleChangedPropertyType(
}
}
//allow/prevent drawing updates for all Pages
bool DrawPage::GlobalUpdateDrawings(void)
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
@@ -456,6 +478,7 @@ bool DrawPage::GlobalUpdateDrawings(void)
return result;
}
//allow/prevent a single page to update despite GlobalUpdateDrawings setting
bool DrawPage::AllowPageOverride(void)
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()

View File

@@ -103,6 +103,7 @@ public:
static bool AllowPageOverride(void);
void forceRedraw(bool b) { m_forceRedraw = b; }
bool forceRedraw(void) { return m_forceRedraw; }
void redrawCommand();
protected:
void onBeforeChange(const App::Property* prop) override;

View File

@@ -74,9 +74,11 @@ DrawProjGroup::DrawProjGroup(void)
ProjectionType.setEnums(ProjectionTypeEnums);
ADD_PROPERTY(ProjectionType, ((long)getDefProjConv()));
ADD_PROPERTY_TYPE(ProjectionType, ((long)getDefProjConv()), group,
App::Prop_None, "First or Third Angle projection");
ADD_PROPERTY_TYPE(AutoDistribute ,(autoDist),agroup,App::Prop_None,"Distribute Views Automatically or Manually");
ADD_PROPERTY_TYPE(AutoDistribute ,(autoDist),agroup,
App::Prop_None,"Distribute Views Automatically or Manually");
ADD_PROPERTY_TYPE(spacingX, (15), agroup, App::Prop_None, "Horizontal spacing between views");
ADD_PROPERTY_TYPE(spacingY, (15), agroup, App::Prop_None, "Vertical spacing between views");
Rotation.setStatus(App::Property::Hidden,true); //DPG does not rotate
@@ -108,8 +110,13 @@ void DrawProjGroup::onChanged(const App::Property* prop)
// }
}
if (prop == &Scale) {
updateChildren();
updateChildrenScale();
}
if (prop == &ProjectionType) {
updateChildrenEnforce();
}
if (prop == &Source) {
updateChildrenSource();
}
@@ -168,17 +175,8 @@ App::DocumentObjectExecReturn *DrawProjGroup::execute(void)
//no anchor yet. nothing to do.
return DrawViewCollection::execute();
}
// for (auto& v: Views.getValues()) { //is this needed here? Up to DPGI to keep up to date.
// v->recomputeFeature();
// }
for (auto& item: getViewsAsDPGI()) {
bool touched = item->isTouched();
item->autoPosition();
if(!touched)
item->purgeTouched();
}
autoPositionChildren();
return DrawViewCollection::execute();
}
@@ -853,16 +851,42 @@ void DrawProjGroup::makeViewBbs(DrawProjGroupItem *viewPtrs[10],
}
}
/*!
* tell children DPGIs that parent DPG has changed Scale
*/
void DrawProjGroup::updateChildren(void)
void DrawProjGroup::recomputeChildren(void)
{
// Base::Console().Message("DPG::recomputeChildren()\n");
for( const auto it : Views.getValues() ) {
auto view( dynamic_cast<DrawProjGroupItem *>(it) );
if (view == nullptr) {
throw Base::TypeError("Error: projection in DPG list is not a DPGI!");
} else {
view->recomputeFeature();
}
}
}
void DrawProjGroup::autoPositionChildren(void)
{
for( const auto it : Views.getValues() ) {
auto view( dynamic_cast<DrawProjGroupItem *>(it) );
if (view == nullptr) {
throw Base::TypeError("Error: projection in DPG list is not a DPGI!");
} else {
view->autoPosition();
}
}
}
/*!
* tell children DPGIs that parent DPG has changed Scale
*/
void DrawProjGroup::updateChildrenScale(void)
{
// Base::Console().Message("DPG::updateChildrenScale\n");
for( const auto it : Views.getValues() ) {
auto view( dynamic_cast<DrawProjGroupItem *>(it) );
if (view == nullptr) {
//if an element in Views is not a DPGI, something really bad has happened somewhere
Base::Console().Log("PROBLEM - DPG::updateChildren - non DPGI entry in Views! %s\n",
Base::Console().Log("PROBLEM - DPG::updateChildrenScale - non DPGI entry in Views! %s\n",
getNameInDocument());
throw Base::TypeError("Error: projection in DPG list is not a DPGI!");
} else if(view->Scale.getValue()!=Scale.getValue()) {
@@ -906,6 +930,21 @@ void DrawProjGroup::updateChildrenLock(void)
}
}
void DrawProjGroup::updateChildrenEnforce(void)
{
for( const auto it : Views.getValues() ) {
auto view( dynamic_cast<DrawProjGroupItem *>(it) );
if (view == nullptr) {
//if an element in Views is not a DPGI, something really bad has happened somewhere
Base::Console().Log("PROBLEM - DPG::updateChildrenEnforce - non DPGI entry in Views! %s\n",
getNameInDocument());
throw Base::TypeError("Error: projection in DPG list is not a DPGI!");
} else {
view->enforceRecompute();
}
}
}
/*!
* check if ProjectionGroup fits on Page
*/

View File

@@ -127,6 +127,11 @@ public:
void dumpISO(char * title);
std::vector<DrawProjGroupItem*> getViewsAsDPGI();
void recomputeChildren(void);
void updateChildrenScale(void);
void autoPositionChildren(void);
void updateChildrenEnforce(void);
protected:
void onChanged(const App::Property* prop) override;
@@ -158,7 +163,7 @@ protected:
/// Returns pointer to our page, or NULL if it couldn't be located
TechDraw::DrawPage * getPage(void) const;
void updateChildren(void);
void updateChildrenSource(void);
void updateChildrenLock(void);
int getViewIndex(const char *viewTypeCStr) const;

View File

@@ -133,24 +133,20 @@ bool DrawProjGroupItem::showLock(void) const
App::DocumentObjectExecReturn *DrawProjGroupItem::execute(void)
{
// Base::Console().Message("DPGI::execute(%s)\n",Label.getValue());
if (DrawUtil::checkParallel(Direction.getValue(),
RotationVector.getValue())) {
return new App::DocumentObjectExecReturn("DPGI: Direction and RotationVector are parallel");
}
App::DocumentObjectExecReturn * ret = DrawViewPart::execute();
if (ret != nullptr) {
return ret;
} else {
autoPosition();
delete ret;
}
return App::DocumentObject::StdReturn;
App::DocumentObjectExecReturn* ret = DrawViewPart::execute();
autoPosition();
return ret;
}
void DrawProjGroupItem::autoPosition()
{
// Base::Console().Message("DPGI::autoPosition(%s)\n",getNameInDocument());
// Base::Console().Message("DPGI::autoPosition(%s)\n",Label.getValue());
auto pgroup = getPGroup();
Base::Vector3d newPos;
if (pgroup != nullptr) {

View File

@@ -144,7 +144,8 @@ void DrawViewDetail::onChanged(const App::Property* prop)
if ((prop == &Reference) ||
(prop == &Radius) ||
(prop == &AnchorPoint)) {
BaseView.getValue()->touch(); //hack. sb "update graphics"
// BaseView.getValue()->touch(); //hack. sb "update graphics"
enforceRecompute();
}
}

View File

@@ -93,22 +93,22 @@ enum RefType{
DrawViewDimension::DrawViewDimension(void)
{
ADD_PROPERTY_TYPE(References2D,(0,0),"",(App::PropertyType)(App::Prop_None),"Projected Geometry References");
ADD_PROPERTY_TYPE(References2D,(0,0),"",(App::Prop_None),"Projected Geometry References");
References2D.setScope(App::LinkScope::Global);
ADD_PROPERTY_TYPE(References3D,(0,0),"",(App::PropertyType)(App::Prop_None),"3D Geometry References");
ADD_PROPERTY_TYPE(References3D,(0,0),"",(App::Prop_None),"3D Geometry References");
References3D.setScope(App::LinkScope::Global);
ADD_PROPERTY_TYPE(FormatSpec,("") , "Format",(App::PropertyType)(App::Prop_None),"Dimension Format");
ADD_PROPERTY_TYPE(Arbitrary,(false) ,"Format",(App::PropertyType)(App::Prop_None),"Value overridden by user");
ADD_PROPERTY_TYPE(FormatSpec,("") , "Format", App::Prop_Output,"Dimension Format");
ADD_PROPERTY_TYPE(Arbitrary,(false) ,"Format", App::Prop_Output,"Value overridden by user");
Type.setEnums(TypeEnums); //dimension type: length, radius etc
ADD_PROPERTY(Type,((long)0));
MeasureType.setEnums(MeasureTypeEnums);
ADD_PROPERTY(MeasureType, ((long)1)); //Projected (or True) measurement
ADD_PROPERTY_TYPE(TheoreticalExact,(false),"",(App::PropertyType)(App::Prop_None),"Set for theoretical exact (basic) dimension");
ADD_PROPERTY_TYPE(OverTolerance ,(0.0),"",App::Prop_None,"+ Tolerance value");
ADD_PROPERTY_TYPE(UnderTolerance ,(0.0),"",App::Prop_None,"- Tolerance value");
ADD_PROPERTY_TYPE(Inverted,(false),"",(App::PropertyType)(App::Prop_None),"The dimensional value is displayed inverted");
ADD_PROPERTY_TYPE(TheoreticalExact,(false),"", App::Prop_Output,"Set for theoretical exact (basic) dimension");
ADD_PROPERTY_TYPE(OverTolerance ,(0.0),"", App::Prop_Output,"+ Tolerance value");
ADD_PROPERTY_TYPE(UnderTolerance ,(0.0),"", App::Prop_Output,"- Tolerance value");
ADD_PROPERTY_TYPE(Inverted,(false),"", App::Prop_Output,"The dimensional value is displayed inverted");
//hide the properties the user can't edit in the property editor
// References2D.setStatus(App::Property::Hidden,true);
@@ -160,19 +160,25 @@ void DrawViewDimension::onChanged(const App::Property* prop)
Base::Console().Warning("%s has no 3D References but is Type: True\n", getNameInDocument());
MeasureType.setValue("Projected");
}
}
if (prop == &References3D) { //have to rebuild the Measurement object
} else if (prop == &References3D) { //have to rebuild the Measurement object
clear3DMeasurements(); //Measurement object
if (!(References3D.getValues()).empty()) {
setAll3DMeasurement();
} else {
if (MeasureType.isValue("True")) { //empty 3dRefs, but True
MeasureType.touch(); //run MeasureType logic for this case
if (MeasureType.isValue("True")) { //empty 3dRefs, but True
MeasureType.touch(); //run MeasureType logic for this case
}
}
}
if (prop == &Type) {
} else if (prop == &Type) { //why??
FormatSpec.setValue(getDefaultFormatSpec().c_str());
} else if ( (prop == &FormatSpec) ||
(prop == &Arbitrary) ||
(prop == &MeasureType) ||
(prop == &TheoreticalExact) ||
(prop == &OverTolerance) ||
(prop == &UnderTolerance) ||
(prop == &Inverted) ) {
// nothing in particular
}
}
@@ -191,18 +197,15 @@ short DrawViewDimension::mustExecute() const
{
bool result = 0;
if (!isRestoring()) {
result = (References2D.isTouched() ||
result = (References2D.isTouched() ||
Type.isTouched() ||
FormatSpec.isTouched() ||
MeasureType.isTouched());
}
if (result) {
return result;
}
auto dvp = getViewPart();
if (dvp != nullptr) {
result = dvp->isTouched();
Arbitrary.isTouched() ||
MeasureType.isTouched() ||
TheoreticalExact.isTouched() ||
OverTolerance.isTouched() ||
UnderTolerance.isTouched() ||
Inverted.isTouched() );
}
if (result) {
return result;
@@ -572,10 +575,10 @@ std::string DrawViewDimension::getFormatedValue(int partial)
}
} else {
//handle single value schemes
QRegExp rxUnits(QString::fromUtf8(" \\D*$")); //space + any non digits at end of string
QRegExp rxUnits(QString::fromUtf8(" \\D*$")); //space + any non digits at end of string
QString userVal = userStr;
userVal.remove(rxUnits); //getUserString(defaultDecimals) without units
userVal.remove(rxUnits); //getUserString(defaultDecimals) without units
QLocale loc;
double userValNum = loc.toDouble(userVal);
@@ -583,7 +586,7 @@ std::string DrawViewDimension::getFormatedValue(int partial)
// QString userUnits;
int pos = 0;
if ((pos = rxUnits.indexIn(userStr, 0)) != -1) {
userUnits = rxUnits.cap(0); //entire capture - non numerics at end of userString
userUnits = rxUnits.cap(0); //entire capture - non numerics at end of userString
}
//find the %x.y tag in FormatSpec

View File

@@ -133,7 +133,8 @@ DrawViewPart::DrawViewPart(void) :
Source.setScope(App::LinkScope::Global);
ADD_PROPERTY_TYPE(Direction ,(0.0,-1.0,0.0),
group,App::Prop_None,"Projection direction. The direction you are looking from.");
ADD_PROPERTY_TYPE(Perspective ,(false),group,App::Prop_None,"Perspective(true) or Orthographic(false) projection");
ADD_PROPERTY_TYPE(Perspective ,(false),group,App::Prop_None,
"Perspective(true) or Orthographic(false) projection");
ADD_PROPERTY_TYPE(Focus,(defDist),group,App::Prop_None,"Perspective view focus distance");
//properties that control HLR algoaffect Appearance
@@ -149,10 +150,10 @@ DrawViewPart::DrawViewPart(void) :
ADD_PROPERTY_TYPE(IsoHidden ,(false),sgroup,App::Prop_None,"Hidden Iso u,v lines on/off");
ADD_PROPERTY_TYPE(IsoCount ,(0),sgroup,App::Prop_None,"Number of isoparameters");
ADD_PROPERTY_TYPE(CosmeticVertexes ,(0),sgroup,App::Prop_None,"CosmeticVertex Save/Restore");
ADD_PROPERTY_TYPE(CosmeticEdges ,(0),sgroup,App::Prop_None,"CosmeticEdge Save/Restore");
ADD_PROPERTY_TYPE(CenterLines ,(0),sgroup,App::Prop_None,"Geometry format Save/Restore");
ADD_PROPERTY_TYPE(GeomFormats ,(0),sgroup,App::Prop_None,"Geometry format Save/Restore");
ADD_PROPERTY_TYPE(CosmeticVertexes ,(0),sgroup,App::Prop_Output,"CosmeticVertex Save/Restore");
ADD_PROPERTY_TYPE(CosmeticEdges ,(0),sgroup,App::Prop_Output,"CosmeticEdge Save/Restore");
ADD_PROPERTY_TYPE(CenterLines ,(0),sgroup,App::Prop_Output,"Geometry format Save/Restore");
ADD_PROPERTY_TYPE(GeomFormats ,(0),sgroup,App::Prop_Output,"Geometry format Save/Restore");
geometryObject = nullptr;
getRunControl();
@@ -283,7 +284,7 @@ TopoDS_Shape DrawViewPart::getSourceShapeFused(void) const
App::DocumentObjectExecReturn *DrawViewPart::execute(void)
{
// Base::Console().Message("DVP::execute()\n");
// Base::Console().Message("DVP::execute() - %s\n", Label.getValue());
if (!keepUpdated()) {
return App::DocumentObject::StdReturn;
}
@@ -323,8 +324,8 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void)
shapeCentroid = Base::Vector3d(inputCenter.X(),inputCenter.Y(),inputCenter.Z());
TopoDS_Shape mirroredShape;
mirroredShape = TechDraw::mirrorShape(shape,
inputCenter,
getScale());
inputCenter,
getScale());
gp_Ax2 viewAxis = getViewAxis(shapeCentroid,Direction.getValue());
if (!DrawUtil::fpCompare(Rotation.getValue(),0.0)) {
@@ -361,8 +362,7 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void)
#endif //#if MOD_TECHDRAW_HANDLE_FACES
requestPaint();
return App::DocumentObject::StdReturn;
return DrawView::execute();
}
short DrawViewPart::mustExecute() const
@@ -371,8 +371,6 @@ short DrawViewPart::mustExecute() const
if (!isRestoring()) {
result = (Direction.isTouched() ||
Source.isTouched() ||
Scale.isTouched() ||
ScaleType.isTouched() ||
Perspective.isTouched() ||
Focus.isTouched() ||
Rotation.isTouched() ||
@@ -646,9 +644,10 @@ std::vector<TechDraw::DrawViewBalloon*> DrawViewPart::getBalloons() const
return result;
}
const std::vector<TechDraw::Vertex *> & DrawViewPart::getVertexGeometry() const
const std::vector<TechDraw::Vertex *> DrawViewPart::getVertexGeometry() const
{
return geometryObject->getVertexGeometry();
std::vector<TechDraw::Vertex*> gVerts = geometryObject->getVertexGeometry();
return gVerts;
}
const std::vector<TechDraw::Face *> & DrawViewPart::getFaceGeometry() const
@@ -960,6 +959,13 @@ void DrawViewPart::clearCosmeticVertexes(void)
CosmeticVertexes.setValues(noVerts);
}
//CosmeticVertex x,y are stored as unscaled, but mirrored values.
//if you are creating a CV based on calculations of scaled geometry, you need to
//unscale x,y before creation.
//if you are creating a CV based on calculations of mirrored geometry, you need to
//mirror again before creation.
//returns CosmeticVertex index! not geomVertexNumber!
int DrawViewPart::addCosmeticVertex(Base::Vector3d pos)
{
std::vector<CosmeticVertex*> verts = CosmeticVertexes.getValues();
@@ -1000,6 +1006,7 @@ void DrawViewPart::removeCosmeticVertex(TechDraw::CosmeticVertex* cv)
}
}
//this is by CV index, not the index returned by selection
void DrawViewPart::removeCosmeticVertex(int idx)
{
std::vector<CosmeticVertex*> verts = CosmeticVertexes.getValues();
@@ -1048,7 +1055,8 @@ TechDraw::CosmeticVertex* DrawViewPart::getCosmeticVertexByIndex(int idx) const
return result;
}
//find the cosmetic vertex corresponding to geometry vertex idx
// find the cosmetic vertex corresponding to geometry vertex idx
// used when selecting
TechDraw::CosmeticVertex* DrawViewPart::getCosmeticVertexByGeom(int idx) const
{
CosmeticVertex* result = nullptr;

View File

@@ -127,7 +127,7 @@ public:
std::vector<TechDraw::DrawViewDimension*> getDimensions() const;
std::vector<TechDraw::DrawViewBalloon*> getBalloons() const;
const std::vector<TechDraw::Vertex *> & getVertexGeometry() const;
const std::vector<TechDraw::Vertex *> getVertexGeometry() const;
const std::vector<TechDraw::BaseGeom *> & getEdgeGeometry() const;
const std::vector<TechDraw::BaseGeom *> getVisibleFaceEdges() const;
const std::vector<TechDraw::Face *> & getFaceGeometry() const;
@@ -210,7 +210,7 @@ protected:
TechDraw::GeometryObject *geometryObject;
Base::BoundBox3d bbox;
void onChanged(const App::Property* prop) override;
virtual void onChanged(const App::Property* prop) override;
virtual void unsetupObject() override;
virtual TechDraw::GeometryObject* buildGeometryObject(TopoDS_Shape shape, gp_Ax2 viewAxis);

View File

@@ -342,8 +342,7 @@ App::DocumentObjectExecReturn *DrawViewSection::execute(void)
//add centerlines to geometry edges list
addCenterLinesToGeom();
requestPaint();
return App::DocumentObject::StdReturn;
return DrawView::execute();
}
gp_Pln DrawViewSection::getSectionPlane() const

View File

@@ -234,6 +234,43 @@ bool CmdTechDrawNewPage::isActive(void)
return hasActiveDocument();
}
//===========================================================================
// TechDraw_Redraw
//===========================================================================
DEF_STD_CMD_A(CmdTechDrawRedraw)
CmdTechDrawRedraw::CmdTechDrawRedraw()
: Command("TechDraw_Redraw")
{
sAppModule = "TechDraw";
sGroup = QT_TR_NOOP("TechDraw");
sMenuText = QT_TR_NOOP("Redraw a page");
sToolTipText = QT_TR_NOOP("Redraw a page");
sWhatsThis = "TechDraw_Redraw";
sStatusTip = sToolTipText;
sPixmap = "actions/techdraw-forceredraw";
}
void CmdTechDrawRedraw::activated(int iMsg)
{
Q_UNUSED(iMsg);
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
if (!page) {
return;
}
Gui::WaitCursor wc;
page->redrawCommand();
}
bool CmdTechDrawRedraw::isActive(void)
{
bool havePage = DrawGuiUtil::needPage(this);
bool haveView = DrawGuiUtil::needView(this,false);
return (havePage && haveView);
}
//===========================================================================
// TechDraw_NewView
//===========================================================================
@@ -561,9 +598,12 @@ void CmdTechDrawProjGroup::activated(int iMsg)
Gui::WaitCursor wc;
openCommand("Create Projection Group");
std::string multiViewName = getUniqueObjectName("ProjGroup");
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawProjGroup','%s')",multiViewName.c_str());
doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),multiViewName.c_str());
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawProjGroup','%s')",
multiViewName.c_str());
doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",
PageName.c_str(),multiViewName.c_str());
App::DocumentObject *docObj = getDocument()->getObject(multiViewName.c_str());
auto multiView( static_cast<TechDraw::DrawProjGroup *>(docObj) );
@@ -578,7 +618,6 @@ void CmdTechDrawProjGroup::activated(int iMsg)
doCommand(Doc,"App.activeDocument().%s.Anchor.RotationVector = FreeCAD.Vector(%.3f,%.3f,%.3f)",
multiViewName.c_str(), dirs.second.x,dirs.second.y,dirs.second.z);
getDocument()->setStatus(App::Document::Status::SkipRecompute, false);
doCommand(Doc,"App.activeDocument().%s.Anchor.recompute()", multiViewName.c_str());
} else {
std::pair<Base::Vector3d,Base::Vector3d> dirs = DrawGuiUtil::get3DDirAndRot();
getDocument()->setStatus(App::Document::Status::SkipRecompute, true);
@@ -587,13 +626,14 @@ void CmdTechDrawProjGroup::activated(int iMsg)
doCommand(Doc,"App.activeDocument().%s.Anchor.RotationVector = FreeCAD.Vector(%.3f,%.3f,%.3f)",
multiViewName.c_str(), dirs.second.x,dirs.second.y,dirs.second.z);
getDocument()->setStatus(App::Document::Status::SkipRecompute, false);
doCommand(Doc,"App.activeDocument().%s.Anchor.recompute()", multiViewName.c_str());
}
commitCommand(); //write the undo
doCommand(Doc,"App.activeDocument().%s.Anchor.recompute()", multiViewName.c_str());
commitCommand();
updateActive();
// create the rest of the desired views
Gui::Control().showDialog(new TaskDlgProjGroup(multiView,true));
}
bool CmdTechDrawProjGroup::isActive(void)
@@ -1276,6 +1316,7 @@ void CreateTechDrawCommands(void)
rcCmdMgr.addCommand(new CmdTechDrawNewPageDef());
rcCmdMgr.addCommand(new CmdTechDrawNewPage());
rcCmdMgr.addCommand(new CmdTechDrawRedraw());
rcCmdMgr.addCommand(new CmdTechDrawNewView());
rcCmdMgr.addCommand(new CmdTechDrawNewActiveView());
rcCmdMgr.addCommand(new CmdTechDrawNewViewSection());

View File

@@ -471,43 +471,6 @@ bool CmdTechDrawToggleFrame::isActive(void)
return (havePage && haveView);
}
//===========================================================================
// TechDraw_Redraw
//===========================================================================
DEF_STD_CMD_A(CmdTechDrawRedraw)
CmdTechDrawRedraw::CmdTechDrawRedraw()
: Command("TechDraw_Redraw")
{
sAppModule = "TechDraw";
sGroup = QT_TR_NOOP("TechDraw");
sMenuText = QT_TR_NOOP("Redraw a page");
sToolTipText = QT_TR_NOOP("Redraw a page");
sWhatsThis = "TechDraw_Redraw";
sStatusTip = sToolTipText;
sPixmap = "actions/techdraw-forceredraw";
}
void CmdTechDrawRedraw::activated(int iMsg)
{
Q_UNUSED(iMsg);
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
if (!page) {
return;
}
Gui::WaitCursor wc;
page->forceRedraw(true);
page->updateAllViews();
page->forceRedraw(false);
}
bool CmdTechDrawRedraw::isActive(void)
{
bool havePage = DrawGuiUtil::needPage(this);
return (havePage);
}
void CreateTechDrawCommandsDecorate(void)
{
@@ -517,7 +480,6 @@ void CreateTechDrawCommandsDecorate(void)
rcCmdMgr.addCommand(new CmdTechDrawNewGeomHatch());
rcCmdMgr.addCommand(new CmdTechDrawImage());
rcCmdMgr.addCommand(new CmdTechDrawToggleFrame());
rcCmdMgr.addCommand(new CmdTechDrawRedraw());
// rcCmdMgr.addCommand(new CmdTechDrawLeaderLine());
// rcCmdMgr.addCommand(new CmdTechDrawRichAnno());
}

View File

@@ -242,6 +242,7 @@ void QGIView::mousePressEvent(QGraphicsSceneMouseEvent * event)
void QGIView::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
{
//TODO: this should be done in itemChange
if(!m_locked) {
if (!isInnerView()) {
double tempX = x(),
@@ -337,13 +338,6 @@ void QGIView::updateView(bool update)
setFlag(QGraphicsItem::ItemIsMovable, true);
}
if (getViewObject()->X.isTouched() || //change in feat position
getViewObject()->Y.isTouched()) {
double featX = Rez::guiX(getViewObject()->X.getValue());
double featY = Rez::guiX(getViewObject()->Y.getValue());
setPosition(featX,featY);
}
double appRotation = getViewObject()->Rotation.getValue();
double guiRotation = rotation();
if (!TechDraw::DrawUtil::fpCompare(appRotation,guiRotation)) {
@@ -412,6 +406,13 @@ void QGIView::toggleCache(bool state)
void QGIView::draw()
{
// Base::Console().Message("QGIV::draw()\n");
double x, y;
if (getViewObject() != nullptr) {
x = Rez::guiX(getViewObject()->X.getValue());
y = Rez::guiX(getViewObject()->Y.getValue());
setPosition(x, y);
}
if (isVisible()) {
drawBorder();
show();

View File

@@ -297,6 +297,7 @@ QPainterPath QGIViewPart::geomToPainterPath(TechDraw::BaseGeom *baseGeom, double
void QGIViewPart::updateView(bool update)
{
// Base::Console().Message("QGIVP::updateView()\n");
auto start = std::chrono::high_resolution_clock::now();
auto viewPart( dynamic_cast<TechDraw::DrawViewPart *>(getViewObject()) );
if( viewPart == nullptr ) {
@@ -307,11 +308,10 @@ void QGIViewPart::updateView(bool update)
return;
}
QGIView::updateView(update);
if (update ) {
draw();
}
QGIView::updateView(update);
auto end = std::chrono::high_resolution_clock::now();
auto diff = end - start;
@@ -320,13 +320,13 @@ void QGIViewPart::updateView(bool update)
}
void QGIViewPart::draw() {
// Base::Console().Message("QGIVP::draw()\n");
if (!isVisible()) {
return;
}
drawViewPart();
drawMatting();
QGIView::draw();
//this is old C/L
drawCenterLines(true); //have to draw centerlines after border to get size correct.
drawAllSectionLines(); //same for section lines
@@ -334,7 +334,7 @@ void QGIViewPart::draw() {
void QGIViewPart::drawViewPart()
{
// Base::Console().Message("QGIVP::dvp()\n");
// Base::Console().Message("QGIVP::DVP()\n");
auto viewPart( dynamic_cast<TechDraw::DrawViewPart *>(getViewObject()) );
if ( viewPart == nullptr ) {
return;
@@ -519,7 +519,6 @@ void QGIViewPart::drawViewPart()
bool showVertices = true;
bool showCenterMarks = true;
// bool usePolygonHLR = viewPart->CoarseView.getValue();
if (getFrameState()) { //frames are on
if (viewPart->CoarseView.getValue()) {
showVertices = false;
@@ -655,7 +654,6 @@ void QGIViewPart::removePrimitives()
QGIPrimPath* prim = dynamic_cast<QGIPrimPath*>(c);
if (prim) {
prim->hide();
// removeFromGroup(prim);
scene()->removeItem(prim);
delete prim;
}
@@ -674,12 +672,10 @@ void QGIViewPart::removeDecorations()
QGIMatting* mat = dynamic_cast<QGIMatting*>(c);
if (decor) {
decor->hide();
// removeFromGroup(decor);
scene()->removeItem(decor);
delete decor;
} else if (mat) {
mat->hide();
// removeFromGroup(mat);
scene()->removeItem(mat);
delete mat;
}

View File

@@ -27,6 +27,8 @@
#include <cmath>
#endif // #ifndef _PreComp_
#include <QMessageBox>
#include <Base/Console.h>
#include <Gui/Application.h>
@@ -116,6 +118,7 @@ TaskProjGroup::TaskProjGroup(TechDraw::DrawProjGroup* featView, bool mode) :
m_mdi = dvp->getMDIViewPage();
setUiPrimary();
saveGroupState();
}
TaskProjGroup::~TaskProjGroup()
@@ -123,6 +126,42 @@ TaskProjGroup::~TaskProjGroup()
delete ui;
}
void TaskProjGroup::saveGroupState()
{
// Base::Console().Message("TPG::saveGroupState()\n");
if (multiView != nullptr) {
m_saveSource = multiView->Source.getValues();
m_saveProjType = multiView->ProjectionType.getValueAsString();
m_saveScaleType = multiView->ScaleType.getValueAsString();
m_saveScale = multiView->Scale.getValue();
DrawProjGroupItem* anchor = multiView->getAnchor();
m_saveDirection = anchor->Direction.getValue();
}
for( const auto it : multiView->Views.getValues() ) {
auto view( dynamic_cast<DrawProjGroupItem *>(it) );
if (view != nullptr) {
m_saveViewNames.push_back(view->Type.getValueAsString());
}
}
}
//never used?
void TaskProjGroup::restoreGroupState()
{
Base::Console().Message("TPG::restoreGroupState()\n");
if (multiView != nullptr) {
multiView->ProjectionType.setValue(m_saveProjType.c_str());
multiView->ScaleType.setValue(m_saveScaleType.c_str());
multiView->Scale.setValue(m_saveScale);
multiView->purgeProjections();
for(auto & sv : m_saveViewNames) {
if (sv != "Front") {
multiView->addProjection(sv.c_str());
}
}
}
}
void TaskProjGroup::viewToggled(bool toggle)
{
Gui::WaitCursor wc;
@@ -132,10 +171,9 @@ void TaskProjGroup::viewToggled(bool toggle)
int index = viewName.mid(7).toInt();
const char *viewNameCStr = viewChkIndexToCStr(index);
if ( toggle && !multiView->hasProjection( viewNameCStr ) ) {
(void) multiView->addProjection( viewNameCStr ); //maybe this should be send a message instead of blocking?
// Gui::Command::doCommand(Gui::Command::Doc, // Gui response is no faster with this. :(
// "App.activeDocument().%s.addProjection('%s')",
// multiView->getNameInDocument(), viewNameCStr);
Gui::Command::doCommand(Gui::Command::Doc,
"App.activeDocument().%s.addProjection('%s')",
multiView->getNameInDocument(), viewNameCStr);
changed = true;
} else if ( !toggle && multiView->hasProjection( viewNameCStr ) ) {
multiView->removeProjection( viewNameCStr );
@@ -164,26 +202,15 @@ void TaskProjGroup::rotateButtonClicked(void)
multiView->rotateRight();
} else if ( clicked == ui->butLeftRotate) {
multiView->rotateLeft();
} else if ( clicked == ui->butCWRotate ) { //doesn't change Anchor view dir. changes projType of secondaries, not dir
} else if ( clicked == ui->butCWRotate ) {
multiView->spinCW();
} else if ( clicked == ui->butCCWRotate) {
multiView->spinCCW();
}
setUiPrimary();
multiView->recomputeFeature(true);
}
}
//void TaskProjGroup::onResetClicked(void)
//{
// TechDraw::DrawProjGroupItem* front = multiView->getProjItem("Front");
// if (front) {
// setUiPrimary();
// Gui::Command::updateActive();
// }
//}
void TaskProjGroup::projectionTypeChanged(int index)
{
if(blockUpdate)
@@ -191,19 +218,14 @@ void TaskProjGroup::projectionTypeChanged(int index)
if(index == 0) {
//layout per Page (Document)
Gui::Command::doCommand(Gui::Command::Doc,
"App.activeDocument().%s.ProjectionType = '%s'",
multiView->getNameInDocument(), "Default");
multiView->ProjectionType.setValue("Default");
} else if(index == 1) {
// First Angle layout
Gui::Command::doCommand(Gui::Command::Doc,
"App.activeDocument().%s.ProjectionType = '%s'",
multiView->getNameInDocument(), "First Angle");
multiView->ProjectionType.setValue("First Angle");
} else if(index == 2) {
// Third Angle layout
Gui::Command::doCommand(Gui::Command::Doc,
"App.activeDocument().%s.ProjectionType = '%s'",
multiView->getNameInDocument(), "Third Angle");
multiView->ProjectionType.setValue("Third Angle");
} else {
Base::Console().Log("Error - TaskProjGroup::projectionTypeChanged - unknown projection layout: %d\n",
index);
@@ -212,9 +234,6 @@ void TaskProjGroup::projectionTypeChanged(int index)
// Update checkboxes so checked state matches the drawing
setupViewCheckboxes();
multiView->recomputeFeature(true);
}
void TaskProjGroup::scaleTypeChanged(int index)
@@ -228,12 +247,9 @@ void TaskProjGroup::scaleTypeChanged(int index)
if(index == 0) {
// Document Scale Type
Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().%s.ScaleType = '%s'", multiView->getNameInDocument()
, "Page");
multiView->ScaleType.setValue("Page");
} else if(index == 1) {
// Automatic Scale Type
// Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().%s.ScaleType = '%s'", multiView->getNameInDocument()
// , "Automatic");
//block recompute
multiView->ScaleType.setValue("Automatic");
double autoScale = multiView->calculateAutomaticScale();
@@ -243,23 +259,19 @@ void TaskProjGroup::scaleTypeChanged(int index)
} else if(index == 2) {
// Custom Scale Type
//block recompute
Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().%s.ScaleType = '%s'", multiView->getNameInDocument()
, "Custom");
multiView->ScaleType.setValue("Custom");
ui->sbScaleNum->setEnabled(true);
ui->sbScaleDen->setEnabled(true);
int a = ui->sbScaleNum->value();
int b = ui->sbScaleDen->value();
double scale = (double) a / (double) b;
Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().%s.Scale = %f", multiView->getNameInDocument()
, scale);
multiView->Scale.setValue(scale);
//unblock recompute
} else {
Base::Console().Log("Error - TaskProjGroup::scaleTypeChanged - unknown scale type: %d\n",index);
return;
}
multiView->recomputeFeature(true);
}
std::pair<int, int> TaskProjGroup::nearestFraction(const double val, const long int maxDenom) const
@@ -374,9 +386,10 @@ void TaskProjGroup::scaleManuallyChanged(int i)
int b = ui->sbScaleDen->value();
double scale = (double) a / (double) b;
Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().%s.Scale = %f", multiView->getNameInDocument()
, scale);
multiView->recomputeFeature(); //just a repaint. multiView is already marked for recompute by changed to Scale
multiView->recomputeFeature();
}
void TaskProjGroup::changeEvent(QEvent *e)
@@ -461,16 +474,34 @@ QString TaskProjGroup::formatVector(Base::Vector3d v)
return data;
}
void TaskProjGroup::saveButtons(QPushButton* btnOK,
QPushButton* btnCancel,
QPushButton* btnApply)
{
m_btnOK = btnOK;
m_btnCancel = btnCancel;
m_btnApply = btnApply;
}
bool TaskProjGroup::apply()
{
// Base::Console().Message("TPG::apply()\n");
multiView->recomputeChildren();
multiView->recomputeFeature();
return true;
}
bool TaskProjGroup::accept()
{
// Base::Console().Message("TPG::accept()\n");
Gui::Document* doc = Gui::Application::Instance->getDocument(multiView->getDocument());
if (!doc) return false;
// if (!getCreateMode()) //this is an edit session, end the transaction
{
Gui::Command::commitCommand();
}
//Gui::Command::updateActive(); //no chain of updates here
multiView->recomputeChildren();
multiView->recomputeFeature();
Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()");
return true;
@@ -481,8 +512,8 @@ bool TaskProjGroup::reject()
Gui::Document* doc = Gui::Application::Instance->getDocument(multiView->getDocument());
if (!doc) return false;
#if 0
if (getCreateMode()) {
//remove the object completely from the document
std::string multiViewName = multiView->getNameInDocument();
std::string PageName = multiView->findParentPage()->getNameInDocument();
@@ -492,22 +523,18 @@ bool TaskProjGroup::reject()
PageName.c_str(),multiViewName.c_str());
Gui::Command::doCommand(Gui::Command::Gui,"App.activeDocument().removeObject('%s')",multiViewName.c_str());
Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()");
//make sure any dangling objects are cleaned up
Gui::Command::doCommand(Gui::Command::Gui,"App.activeDocument().recompute()");
} else {
//set the DPG and it's views back to entry state.
if (Gui::Command::hasPendingCommand()) {
std::vector<std::string> undos = Gui::Application::Instance->activeDocument()->getUndoVector();
Gui::Application::Instance->activeDocument()->undo(1);
multiView->rebuildViewList();
Gui::Command::abortCommand();
// std::vector<std::string> undos = Gui::Application::Instance->activeDocument()->getUndoVector();
// Gui::Application::Instance->activeDocument()->undo(1);
// multiView->rebuildViewList();
// apply();
} else {
Base::Console().Log("TaskProjGroup: Edit mode - NO command is active\n");
}
Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()");
}
#endif
Gui::Command::abortCommand();
Gui::Command::runCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()");
return false;
}
@@ -541,17 +568,29 @@ void TaskDlgProjGroup::setCreateMode(bool b)
widget->setCreateMode(b);
}
void TaskDlgProjGroup::modifyStandardButtons(QDialogButtonBox* box)
{
QPushButton* btnOK = box->button(QDialogButtonBox::Ok);
QPushButton* btnCancel = box->button(QDialogButtonBox::Cancel);
QPushButton* btnApply = box->button(QDialogButtonBox::Apply);
widget->saveButtons(btnOK, btnCancel, btnApply);
}
//==== calls from the TaskView ===============================================================
void TaskDlgProjGroup::open()
{
// if (!widget->getCreateMode()) { //this is an edit session, start a transaction
// Gui::Command::openCommand("Edit Projection Group");
// }
App::GetApplication().setActiveTransaction("Edit Projection Group", true);
if (!widget->getCreateMode()) { //this is an edit session, start a transaction
App::GetApplication().setActiveTransaction("Edit Projection Group", true);
}
}
void TaskDlgProjGroup::clicked(int)
void TaskDlgProjGroup::clicked(int i)
{
// Q_UNUSED(i);
// Base::Console().Message("TDPG::clicked(%X)\n",i);
if (i == QMessageBox::Apply) {
widget->apply();
}
}
bool TaskDlgProjGroup::accept()

View File

@@ -62,6 +62,12 @@ public:
public:
virtual bool accept();
virtual bool reject();
virtual bool apply();
void modifyStandardButtons(QDialogButtonBox* box);
void saveButtons(QPushButton* btnOK,
QPushButton* btnCancel,
QPushButton* btnApply);
void updateTask();
std::pair<int, int> nearestFraction(const double val, const long int maxDenom = 999) const;
// Sets the numerator and denominator widgets to match newScale
@@ -91,22 +97,33 @@ protected:
*/
void setupViewCheckboxes(bool addConnections = false);
void setUiPrimary(void);
void saveGroupState();
void restoreGroupState();
QString formatVector(Base::Vector3d v);
TechDraw::DrawPage* m_page;
MDIViewPage* m_mdi;
private:
//class Private;
Ui_TaskProjGroup * ui;
TechDraw::DrawProjGroup* multiView;
bool m_createMode;
bool blockUpdate;
/// Translate a view checkbox index into represented view string, depending on projection type
const char * viewChkIndexToCStr(int index);
protected:
//ViewProviderProjGroup *viewProvider;
TechDraw::DrawProjGroup* multiView;
bool m_createMode;
TechDraw::DrawPage* m_page;
MDIViewPage* m_mdi;
QPushButton* m_btnOK;
QPushButton* m_btnCancel;
QPushButton* m_btnApply;
std::vector<App::DocumentObject*> m_saveSource;
std::string m_saveProjType;
std::string m_saveScaleType;
double m_saveScale;
Base::Vector3d m_saveDirection;
std::vector<std::string> m_saveViewNames;
};
/// Simulation dialog for the TaskView
@@ -120,6 +137,11 @@ public:
const ViewProviderProjGroup * getViewProvider() const { return viewProvider; }
TechDraw::DrawProjGroup * getMultiView() const { return multiView; }
virtual QDialogButtonBox::StandardButtons getStandardButtons() const
{ return QDialogButtonBox::Ok | QDialogButtonBox::Apply | QDialogButtonBox::Cancel; }
virtual void modifyStandardButtons(QDialogButtonBox* box);
public:
/// is called the TaskView when the dialog is opened
virtual void open();

View File

@@ -90,29 +90,11 @@ std::vector<std::string> ViewProviderProjGroup::getDisplayModes(void) const
void ViewProviderProjGroup::updateData(const App::Property* prop)
{
ViewProviderDrawingView::updateData(prop);
if(prop == &(getObject()->Scale) ||
prop == &(getObject()->ScaleType) ||
prop == &(getObject()->Views) ||
prop == &(getObject()->ProjectionType) ||
prop == &(getObject()->LockPosition) ) {
QGIView* qgiv = getQView();
if (qgiv) {
qgiv->updateView(true);
}
}
}
void ViewProviderProjGroup::onChanged(const App::Property *prop)
{
if (prop == &(getViewObject()->Scale)) {
if (getViewObject()->ScaleType.isValue("Automatic")) {
getMDIViewPage()->redraw1View(getViewObject());
}
} else if (prop == &(getViewObject()->ScaleType)) {
getMDIViewPage()->redraw1View(getViewObject());
}
ViewProviderDrawingView::onChanged(prop);
}
void ViewProviderProjGroup::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)

View File

@@ -53,6 +53,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const
draw->setCommand("TechDraw");
*draw << "TechDraw_NewPageDef";
*draw << "TechDraw_NewPage";
*draw << "TechDraw_Redraw";
*draw << "Separator";
*draw << "TechDraw_NewView";
*draw << "TechDraw_NewActiveView";
@@ -87,7 +88,6 @@ Gui::MenuItem* Workbench::setupMenuBar() const
*draw << "TechDraw_Symbol";
*draw << "TechDraw_Image";
*draw << "TechDraw_ToggleFrame";
*draw << "TechDraw_Redraw";
*draw << "Separator";
*draw << "TechDraw_Annotation";
*draw << "TechDraw_LeaderLine";
@@ -112,6 +112,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const
pages->setCommand("TechDraw Pages");
*pages << "TechDraw_NewPageDef";
*pages << "TechDraw_NewPage";
*pages << "TechDraw_Redraw";
Gui::ToolBarItem *views = new Gui::ToolBarItem(root);
views->setCommand("TechDraw Views");
@@ -156,7 +157,6 @@ Gui::ToolBarItem* Workbench::setupToolBars() const
*decor << "TechDraw_Symbol";
*decor << "TechDraw_Image";
*decor << "TechDraw_ToggleFrame";
*decor << "TechDraw_Redraw";
Gui::ToolBarItem *anno = new Gui::ToolBarItem(root);
anno->setCommand("TechDraw Annotation");
@@ -182,6 +182,7 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const
pages->setCommand("TechDraw Pages");
*pages << "TechDraw_NewPageDef";
*pages << "TechDraw_NewPage";
*pages << "TechDraw_Redraw";
Gui::ToolBarItem *views = new Gui::ToolBarItem(root);
views->setCommand("Views");
@@ -225,7 +226,6 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const
*decor << "TechDraw_Symbol";
*decor << "TechDraw_Image";
*decor << "TechDraw_ToggleFrame";
*decor << "TechDraw_Redraw";
Gui::ToolBarItem *anno = new Gui::ToolBarItem(root);
anno->setCommand("TechDraw Annotation");