00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <TopExp_Explorer.hxx>
00027 # include <QMessageBox>
00028 #endif
00029
00030 #include <Gui/Application.h>
00031 #include <Gui/Command.h>
00032 #include <Gui/Control.h>
00033 #include <Gui/Selection.h>
00034 #include <Gui/MainWindow.h>
00035 #include <Gui/FileDialog.h>
00036
00037 #include <Mod/Part/App/Part2DObject.h>
00038 #include "TaskChamfer.h"
00039
00040
00041 using namespace std;
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 DEF_STD_CMD_A(CmdPartDesignPad);
00092
00093 CmdPartDesignPad::CmdPartDesignPad()
00094 : Command("PartDesign_Pad")
00095 {
00096 sAppModule = "PartDesign";
00097 sGroup = QT_TR_NOOP("PartDesign");
00098 sMenuText = QT_TR_NOOP("Pad");
00099 sToolTipText = QT_TR_NOOP("Pad a selected sketch");
00100 sWhatsThis = sToolTipText;
00101 sStatusTip = sToolTipText;
00102 sPixmap = "PartDesign_Pad";
00103 }
00104
00105 void CmdPartDesignPad::activated(int iMsg)
00106 {
00107 unsigned int n = getSelection().countObjectsOfType(Part::Part2DObject::getClassTypeId());
00108 if (n != 1) {
00109 QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
00110 QObject::tr("Select a sketch or 2D object."));
00111 return;
00112 }
00113
00114 std::string FeatName = getUniqueObjectName("Pad");
00115
00116 std::vector<App::DocumentObject*> Sel = getSelection().getObjectsOfType(Part::Part2DObject::getClassTypeId());
00117 Part::Part2DObject* sketch = static_cast<Part::Part2DObject*>(Sel.front());
00118 const TopoDS_Shape& shape = sketch->Shape.getValue();
00119 if (shape.IsNull()) {
00120 QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
00121 QObject::tr("The shape of the selected object is empty."));
00122 return;
00123 }
00124
00125
00126 int ctWires=0;
00127 TopExp_Explorer ex;
00128 for (ex.Init(shape, TopAbs_WIRE); ex.More(); ex.Next()) {
00129 ctWires++;
00130 }
00131 if (ctWires == 0) {
00132 QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
00133 QObject::tr("The shape of the selected object is not a wire."));
00134 return;
00135 }
00136
00137 App::DocumentObject* support = sketch->Support.getValue();
00138
00139 openCommand("Make Pad");
00140 doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::Pad\",\"%s\")",FeatName.c_str());
00141 doCommand(Doc,"App.activeDocument().%s.Sketch = App.activeDocument().%s",FeatName.c_str(),sketch->getNameInDocument());
00142 doCommand(Doc,"App.activeDocument().%s.Length = 10.0",FeatName.c_str());
00143 updateActive();
00144 if (isActiveObjectValid()) {
00145 doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",sketch->getNameInDocument());
00146 if (support)
00147 doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",support->getNameInDocument());
00148 }
00149 doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
00150
00151
00152 adjustCameraPosition();
00153
00154 if (support) {
00155 copyVisual(FeatName.c_str(), "ShapeColor", support->getNameInDocument());
00156 copyVisual(FeatName.c_str(), "LineColor", support->getNameInDocument());
00157 copyVisual(FeatName.c_str(), "PointColor", support->getNameInDocument());
00158 }
00159 }
00160
00161 bool CmdPartDesignPad::isActive(void)
00162 {
00163 return hasActiveDocument();
00164 }
00165
00166
00167
00168
00169 DEF_STD_CMD_A(CmdPartDesignPocket);
00170
00171 CmdPartDesignPocket::CmdPartDesignPocket()
00172 : Command("PartDesign_Pocket")
00173 {
00174 sAppModule = "PartDesign";
00175 sGroup = QT_TR_NOOP("PartDesign");
00176 sMenuText = QT_TR_NOOP("Pocket");
00177 sToolTipText = QT_TR_NOOP("create a pocket with the selected sketch");
00178 sWhatsThis = sToolTipText;
00179 sStatusTip = sToolTipText;
00180 sPixmap = "PartDesign_Pocket";
00181 }
00182
00183 void CmdPartDesignPocket::activated(int iMsg)
00184 {
00185 unsigned int n = getSelection().countObjectsOfType(Part::Part2DObject::getClassTypeId());
00186 if (n != 1) {
00187 QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
00188 QObject::tr("Select a sketch or 2D object."));
00189 return;
00190 }
00191
00192 std::string FeatName = getUniqueObjectName("Pocket");
00193
00194 std::vector<App::DocumentObject*> Sel = getSelection().getObjectsOfType(Part::Part2DObject::getClassTypeId());
00195 Part::Part2DObject* sketch = static_cast<Part::Part2DObject*>(Sel.front());
00196 const TopoDS_Shape& shape = sketch->Shape.getValue();
00197 if (shape.IsNull()) {
00198 QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
00199 QObject::tr("The shape of the selected object is empty."));
00200 return;
00201 }
00202
00203
00204 int ctWires=0;
00205 TopExp_Explorer ex;
00206 for (ex.Init(shape, TopAbs_WIRE); ex.More(); ex.Next()) {
00207 ctWires++;
00208 }
00209 if (ctWires == 0) {
00210 QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
00211 QObject::tr("The shape of the selected object is not a wire."));
00212 return;
00213 }
00214 App::DocumentObject* support = sketch->Support.getValue();
00215 if (support == 0) {
00216 QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No Support"),
00217 QObject::tr("The sketch has to have a support for the pocket feature.\nCreate the sketch on a face."));
00218 return;
00219 }
00220
00221 openCommand("Make Pocket");
00222 doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::Pocket\",\"%s\")",FeatName.c_str());
00223 doCommand(Doc,"App.activeDocument().%s.Sketch = App.activeDocument().%s",FeatName.c_str(),sketch->getNameInDocument());
00224 doCommand(Doc,"App.activeDocument().%s.Length = 5.0",FeatName.c_str());
00225 updateActive();
00226 if (isActiveObjectValid()) {
00227 doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",sketch->getNameInDocument());
00228 doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",support->getNameInDocument());
00229 }
00230 doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
00231
00232 copyVisual(FeatName.c_str(), "ShapeColor", support->getNameInDocument());
00233 copyVisual(FeatName.c_str(), "LineColor", support->getNameInDocument());
00234 copyVisual(FeatName.c_str(), "PointColor", support->getNameInDocument());
00235 }
00236
00237 bool CmdPartDesignPocket::isActive(void)
00238 {
00239 return hasActiveDocument();
00240 }
00241
00242
00243
00244
00245 DEF_STD_CMD_A(CmdPartDesignRevolution);
00246
00247 CmdPartDesignRevolution::CmdPartDesignRevolution()
00248 : Command("PartDesign_Revolution")
00249 {
00250 sAppModule = "PartDesign";
00251 sGroup = QT_TR_NOOP("PartDesign");
00252 sMenuText = QT_TR_NOOP("Revolution");
00253 sToolTipText = QT_TR_NOOP("Revolve a selected sketch");
00254 sWhatsThis = sToolTipText;
00255 sStatusTip = sToolTipText;
00256 sPixmap = "PartDesign_Revolution";
00257 }
00258
00259 void CmdPartDesignRevolution::activated(int iMsg)
00260 {
00261 unsigned int n = getSelection().countObjectsOfType(Part::Part2DObject::getClassTypeId());
00262 if (n != 1) {
00263 QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
00264 QObject::tr("Select a sketch or 2D object."));
00265 return;
00266 }
00267
00268 std::string FeatName = getUniqueObjectName("Revolution");
00269
00270 std::vector<App::DocumentObject*> Sel = getSelection().getObjectsOfType(Part::Part2DObject::getClassTypeId());
00271 Part::Part2DObject* sketch = static_cast<Part::Part2DObject*>(Sel.front());
00272 const TopoDS_Shape& shape = sketch->Shape.getValue();
00273 if (shape.IsNull()) {
00274 QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
00275 QObject::tr("The shape of the selected object is empty."));
00276 return;
00277 }
00278
00279
00280 int ctWires=0;
00281 TopExp_Explorer ex;
00282 for (ex.Init(shape, TopAbs_WIRE); ex.More(); ex.Next()) {
00283 ctWires++;
00284 }
00285 if (ctWires == 0) {
00286 QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
00287 QObject::tr("The shape of the selected object is not a wire."));
00288 return;
00289 }
00290
00291 App::DocumentObject* support = sketch->Support.getValue();
00292
00293 openCommand("Make Revolution");
00294 doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::Revolution\",\"%s\")",FeatName.c_str());
00295 doCommand(Doc,"App.activeDocument().%s.Sketch = App.activeDocument().%s",FeatName.c_str(),sketch->getNameInDocument());
00296 doCommand(Doc,"App.activeDocument().%s.Axis = App.Vector(0,1,0)",FeatName.c_str());
00297 doCommand(Doc,"App.activeDocument().%s.Angle = 360.0",FeatName.c_str());
00298 updateActive();
00299 if (isActiveObjectValid()) {
00300 doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",sketch->getNameInDocument());
00301 if (support)
00302 doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",support->getNameInDocument());
00303 }
00304 doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
00305
00306 if (support) {
00307 copyVisual(FeatName.c_str(), "ShapeColor", support->getNameInDocument());
00308 copyVisual(FeatName.c_str(), "LineColor", support->getNameInDocument());
00309 copyVisual(FeatName.c_str(), "PointColor", support->getNameInDocument());
00310 }
00311 }
00312
00313 bool CmdPartDesignRevolution::isActive(void)
00314 {
00315 return hasActiveDocument();
00316 }
00317
00318
00319
00320
00321 DEF_STD_CMD_A(CmdPartDesignFillet);
00322
00323 CmdPartDesignFillet::CmdPartDesignFillet()
00324 :Command("PartDesign_Fillet")
00325 {
00326 sAppModule = "PartDesign";
00327 sGroup = QT_TR_NOOP("PartDesign");
00328 sMenuText = QT_TR_NOOP("Fillet");
00329 sToolTipText = QT_TR_NOOP("Make a fillet on an edge, face or body");
00330 sWhatsThis = sToolTipText;
00331 sStatusTip = sToolTipText;
00332 sPixmap = "Part_Fillet";
00333 }
00334
00335 void CmdPartDesignFillet::activated(int iMsg)
00336 {
00337 std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
00338
00339 if (selection.size() != 1) {
00340 QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
00341 QObject::tr("Select an edge, face or body. Only one body is allowed."));
00342 return;
00343 }
00344
00345 if (!selection[0].isObjectTypeOf(Part::Feature::getClassTypeId())){
00346 QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong object type"),
00347 QObject::tr("Fillet works only on parts"));
00348 return;
00349 }
00350 std::string SelString = selection[0].getAsPropertyLinkSubString();
00351 std::string FeatName = getUniqueObjectName("Fillet");
00352
00353 openCommand("Make Fillet");
00354 doCommand(Doc,"App.activeDocument().addObject(\"PartDesign::Fillet\",\"%s\")",FeatName.c_str());
00355 doCommand(Doc,"App.activeDocument().%s.Base = %s",FeatName.c_str(),SelString.c_str());
00356 doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",selection[0].getFeatName());
00357 doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
00358
00359 copyVisual(FeatName.c_str(), "ShapeColor", selection[0].getFeatName());
00360 copyVisual(FeatName.c_str(), "LineColor", selection[0].getFeatName());
00361 copyVisual(FeatName.c_str(), "PointColor", selection[0].getFeatName());
00362 }
00363
00364 bool CmdPartDesignFillet::isActive(void)
00365 {
00366 return hasActiveDocument();
00367 }
00368
00369
00370
00371
00372 DEF_STD_CMD_A(CmdPartDesignChamfer);
00373
00374 CmdPartDesignChamfer::CmdPartDesignChamfer()
00375 :Command("PartDesign_Chamfer")
00376 {
00377 sAppModule = "PartDesign";
00378 sGroup = QT_TR_NOOP("Part");
00379 sMenuText = QT_TR_NOOP("Chamfer...");
00380 sToolTipText = QT_TR_NOOP("Chamfer the selected edges of a shape");
00381 sWhatsThis = sToolTipText;
00382 sStatusTip = sToolTipText;
00383 sPixmap = "Part_Chamfer";
00384 }
00385
00386 void CmdPartDesignChamfer::activated(int iMsg)
00387 {
00388 Gui::Control().showDialog(new PartDesignGui::TaskChamfer());
00389 }
00390
00391 bool CmdPartDesignChamfer::isActive(void)
00392 {
00393 return (hasActiveDocument() && !Gui::Control().activeDialog());
00394 }
00395
00396
00397 void CreatePartDesignCommands(void)
00398 {
00399 Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
00400
00401 rcCmdMgr.addCommand(new CmdPartDesignPad());
00402 rcCmdMgr.addCommand(new CmdPartDesignPocket());
00403 rcCmdMgr.addCommand(new CmdPartDesignRevolution());
00404 rcCmdMgr.addCommand(new CmdPartDesignFillet());
00405
00406 rcCmdMgr.addCommand(new CmdPartDesignChamfer());
00407 }