Sketcher: /Mod/Sketcher python code black formatted

This commit is contained in:
Abdullah Tahiri
2023-05-25 15:18:51 +02:00
committed by abdullahtahiriyo
parent 96acbaf252
commit 233a337ca5
6 changed files with 116 additions and 95 deletions

View File

@@ -1,26 +1,26 @@
#***************************************************************************
#* Copyright (c) 2001,2002 Juergen Riegel <juergen.riegel@web.de> *
#* *
#* This file is part of the FreeCAD CAx development system. *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
#* as published by the Free Software Foundation; either version 2 of *
#* the License, or (at your option) any later version. *
#* for detail see the LICENCE text file. *
#* *
#* FreeCAD 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 Lesser General Public License for more details. *
#* *
#* You should have received a copy of the GNU Library General Public *
#* License along with FreeCAD; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#***************************************************************************/
# ***************************************************************************
# * Copyright (c) 2001,2002 Juergen Riegel <juergen.riegel@web.de> *
# * *
# * This file is part of the FreeCAD CAx development system. *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * FreeCAD 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 Lesser General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with FreeCAD; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************/
# FreeCAD init script of the Sketcher module
FreeCAD.__unit_test__ += [ "TestSketcherApp" ]
FreeCAD.__unit_test__ += ["TestSketcherApp"]

View File

@@ -1,25 +1,25 @@
#***************************************************************************
#* Copyright (c) 2002,2003 Juergen Riegel <juergen.riegel@web.de> *
#* *
#* This file is part of the FreeCAD CAx development system. *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
#* as published by the Free Software Foundation; either version 2 of *
#* the License, or (at your option) any later version. *
#* for detail see the LICENCE text file. *
#* *
#* FreeCAD 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 Lesser General Public License for more details. *
#* *
#* You should have received a copy of the GNU Library General Public *
#* License along with FreeCAD; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#***************************************************************************/
# ***************************************************************************
# * Copyright (c) 2002,2003 Juergen Riegel <juergen.riegel@web.de> *
# * *
# * This file is part of the FreeCAD CAx development system. *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * FreeCAD 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 Lesser General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with FreeCAD; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************/
# Sketcher gui init module
#
@@ -27,10 +27,15 @@
# This is the second one of three init scripts, the third one
# runs when the gui is up
class SketcherWorkbench ( Workbench ):
class SketcherWorkbench(Workbench):
"Sketcher workbench object"
def __init__(self):
self.__class__.Icon = FreeCAD.getResourceDir() + "Mod/Sketcher/Resources/icons/SketcherWorkbench.svg"
self.__class__.Icon = (
FreeCAD.getResourceDir()
+ "Mod/Sketcher/Resources/icons/SketcherWorkbench.svg"
)
self.__class__.MenuText = "Sketcher"
self.__class__.ToolTip = "Sketcher workbench"
@@ -47,6 +52,7 @@ class SketcherWorkbench ( Workbench ):
def GetClassName(self):
return "SketcherGui::Workbench"
Gui.addWorkbench(SketcherWorkbench())
FreeCAD.__unit_test__ += [ "TestSketcherGui" ]
FreeCAD.__unit_test__ += ["TestSketcherGui"]

View File

