File size: 7,088 Bytes
985c397 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | # SPDX-License-Identifier: LGPL-2.1-or-later
#***************************************************************************
#* Copyright (c) 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 *
#* *
#***************************************************************************/
# OpenSCAD gui init module
#
# Gathering all the information to start FreeCAD
# This is the second one of three init scripts, the third one
# runs when the gui is up
import FreeCAD
import sys
class OpenSCADWorkbench(Workbench):
"OpenSCAD workbench object"
def __init__(self):
self.__class__.Icon = (
FreeCAD.getResourceDir()
+ "Mod/OpenSCAD/Resources/icons/OpenSCADWorkbench.svg"
)
self.__class__.MenuText = "OpenSCAD"
self.__class__.ToolTip = (
"OpenSCAD is an application for creating solid 3D CAD.\n"
"FreeCAD utizes OpenSCAD's capability as a script-only based modeller that uses its own description language\n"
"Note: the Mesh workbench heavily uses the boolean operations of this workbench because they are quite robust"
)
def Initialize(self):
def QT_TRANSLATE_NOOP(scope, text):
return text
import OpenSCAD_rc, OpenSCADCommands
commands = [
"OpenSCAD_ReplaceObject",
"OpenSCAD_RemoveSubtree",
"OpenSCAD_RefineShapeFeature",
"OpenSCAD_MirrorMeshFeature",
"OpenSCAD_ScaleMeshFeature",
"OpenSCAD_ResizeMeshFeature",
"OpenSCAD_IncreaseToleranceFeature",
"OpenSCAD_Edgestofaces",
"OpenSCAD_ExpandPlacements",
"OpenSCAD_ExplodeGroup",
]
toolbarcommands = [
"OpenSCAD_ReplaceObject",
"OpenSCAD_RemoveSubtree",
"OpenSCAD_ExplodeGroup",
"OpenSCAD_RefineShapeFeature",
"OpenSCAD_IncreaseToleranceFeature",
]
import PartGui
parttoolbarcommands = [
"Part_CheckGeometry",
"Part_Primitives",
"Part_Builder",
"Part_Cut",
"Part_Fuse",
"Part_Common",
"Part_Extrude",
"Part_Revolve",
]
import FreeCAD
translate = FreeCAD.Qt.translate
param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/OpenSCAD")
openscadfilename = param.GetString("openscadexecutable")
if not openscadfilename:
import OpenSCADUtils
openscadfilename = OpenSCADUtils.searchforopenscadexe()
if openscadfilename: # automatic search was successful
FreeCAD.addImportType("OpenSCAD Format (*.scad *.SCAD)", "importCSG")
param.SetString(
"openscadexecutable", openscadfilename
) # save the result
if openscadfilename:
commands.extend(
[
"OpenSCAD_AddOpenSCADElement",
"OpenSCAD_MeshBoolean",
"OpenSCAD_Hull",
"OpenSCAD_Minkowski",
]
)
toolbarcommands.extend(
[
"OpenSCAD_AddOpenSCADElement",
"OpenSCAD_MeshBoolean",
"OpenSCAD_Hull",
"OpenSCAD_Minkowski",
]
)
else:
FreeCAD.Console.PrintWarning("OpenSCAD executable not found\n")
transferMechanism = param.GetInt("transfermechanism", 0)
if openscadfilename and transferMechanism == 0:
# We are using the Python temp-directory creation function
if "snap" in openscadfilename:
FreeCAD.Console.PrintMessage(
translate(
"OpenSCAD",
"It looks like you may be using a Snap version of OpenSCAD.",
)
+ " "
+ translate(
"OpenSCAD",
"If OpenSCAD execution fails to load the temporary file, use FreeCAD's OpenSCAD Workbench Preferences to change the transfer mechanism.",
)
+ "\n"
)
elif sys.executable.startswith("/tmp/"): # Heuristic for AppImages
FreeCAD.Console.PrintMessage(
translate(
"OpenSCAD",
"It looks like you may be using a sandboxed version of FreeCAD.",
)
+ " "
+ translate(
"OpenSCAD",
"If OpenSCAD execution fails to load the temporary file, use FreeCAD's OpenSCAD Workbench Preferences to change the transfer mechanism.",
)
+ "\n"
)
self.appendToolbar(
QT_TRANSLATE_NOOP("Workbench", "OpenSCAD Tools"), toolbarcommands
)
self.appendMenu("OpenSCAD", commands)
self.appendToolbar(
QT_TRANSLATE_NOOP("Workbench", "Frequently-used Part WB tools"), parttoolbarcommands
)
FreeCADGui.addIconPath(":/icons")
FreeCADGui.addLanguagePath(":/translations")
FreeCADGui.addPreferencePage(":/ui/openscadprefs-base.ui", "OpenSCAD")
def GetClassName(self):
return "Gui::PythonWorkbench"
Gui.addWorkbench(OpenSCADWorkbench())
# Not all of the GUI tests will require an OpenSCAD binary (CSG import and export don't)
FreeCAD.__unit_test__ += ["TestOpenSCADGui"]
|