Sketcher: New Functionality: Mirror full sketch
=============================================== Support for mirroring a full sketch. A dialog appears allowing to select X, Y axis mirroring or mirroring about the origin of the sketch.
This commit is contained in:
parent
0e01764f0b
commit
d795eb2b7d
|
@ -36,6 +36,7 @@ set(SketcherGui_MOC_HDRS
|
|||
TaskSketcherValidation.h
|
||||
TaskDlgEditSketch.h
|
||||
SketchOrientationDialog.h
|
||||
SketchMirrorDialog.h
|
||||
SketcherSettings.h
|
||||
SketchRectangularArrayDialog.h
|
||||
PropertyConstraintListItem.h
|
||||
|
@ -54,6 +55,7 @@ set(SketcherGui_UIC_SRCS
|
|||
TaskSketcherValidation.ui
|
||||
InsertDatum.ui
|
||||
SketchOrientationDialog.ui
|
||||
SketchMirrorDialog.ui
|
||||
SketcherSettings.ui
|
||||
SketchRectangularArrayDialog.ui
|
||||
)
|
||||
|
@ -110,6 +112,8 @@ SET(SketcherGui_SRCS
|
|||
EditDatumDialog.h
|
||||
SketchOrientationDialog.cpp
|
||||
SketchOrientationDialog.h
|
||||
SketchMirrorDialog.cpp
|
||||
SketchMirrorDialog.h
|
||||
SketcherSettings.cpp
|
||||
SketcherSettings.h
|
||||
SketchRectangularArrayDialog.h
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
#include <Mod/Part/App/Part2DObject.h>
|
||||
|
||||
#include "SketchOrientationDialog.h"
|
||||
#include "SketchMirrorDialog.h"
|
||||
#include "ViewProviderSketch.h"
|
||||
#include "TaskSketcherValidation.h"
|
||||
#include "../App/Constraint.h"
|
||||
|
@ -506,10 +507,121 @@ bool CmdSketcherValidateSketch::isActive(void)
|
|||
return (hasActiveDocument() && !Gui::Control().activeDialog());
|
||||
}
|
||||
|
||||
DEF_STD_CMD_A(CmdSketcherMirrorSketch);
|
||||
|
||||
CmdSketcherMirrorSketch::CmdSketcherMirrorSketch()
|
||||
: Command("Sketcher_MirrorSketch")
|
||||
{
|
||||
sAppModule = "Sketcher";
|
||||
sGroup = QT_TR_NOOP("Sketcher");
|
||||
sMenuText = QT_TR_NOOP("Mirror sketch");
|
||||
sToolTipText = QT_TR_NOOP("Mirror sketch");
|
||||
sWhatsThis = "Sketcher_MirrorSketch";
|
||||
sStatusTip = sToolTipText;
|
||||
eType = 0;
|
||||
sPixmap = "Sketcher_MirrorSketch";
|
||||
}
|
||||
|
||||
void CmdSketcherMirrorSketch::activated(int iMsg)
|
||||
{
|
||||
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx(0, Sketcher::SketchObject::getClassTypeId());
|
||||
if (selection.size() < 1) {
|
||||
QMessageBox::warning(Gui::getMainWindow(),
|
||||
qApp->translate("CmdSketcherMirrorSketch", "Wrong selection"),
|
||||
qApp->translate("CmdSketcherMirrorSketch", "Select one or more sketches, please."));
|
||||
return;
|
||||
}
|
||||
|
||||
// Ask the user which kind of mirroring he wants
|
||||
SketchMirrorDialog * smd = new SketchMirrorDialog();
|
||||
|
||||
int refgeoid=-1;
|
||||
Sketcher::PointPos refposid=Sketcher::none;
|
||||
|
||||
if( smd->exec() == QDialog::Accepted ){
|
||||
refgeoid=smd->RefGeoid;
|
||||
refposid=smd->RefPosid;
|
||||
|
||||
delete smd;
|
||||
}
|
||||
else {
|
||||
delete smd;
|
||||
return;
|
||||
}
|
||||
|
||||
App::Document* doc = App::GetApplication().getActiveDocument();
|
||||
|
||||
openCommand("Create a mirror Sketch for each sketch");
|
||||
|
||||
for (std::vector<Gui::SelectionObject>::const_iterator it=selection.begin(); it != selection.end(); ++it) {
|
||||
// create Sketch
|
||||
std::string FeatName = getUniqueObjectName("MirroredSketch");
|
||||
|
||||
doCommand(Doc,"App.activeDocument().addObject('Sketcher::SketchObject','%s')",FeatName.c_str());
|
||||
|
||||
Sketcher::SketchObject* mirrorsketch = static_cast<Sketcher::SketchObject*>(doc->getObject(FeatName.c_str()));
|
||||
|
||||
const Sketcher::SketchObject* Obj = static_cast<const Sketcher::SketchObject*>((*it).getObject());
|
||||
|
||||
Base::Placement pl = Obj->Placement.getValue();
|
||||
|
||||
Base::Vector3d p = pl.getPosition();
|
||||
Base::Rotation r = pl.getRotation();
|
||||
|
||||
doCommand(Doc,"App.activeDocument().%s.Placement = App.Placement(App.Vector(%f,%f,%f),App.Rotation(%f,%f,%f,%f))",
|
||||
FeatName.c_str(),
|
||||
p.x,p.y,p.z,r[0],r[1],r[2],r[3]);
|
||||
|
||||
Sketcher::SketchObject* tempsketch = new Sketcher::SketchObject();
|
||||
|
||||
int addedGeometries=tempsketch->addGeometry(Obj->getInternalGeometry());
|
||||
|
||||
int addedConstraints=tempsketch->addConstraints(Obj->Constraints.getValues());
|
||||
|
||||
std::vector<int> geoIdList;
|
||||
|
||||
for(int i=0;i<=addedGeometries;i++)
|
||||
geoIdList.push_back(i);
|
||||
|
||||
tempsketch->addSymmetric(geoIdList, refgeoid, refposid);
|
||||
|
||||
std::vector<Part::Geometry *> tempgeo = tempsketch->getInternalGeometry();
|
||||
std::vector<Sketcher::Constraint *> tempconstr = tempsketch->Constraints.getValues();
|
||||
|
||||
int nconstraints = tempconstr.size();
|
||||
|
||||
std::vector<Part::Geometry *> mirrorgeo (tempgeo.begin()+addedGeometries+1,tempgeo.end());
|
||||
std::vector<Sketcher::Constraint *> mirrorconstr (tempconstr.begin()+addedConstraints+1,tempconstr.end());
|
||||
|
||||
for(std::vector<Sketcher::Constraint *>::const_iterator itc=mirrorconstr.begin(); itc != mirrorconstr.end(); ++itc) {
|
||||
|
||||
if((*itc)->First!=Sketcher::Constraint::GeoUndef || (*itc)->First==-1 || (*itc)->First==-2) // not x, y axes or origin
|
||||
(*itc)->First-=(addedGeometries+1);
|
||||
if((*itc)->Second!=Sketcher::Constraint::GeoUndef || (*itc)->Second==-1 || (*itc)->Second==-2) // not x, y axes or origin
|
||||
(*itc)->Second-=(addedGeometries+1);
|
||||
if((*itc)->Third!=Sketcher::Constraint::GeoUndef || (*itc)->Third==-1 || (*itc)->Third==-2) // not x, y axes or origin
|
||||
(*itc)->Third-=(addedGeometries+1);
|
||||
}
|
||||
|
||||
mirrorsketch->addGeometry(mirrorgeo);
|
||||
mirrorsketch->addConstraints(mirrorconstr);
|
||||
|
||||
delete tempsketch;
|
||||
}
|
||||
|
||||
doCommand(Gui,"App.activeDocument().recompute()");
|
||||
|
||||
}
|
||||
|
||||
bool CmdSketcherMirrorSketch::isActive(void)
|
||||
{
|
||||
return (hasActiveDocument() && !Gui::Control().activeDialog());
|
||||
}
|
||||
|
||||
DEF_STD_CMD_A(CmdSketcherMergeSketches);
|
||||
|
||||
CmdSketcherMergeSketches::CmdSketcherMergeSketches()
|
||||
: Command("Sketcher_MergeSketches")
|
||||
: Command("Sketcher_MergeSketches")
|
||||
{
|
||||
sAppModule = "Sketcher";
|
||||
sGroup = QT_TR_NOOP("Sketcher");
|
||||
|
@ -526,18 +638,18 @@ void CmdSketcherMergeSketches::activated(int iMsg)
|
|||
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx(0, Sketcher::SketchObject::getClassTypeId());
|
||||
if (selection.size() < 2) {
|
||||
QMessageBox::warning(Gui::getMainWindow(),
|
||||
qApp->translate("CmdSketcherMergeSketches", "Wrong selection"),
|
||||
qApp->translate("CmdSketcherMergeSketches", "Select at least two sketches, please."));
|
||||
qApp->translate("CmdSketcherMergeSketches", "Wrong selection"),
|
||||
qApp->translate("CmdSketcherMergeSketches", "Select at least two sketches, please."));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Sketcher::SketchObject* Obj1 = static_cast<Sketcher::SketchObject*>(selection[0].getObject());
|
||||
|
||||
App::Document* doc = App::GetApplication().getActiveDocument();
|
||||
|
||||
|
||||
// create Sketch
|
||||
std::string FeatName = getUniqueObjectName("Sketch");
|
||||
|
||||
|
||||
openCommand("Create a merge Sketch");
|
||||
doCommand(Doc,"App.activeDocument().addObject('Sketcher::SketchObject','%s')",FeatName.c_str());
|
||||
|
||||
|
@ -553,16 +665,16 @@ void CmdSketcherMergeSketches::activated(int iMsg)
|
|||
int addedConstraints=mergesketch->addConstraints(Obj->Constraints.getValues());
|
||||
|
||||
for(int i=0; i<=(addedConstraints-baseConstraints); i++){
|
||||
Sketcher::Constraint * constraint= mergesketch->Constraints.getValues()[i+baseConstraints];
|
||||
|
||||
if(constraint->First!=Sketcher::Constraint::GeoUndef || constraint->First==-1 || constraint->First==-2) // not x, y axes or origin
|
||||
constraint->First+=baseGeometry;
|
||||
if(constraint->Second!=Sketcher::Constraint::GeoUndef || constraint->Second==-1 || constraint->Second==-2) // not x, y axes or origin
|
||||
constraint->Second+=baseGeometry;
|
||||
if(constraint->Third!=Sketcher::Constraint::GeoUndef || constraint->Third==-1 || constraint->Third==-2) // not x, y axes or origin
|
||||
constraint->Third+=baseGeometry;
|
||||
}
|
||||
Sketcher::Constraint * constraint= mergesketch->Constraints.getValues()[i+baseConstraints];
|
||||
|
||||
if(constraint->First!=Sketcher::Constraint::GeoUndef || constraint->First==-1 || constraint->First==-2) // not x, y axes or origin
|
||||
constraint->First+=baseGeometry;
|
||||
if(constraint->Second!=Sketcher::Constraint::GeoUndef || constraint->Second==-1 || constraint->Second==-2) // not x, y axes or origin
|
||||
constraint->Second+=baseGeometry;
|
||||
if(constraint->Third!=Sketcher::Constraint::GeoUndef || constraint->Third==-1 || constraint->Third==-2) // not x, y axes or origin
|
||||
constraint->Third+=baseGeometry;
|
||||
}
|
||||
|
||||
baseGeometry=addedGeometries+1;
|
||||
baseConstraints=addedConstraints+1;
|
||||
}
|
||||
|
@ -576,8 +688,6 @@ bool CmdSketcherMergeSketches::isActive(void)
|
|||
return (hasActiveDocument() && !Gui::Control().activeDialog());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CreateSketcherCommands(void)
|
||||
{
|
||||
Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
|
||||
|
@ -589,5 +699,6 @@ void CreateSketcherCommands(void)
|
|||
rcCmdMgr.addCommand(new CmdSketcherMapSketch());
|
||||
rcCmdMgr.addCommand(new CmdSketcherViewSketch());
|
||||
rcCmdMgr.addCommand(new CmdSketcherValidateSketch());
|
||||
rcCmdMgr.addCommand(new CmdSketcherMirrorSketch());
|
||||
rcCmdMgr.addCommand(new CmdSketcherMergeSketches());
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/***************************************************************************
|
||||
* Copyright (c) 2014 Abdullah Tahiri <abdullah.tahiri.yo@gmail.com *
|
||||
* Copyright (c) 2014 Abdullah Tahiri <abdullah.tahiri.yo@gmail.com *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
|
|
69
src/Mod/Sketcher/Gui/SketchMirrorDialog.cpp
Normal file
69
src/Mod/Sketcher/Gui/SketchMirrorDialog.cpp
Normal file
|
@ -0,0 +1,69 @@
|
|||
/***************************************************************************
|
||||
* Copyright (c) 2015 Abdullah Tahiri <abdullah.tahiri.yo@gmail.com *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
# include <QPixmap>
|
||||
# include <QDialog>
|
||||
#endif
|
||||
|
||||
#include <Gui/BitmapFactory.h>
|
||||
#include <Gui/MainWindow.h>
|
||||
#include <Base/Tools.h>
|
||||
#include <Base/UnitsApi.h>
|
||||
|
||||
#include "ui_SketchMirrorDialog.h"
|
||||
#include "SketchMirrorDialog.h"
|
||||
|
||||
using namespace SketcherGui;
|
||||
|
||||
SketchMirrorDialog::SketchMirrorDialog(void)
|
||||
: QDialog(Gui::getMainWindow()), ui(new Ui_SketchMirrorDialog), RefGeoid(-1), RefPosid(Sketcher::none)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
SketchMirrorDialog::~SketchMirrorDialog()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SketchMirrorDialog::accept()
|
||||
{
|
||||
if (ui->XAxisRadioButton->isChecked()) {
|
||||
RefGeoid=-1;
|
||||
RefPosid=Sketcher::none;
|
||||
}
|
||||
else if (ui->YAxisRadioButton->isChecked()) {
|
||||
RefGeoid=-2;
|
||||
RefPosid=Sketcher::none;
|
||||
}
|
||||
else if (ui->OriginRadioButton->isChecked()) {
|
||||
RefGeoid=-1;
|
||||
RefPosid=Sketcher::start;
|
||||
}
|
||||
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
#include "moc_SketchMirrorDialog.cpp"
|
51
src/Mod/Sketcher/Gui/SketchMirrorDialog.h
Normal file
51
src/Mod/Sketcher/Gui/SketchMirrorDialog.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
/***************************************************************************
|
||||
* Copyright (c) 2015 Abdullah Tahiri <abdullah.tahiri.yo@gmail.com *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef SKETCHERGUI_SketchMirrorDialog_H
|
||||
#define SKETCHERGUI_SketchMirrorDialog_H
|
||||
|
||||
#include <QDialog>
|
||||
#include "../App/Constraint.h"
|
||||
|
||||
namespace SketcherGui {
|
||||
|
||||
class Ui_SketchMirrorDialog;
|
||||
class SketchMirrorDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SketchMirrorDialog(void);
|
||||
~SketchMirrorDialog();
|
||||
|
||||
int RefGeoid;
|
||||
Sketcher::PointPos RefPosid;
|
||||
|
||||
void accept();
|
||||
|
||||
private:
|
||||
Ui_SketchMirrorDialog* ui;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // SKETCHERGUI_SketchMirrorDialog_H
|
110
src/Mod/Sketcher/Gui/SketchMirrorDialog.ui
Normal file
110
src/Mod/Sketcher/Gui/SketchMirrorDialog.ui
Normal file
|
@ -0,0 +1,110 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>SketcherGui::SketchMirrorDialog</class>
|
||||
<widget class="QDialog" name="SketcherGui::SketchMirrorDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>220</width>
|
||||
<height>171</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Select Mirror Axis/Point</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Select Mirror Axis/Point</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QRadioButton" name="XAxisRadioButton">
|
||||
<property name="text">
|
||||
<string>X-Axis</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="YAxisRadioButton">
|
||||
<property name="text">
|
||||
<string>Y-Axis</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="OriginRadioButton">
|
||||
<property name="text">
|
||||
<string>Origin</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>SketcherGui::SketchMirrorDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>SketcherGui::SketchMirrorDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
|
@ -271,7 +271,8 @@ template <>
|
|||
inline void SketcherAddWorkspaceSketchExtra<Gui::MenuItem>(Gui::MenuItem& sketch){
|
||||
sketch << "Sketcher_ReorientSketch"
|
||||
<< "Sketcher_ValidateSketch"
|
||||
<< "Sketcher_MergeSketches";
|
||||
<< "Sketcher_MergeSketches"
|
||||
<< "Sketcher_MirrorSketch";
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
|
Loading…
Reference in New Issue
Block a user