+ implement hexagon sketch
This commit is contained in:
@@ -778,6 +778,21 @@ PythonCommand::PythonCommand(const char* name,PyObject * pcPyCommand, const char
|
||||
// check if the "GetResources()" method returns a Dict object
|
||||
if (!PyDict_Check(_pcPyResourceDict))
|
||||
throw Base::Exception("PythonCommand::PythonCommand(): Method GetResources() of the Python command object returns the wrong type (has to be Py Dictonary)");
|
||||
|
||||
// check for command type
|
||||
std::string cmdType = getResource("CmdType");
|
||||
if (!cmdType.empty()) {
|
||||
int type = 0;
|
||||
if (cmdType.find("AlterDoc") != std::string::npos)
|
||||
type += int(AlterDoc);
|
||||
if (cmdType.find("Alter3DView") != std::string::npos)
|
||||
type += int(Alter3DView);
|
||||
if (cmdType.find("AlterSelection") != std::string::npos)
|
||||
type += int(AlterSelection);
|
||||
if (cmdType.find("ForEdit") != std::string::npos)
|
||||
type += int(ForEdit);
|
||||
eType = type;
|
||||
}
|
||||
}
|
||||
|
||||
const char* PythonCommand::getResource(const char* sName) const
|
||||
@@ -796,7 +811,7 @@ const char* PythonCommand::getResource(const char* sName) const
|
||||
|
||||
void PythonCommand::activated(int iMsg)
|
||||
{
|
||||
if (Activation == "") {
|
||||
if (Activation.empty()) {
|
||||
try {
|
||||
Interpreter().runMethodVoid(_pcPyCommand, "Activated");
|
||||
}
|
||||
|
||||
@@ -36,6 +36,14 @@
|
||||
</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="getInEdit">
|
||||
<Documentation>
|
||||
<UserDocu>
|
||||
getInEdit()
|
||||
Returns the current object in edit mode or None if there is no such object
|
||||
</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="resetEdit">
|
||||
<Documentation>
|
||||
<UserDocu>
|
||||
|
||||
@@ -119,6 +119,19 @@ PyObject* DocumentPy::setEdit(PyObject *args)
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* DocumentPy::getInEdit(PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
return NULL;
|
||||
|
||||
ViewProvider* vp = getDocumentPtr()->getInEdit();
|
||||
if (vp) {
|
||||
return vp->getPyObject();
|
||||
}
|
||||
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* DocumentPy::resetEdit(PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ";No arguments allowed")) // convert args: Python->C
|
||||
|
||||
@@ -61,7 +61,7 @@ SET(SketcherGui_SRCS
|
||||
Command.cpp
|
||||
CommandCreateGeo.cpp
|
||||
CommandConstraints.cpp
|
||||
CommandAlterGeometry.cpp
|
||||
CommandAlterGeometry.cpp
|
||||
Resources/Sketcher.qrc
|
||||
PreCompiled.cpp
|
||||
PreCompiled.h
|
||||
@@ -103,7 +103,7 @@ SET(SketcherGui_SRCS
|
||||
|
||||
SET(SketcherGui_Scripts
|
||||
InitGui.py
|
||||
TestSketcherGui.py
|
||||
TestSketcherGui.py
|
||||
)
|
||||
|
||||
add_library(SketcherGui SHARED ${SketcherGui_SRCS})
|
||||
|
||||
@@ -20,14 +20,44 @@
|
||||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
import FreeCAD, FreeCADGui, Sketcher
|
||||
import FreeCAD, FreeCADGui, Sketcher, Part
|
||||
|
||||
|
||||
__title__="Hexagon profile lib"
|
||||
__author__ = "Juergen Riegel"
|
||||
__url__ = "http://www.freecadweb.org"
|
||||
|
||||
App = FreeCAD
|
||||
Gui = FreeCADGui
|
||||
|
||||
def makeHexagonSimple():
|
||||
def makeHexagonSimple(sketchName=None):
|
||||
if not sketchName:
|
||||
sketch = App.ActiveDocument.addObject("Sketcher::SketchObject","Hexagon")
|
||||
else:
|
||||
sketch = App.ActiveDocument.getObject(sketchName)
|
||||
|
||||
l1=sketch.addGeometry(Part.Line(App.Vector(-20.00,34.64,0),App.Vector(20.00,34.64,0)))
|
||||
l2=sketch.addGeometry(Part.Line(App.Vector(20.00,34.64,0),App.Vector(47.082363,0.00,0)))
|
||||
sketch.addConstraint(Sketcher.Constraint('Coincident',l1,2,l2,1))
|
||||
l3=sketch.addGeometry(Part.Line(App.Vector(40.00,0.00,0),App.Vector(20.00,-34.64,0)))
|
||||
sketch.addConstraint(Sketcher.Constraint('Coincident',l2,2,l3,1))
|
||||
l4=sketch.addGeometry(Part.Line(App.Vector(20.00,-34.64,0),App.Vector(-20.00,-34.64,0)))
|
||||
sketch.addConstraint(Sketcher.Constraint('Coincident',l3,2,l4,1))
|
||||
l5=sketch.addGeometry(Part.Line(App.Vector(-20.00,-34.64,0),App.Vector(-40.00,0.00,0)))
|
||||
sketch.addConstraint(Sketcher.Constraint('Coincident',l4,2,l5,1))
|
||||
l6=sketch.addGeometry(Part.Line(App.Vector(-40.00,0.00,0),App.Vector(-20.00,34.64,0)))
|
||||
sketch.addConstraint(Sketcher.Constraint('Coincident',l5,2,l6,1))
|
||||
sketch.addConstraint(Sketcher.Constraint('Coincident',l6,2,l1,1))
|
||||
sketch.addConstraint(Sketcher.Constraint('Equal',l1,l2))
|
||||
sketch.addConstraint(Sketcher.Constraint('Equal',l2,l3))
|
||||
sketch.addConstraint(Sketcher.Constraint('Equal',l3,l4))
|
||||
sketch.addConstraint(Sketcher.Constraint('Equal',l4,l5))
|
||||
sketch.addConstraint(Sketcher.Constraint('Equal',l5,l6))
|
||||
a1=sketch.addConstraint(Sketcher.Constraint('Angle',l1,2,l2,1,2.0943951023931953))
|
||||
sketch.setDatum(a1,App.Units.Quantity('120.000000 deg'))
|
||||
a2=sketch.addConstraint(Sketcher.Constraint('Angle',l3,2,l4,1,2.0943951023931953))
|
||||
sketch.setDatum(a2,App.Units.Quantity('120.000000 deg'))
|
||||
a3=sketch.addConstraint(Sketcher.Constraint('Angle',l5,2,l6,1,2.0943951023931953))
|
||||
sketch.setDatum(a3,App.Units.Quantity('120.000000 deg'))
|
||||
return
|
||||
|
||||
|
||||
@@ -23,12 +23,16 @@
|
||||
import FreeCAD, Sketcher
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
import FreeCADGui,SketcherGui
|
||||
import FreeCADGui,SketcherGui,os
|
||||
from PySide import QtCore, QtGui
|
||||
from PySide.QtCore import Qt
|
||||
from PySide.QtGui import QApplication, QCursor
|
||||
from FreeCADGui import PySideUic as uic
|
||||
|
||||
#s=os.path.dirname(__file__)
|
||||
#s=os.path.join(s,"ProfileLib")
|
||||
#FreeCADGui.addIconPath(s)
|
||||
|
||||
__title__="Sketcher profile lib handling"
|
||||
__author__ = "Juergen Riegel"
|
||||
__url__ = "http://www.freecadweb.org"
|
||||
@@ -37,19 +41,33 @@ __url__ = "http://www.freecadweb.org"
|
||||
def isProfileActive():
|
||||
return not FreeCAD.ActiveDocument is None
|
||||
|
||||
def getSketch():
|
||||
edit = FreeCADGui.ActiveDocument.getInEdit()
|
||||
if edit and edit.isDerivedFrom('SketcherGui::ViewProviderSketch'):
|
||||
return edit.Object
|
||||
#act = FreeCAD.ActiveDocument.ActiveObject
|
||||
#if act and act.isDerivedFrom('Sketcher::SketchObject'):
|
||||
# return act
|
||||
return None
|
||||
|
||||
class _CommandProfileHexagon1:
|
||||
"The basis hexagon profile command definition"
|
||||
def GetResources(self):
|
||||
return {'Pixmap' : 'Sketcher_Hexagon',
|
||||
'MenuText': QtCore.QT_TRANSLATE_NOOP("Sketcher_ProfilesHexagon1","Creates a hexagon profile"),
|
||||
'Accel': "",
|
||||
'CmdType': "ForEdit",
|
||||
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Sketcher_ProfilesHexagon1","Creates a hexagon profile in the sketch")}
|
||||
|
||||
def Activated(self):
|
||||
|
||||
FreeCAD.ActiveDocument.openTransaction("Create hexagon profile")
|
||||
FreeCADGui.addModule("ProfileLib.Hexagon")
|
||||
FreeCADGui.doCommand("ProfileLib.Hexagon.makeHexagonSimple()")
|
||||
sketch = getSketch()
|
||||
if not sketch is None:
|
||||
FreeCADGui.doCommand("ProfileLib.Hexagon.makeHexagonSimple('%s')" % (sketch.Name))
|
||||
else:
|
||||
FreeCADGui.doCommand("ProfileLib.Hexagon.makeHexagonSimple()")
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
|
||||
def IsActive(self):
|
||||
return isProfileActive()
|
||||
|
||||
Reference in New Issue
Block a user