@@ -1,23 +1,23 @@
#***************************************************************************
#* Copyright (c) 2014 Juergen Riegel <FreeCAD@juergen-riegel.net> *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
#* as published by the Free Software Foundation; either version 2 of *
#* the License, or (at your option) any later version. *
#* for detail see the LICENCE text file. *
#* *
#* This program 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 program; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#***************************************************************************
# ***************************************************************************
# * Copyright (c) 2014 Juergen Riegel <FreeCAD@juergen-riegel.net> *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * This program 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 program; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
import FreeCAD
@@ -25,11 +25,11 @@ if FreeCAD.GuiUp:
import FreeCADGui
from PySide import QtCore
#s=os.path.dirname(__file__)
#s=os.path.join(s,"ProfileLib")
#FreeCADGui.addIconPath(s)
# s=os.path.dirname(__file__)
# s=os.path.join(s,"ProfileLib")
# FreeCADGui.addIconPath(s)
__title__="Sketcher profile lib handling"
__title__ = "Sketcher profile lib handling"
__author__ = "Juergen Riegel"
__url__ = "http://www.freecad.org"
@@ -37,30 +37,41 @@ __url__ = "http://www.freecad.org"
def isProfileActive():
return not FreeCAD.ActiveDocument is None
def getSketch():
edit = FreeCADGui.ActiveDocument.getInEdit()
if edit and edit.isDerivedFrom('SketcherGui::ViewProviderSketch'):
if edit and edit.isDerivedFrom("SketcherGui::ViewProviderSketch"):
return edit.Object
#act = FreeCAD.ActiveDocument.ActiveObject
#if act and act.isDerivedFrom('Sketcher::SketchObject'):
# 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_ProfilesHexagon1',
'MenuText': QtCore.QT_TRANSLATE_NOOP("Sketcher_ProfilesHexagon1","Creates a hexagonal profile"),
'Accel': "",
'CmdType': "ForEdit",
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Sketcher_ProfilesHexagon1","Creates a hexagonal profile in the sketch")}
return {
"Pixmap": "Sketcher_ProfilesHexagon1",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"Sketcher_ProfilesHexagon1", "Creates a hexagonal profile"
),
"Accel": "",
"CmdType": "ForEdit",
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"Sketcher_ProfilesHexagon1", "Creates a hexagonal profile in the sketch"
),
}
def Activated(self):
FreeCAD.ActiveDocument.openTransaction("Create hexagon profile")
FreeCADGui.addModule("ProfileLib.Hexagon")
sketch = getSketch()
if not sketch is None:
FreeCADGui.doCommand("ProfileLib.Hexagon.makeHexagonSimple('%s')" % (sketch.Name))
FreeCADGui.doCommand(
"ProfileLib.Hexagon.makeHexagonSimple('%s')" % (sketch.Name)
)
else:
FreeCADGui.doCommand("ProfileLib.Hexagon.makeHexagonSimple()")
FreeCAD.ActiveDocument.recompute()
@@ -69,4 +80,4 @@ class _CommandProfileHexagon1:
return isProfileActive()
FreeCADGui.addCommand('Sketcher_ProfilesHexagon1',_CommandProfileHexagon1())
FreeCADGui.addCommand("Sketcher_ProfilesHexagon1", _CommandProfileHexagon1())

View File

@@ -10,22 +10,26 @@ EndPoint = 2
MiddlePoint = 3
# create a document and a Sketch object
if(App.activeDocument() is None):App.newDocument()
if App.activeDocument() is None:
App.newDocument()
f = App.activeDocument().addObject("Sketcher::SketchObject","Sketch")
f = App.activeDocument().addObject("Sketcher::SketchObject", "Sketch")
# add geometry to the sketch
f.Geometry = [LineSegment(Vector(0,0,0),Vector(2,20,0)),LineSegment(Vector(0,0,0),Vector(20,2,0))]
f.Geometry = [
LineSegment(Vector(0, 0, 0), Vector(2, 20, 0)),
LineSegment(Vector(0, 0, 0), Vector(20, 2, 0)),
]
# add constraints to the sketch
f.Constraints = [Constraint('Vertical',0),Constraint('Horizontal',1)]
f.Constraints = [Constraint("Vertical", 0), Constraint("Horizontal", 1)]
# recompute (solving) the sketch
App.activeDocument().recompute()
# add another constraint to tie the start points together
l = f.Constraints
l.append(Constraint('Coincident',0,StartPoint,1,StartPoint))
l.append(Constraint("Coincident", 0, StartPoint, 1, StartPoint))
f.Constraints = l
# again recompute

View File

@@ -1,4 +1,4 @@
#**************************************************************************
# **************************************************************************
# Copyright (c) 2011 Juergen Riegel <FreeCAD@juergen-riegel.net> *
# Copyright (c) 2021 Emmanuel O'Brien *
# *
@@ -19,7 +19,7 @@
# License along with FreeCAD; if not, write to the Free Software *
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# USA *
#**************************************************************************
# **************************************************************************
# Broken-out test modules
from SketcherTests.TestSketcherSolver import TestSketcherSolver

View File

@@ -1,4 +1,4 @@
#**************************************************************************
# **************************************************************************
# Copyright (c) 2011 Juergen Riegel <FreeCAD@juergen-riegel.net> *
# *
# This file is part of the FreeCAD CAx development system. *
@@ -18,17 +18,17 @@
# License along with FreeCAD; if not, write to the Free Software *
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# USA *
#**************************************************************************
# **************************************************************************
#import FreeCAD, FreeCADGui, os, sys, unittest, Sketcher, SketcherGui
# import FreeCAD, FreeCADGui, os, sys, unittest, Sketcher, SketcherGui
#---------------------------------------------------------------------------
# ---------------------------------------------------------------------------
# define the test cases to test the FreeCAD Sketcher module
#---------------------------------------------------------------------------
# ---------------------------------------------------------------------------
#class SketcherGuiTestCases(unittest.TestCase):
# class SketcherGuiTestCases(unittest.TestCase):
# def setUp(self):
# self.Doc = FreeCAD.newDocument("SketchGuiTest")
#