~freecad-community/freecad-extras/kicad-stepup-tools-manual

« back to all changes in this revision

Viewing changes to kicad-StepUp-tools.FCMacro

  • Committer: Abdullah Tahiri
  • Date: 2016-03-04 18:47:49 UTC
  • Revision ID: abdullahtahiriyo@gmail.com-20160304184749-vuu9gnzlsxk918gs
improved version

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf8 -*-
2
 
#* this macro rotates, translates and scales one object                     *
3
 
#* scale for VRML export and open footprint for easy alignement             *
4
 
#* this sw is a part of kicad StepUp code                                   *
5
 
#* all credits and licence details in kicad StepUp code                     *
6
 
#* Macro_Move_Rotate_Scale                                                  *
7
 
#* ver in ___ver___                                                         *
8
 
#*   Copyright (c) 2015                                                     *
9
 
#*   Maurice easyw@katamail.com                                             *
10
 
#*                                                                          *
11
 
#*   Collisions routines from Highlight Common parts Macro                  *
12
 
#*   author JMG, galou and other contributors                               *
 
1
#!/usr/bin/python
 
2
# -*- coding: utf-8 -*-
 
3
#****************************************************************************
 
4
#*                                                                          *
 
5
#*  Kicad STEPUP (TM) (3D kicad board and models to STEP) for FreeCAD       *
 
6
#*  3D exporter for FreeCAD                                                 *
 
7
#*  Kicad STEPUP TOOLS (TM) (3D kicad board and models to STEP) for FreeCAD *
 
8
#*  Copyright (c) 2015                                                      *
 
9
#*  Maurice easyw@katamail.com                                              *
 
10
#*                                                                          *
 
11
#*  Kicad STEPUP (TM) is a TradeMark and cannot be freely useable           *
 
12
#*                                                                          *
 
13
#*   code partially based on:                                               *
 
14
#*      Printed Circuit Board Workbench for FreeCAD  FreeCAD-PCB            *
 
15
#*      Copyright (c) 2013, 2014, 2015                                      *
 
16
#*      marmni <marmni@onet.eu>                                             *
 
17
#*                                                                          *
 
18
#*      and IDF import for FreeCAD                                          *
 
19
#*      (c) Milos Koutny (milos.koutny@gmail.com) 2012                      *
 
20
#*      and (c) hyOzd ecad-3d-model-generator                               *
 
21
#*                                                                          *
 
22
#*   this macro rotates, translates and scales one object                   *
 
23
#*   scale for VRML export and open footprint for easy alignement           *
 
24
#*   this sw is a part of kicad StepUp code                                 *
 
25
#*   all credits and licence details in kicad StepUp code                   *
 
26
#*   Macro_Move_Rotate_Scale                                                *
 
27
#*   ver in ___ver___                                                       *
 
28
#*     Copyright (c) 2015                                                   *
 
29
#*     Maurice easyw@katamail.com                                           *
 
30
#*                                                                          *
 
31
#*     Collisions routines from Highlight Common parts Macro                *
 
32
#*     author JMG, galou and other contributors                             *
 
33
#*                                                                          *
 
34
#* IDF_ImporterVersion="3.9.2"
 
35
#*  ignoring step search associations (too old models)
 
36
#*  displaying Flat Mode models
 
37
#*  checking version 3 for both Geometry and Part Number
 
38
#*  supporting Z position
 
39
#*  skipping PROP in emp file
 
40
#*  adding color to shapes opt IDF_colorize
 
41
#*  adding emp library/single model load support
 
42
#*  aligning IDF shape to both Geom and PartNBR for exactly match
 
43
#*  to do: .ROUTE_OUTLINE ECAD, .PLACE_OUTLINE MCAD, .ROUTE_KEPOUT ECAD, .PLACE_KEEPOUT ECAD
 
44
#****************************************************************************
13
45
#*                                                                          *
14
46
#*   This program is free software; you can redistribute it and/or modify   *
15
 
#*   it under the terms of the GNU Lesser General Public License (LGPL)     *
16
 
#*   as published by the Free Software Foundation; either version 2 of      *
17
 
#*   the License, or (at your option) any later version.                    *
 
47
#*   it under the terms of the GNU Affero General Public License            *
 
48
#*   as published by the Free Software Foundation to ensure cooperation     *
 
49
#*   with the community in the case of network server software;             *
18
50
#*   for detail see the LICENCE text file.                                  *
 
51
#*   http://www.gnu.org/licenses/agpl-3.0.en.html                           *
19
52
#*   Moreover you have to include the original author copyright             *
20
53
#*   kicad StepUP made by Maurice easyw@katamail.com                        *
21
54
#*                                                                          *
29
62
#*   Foundation, Inc.,                                                      *
30
63
#*   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA           *
31
64
#*                                                                          *
32
 
#****************************************************************************#
 
65
#****************************************************************************
 
66
##With kicad StepUp you’ll get an exact representation of your physical board in Native 3D PCB
33
67
 
34
 
#todo list
35
 
# collision and proximity as microelly
36
 
# remove test button
 
68
## kicad StepUp tools
 
69
##done
37
70
# upgrade kicadstepup version
38
 
# enable confirm on exit
39
71
# resized font size
40
72
# add bbox and volume images on the starter guide
41
73
# add ksu config more detailed description
42
74
# complete volume_minimum config in doc
43
 
 
44
 
 
45
 
# import statements
46
 
from __future__ import unicode_literals
47
 
 
 
75
# improved OSX QtGui File Open
 
76
# better arc and line import
 
77
##todo list
 
78
# collision and proximity as microelly
 
79
# remove test button
 
80
# enable confirm on exit
 
81
# replace FreeCAD.Console.Message -> say 
 
82
## kicad StepUp
 
83
# added messages on missing emn files
 
84
# added messages on missing models
 
85
# added path to adapt your KISYS3DMOD
 
86
# added blacklist for unwanted modules
 
87
# added messages on blacklisted modules
 
88
# added pcb color attribute
 
89
# added bounding box option
 
90
# added bounding box white list to leave real model on connector or peripheral models
 
91
# added auxorigin, base origin, base point placement option
 
92
# added vrml models z-rotation angle
 
93
# added virtual models option
 
94
# added fusion export option
 
95
# added saving in native format, export to STEP
 
96
# added arcs and circles for calculate board position
 
97
# added idf_to_origin flag for version >6091
 
98
# added reset properties for FC 016 bug
 
99
# added ${KIPRJMOD} support
 
100
# added v3,v4 pcb version support
 
101
# added multi 3D vrml model support
 
102
# added compatibility to kicad version >=3
 
103
# added auto color assigning in bboxes
 
104
# added minimum volume per model
 
105
# added minimum height per model
 
106
# updated findPcbCenter method
 
107
# added support for .stp extension beside .step
 
108
# added support for .igs extension beside .step
 
109
# added support for .iges extension beside .step
 
110
# because of hole sovrapposition prob...
 
111
# cutting hole by hole instead of hole compound
 
112
# added holes_solid var
 
113
# to have holes as solid to garantee cutting
 
114
# handled single circle 
 
115
# used OpenSCAD2Dgeom instead of wire + face (best option)
 
116
# http://www.freecadweb.org/wiki/index.php?title=Macro_Creating_faces_from_a_DXF_file
 
117
# fixed unicode text parsing
 
118
# double option .kicad_pcb .emn
 
119
# in case of non coincidences .emn is more tolerant
 
120
# try to build wires on closed shaped for make the cutting faster
 
121
# try to optimize cutting changing creation/type of holes
 
122
# manage bklist and volume
 
123
# accept with or without /\ at the end of 3Dpath
 
124
# search models in KIPRJMOD and in KISYS3DMOD 
 
125
# removed unicode chars in .kicad_pcb
 
126
# exported wrl, step from python
 
127
# reload & display ini cfg file
 
128
# display/edit ini file with syntax highlight
 
129
# msg first ksu config
 
130
# added warning for import step multi part
 
131
# added warning in load footprint and in placing step mod if x,y and scale are different from 0 0 0 and 1 1 1
 
132
# non stopping warning for footprint
 
133
# added command line args to load board(/emn)
 
134
# avoid argv in memory in case of opened from  command line
 
135
# used multi cut also for footprint too
 
136
# enabled loadB, loadI, loadF with filename=None to align Mod and Macro
 
137
# enabled Macro & Mod
 
138
# added ico tools info
 
139
# added checkbox export_2_step
 
140
# added export2STEP var in ini file
 
141
# subst print to say
 
142
# fixed cursor wait
 
143
# most clean code and comments done
 
144
##todo
 
145
 
 
146
# message error for bad config
 
147
# enable upper case configparser optionxform
 
148
# http://stackoverflow.com/questions/19359556/configparser-reads-capital-keys-and-make-them-lower-case
 
149
# use isInside/common ( TopoShape ) to cut only intersection objs
 
150
# multi board
 
151
# evaluate python occ for step exporting without triangulation
 
152
# test option placement
 
153
# check line 772 abs ZMax = height?
 
154
# add checkbox virtual
 
155
# fix fonts for html and new buttons
 
156
# ...
 
157
# try to close non closed wire
 
158
# from Macro_JointWire
 
159
# pad type trapez
 
160
 
 
161
## import statements
 
162
 
 
163
import FreeCAD, FreeCADGui
 
164
 
 
165
import PySide
48
166
from PySide import QtGui, QtCore
 
167
#QtGui.QSyntaxHighlighter, QtGui.QTextCharFormat, QtGui.QBrush
 
168
#https://github.com/JimmXinu/FanFicFare/blob/master/calibre-plugin/basicinihighlighter.py
 
169
#http://fanficdownloader.googlecode.com/hg/calibre-plugin/basicinihighlighter.py
49
170
 
50
171
from time import sleep
51
 
from math import sqrt, tan, atan, atan2, degrees, radians, hypot, sin, cos, pi
52
 
#from math import sqrt, atan2, sin, cos, radians, pi, hypot, atan
53
 
 
54
 
import Draft
55
 
import Part
56
 
 
 
172
from math import sqrt, tan, atan, atan2, degrees, radians, hypot, sin, cos, pi, fmod
 
173
import Draft, Part
 
174
from collections import namedtuple
57
175
from FreeCAD import Base
58
176
import sys, os
 
177
from os.path import expanduser
59
178
import re
 
179
import time
 
180
import OpenSCAD2Dgeom
 
181
import ImportGui
 
182
from math import sqrt, atan, sin, cos, radians, degrees, pi
 
183
 
 
184
import argparse
 
185
import __builtin__
 
186
if FreeCAD.GuiUp:
 
187
    from PySide import QtCore, QtGui
 
188
 
 
189
import OpenSCADFeatures
 
190
#from codecs import open #maui to verify
 
191
#import unicodedata
 
192
 
 
193
 
 
194
pythonopen = __builtin__.open # to distinguish python built-in open function from the one declared here
 
195
 
 
196
## Constant definitions
 
197
___ver___ = "3.0.3.3"  #reviewing FPL 
 
198
__title__ = "kicad_StepUp"
 
199
__author__ = "maurice & mg"
 
200
__Comment__ = 'Kicad STEPUP(TM) (3D kicad board and models exported to STEP) for FreeCAD'
 
201
___ver_ksu___ = "1.0.1.9  25/11/2015 COPIA!!!" 
 
202
IDF_ImporterVersion="3.9.2"
 
203
__Icon__ = "stepup.png"
 
204
 
 
205
global userCancelled, userOK, show_mouse_pos, min_val, last_file_path, resetP
 
206
global start_time, show_messages
 
207
global show_messages
 
208
global real_board_pos_x, real_board_pos_y, board_base_point_x, board_base_point_y
 
209
global ksu_config_fname, ini_content, configFilePath
 
210
global models3D_prefix, blacklisted_model_elements, col, colr, colg, colb
 
211
global bbox, volume_minimum, height_minimum, idf_to_origin, aux_orig
 
212
global base_orig, base_point, bbox_all, bbox_list, whitelisted_model_elements
 
213
global fusion, addVirtual, blacklisted_models, exportFusing, min_drill_size
 
214
global last_fp_path, last_pcb_path, plcmnt, xp, yp, exportFusing
 
215
 
 
216
last_file_path=''
 
217
resetP=True
 
218
global rot_wrl, test_flag, test_flag_pads
 
219
rot_wrl=0.0
 
220
#global module_3D_dir
 
221
userCancelled        = "Cancelled"
 
222
userOK            = "OK"
 
223
show_mouse_pos = True
 
224
#module_3D_dir="C:/Cad/Progetti_K/a_mod"
 
225
min_val=0.001
 
226
conflict_tolerance=1e-6  #volume tolerance
 
227
font_size=8
 
228
bbox_r_col=(0.411765, 0.411765, 0.411765)  #dimgrey
 
229
bbox_c_col=(0.823529, 0.411765, 0.117647)  #chocolate
 
230
bbox_x_col=(0.862745, 0.862745, 0.862745) #gainsboro
 
231
bbox_l_col=(0.333333, 0.333333, 0.333333) #sgidarkgrey
 
232
bbox_IC_col=(0.156863, 0.156863, 0.156863)  #sgiverydarkgrey
 
233
bbox_default_col=(0.439216, 0.501961, 0.564706)  #slategrey
 
234
 
 
235
test_flag=False
 
236
#test_flag=True
 
237
test_flag_exit=False
 
238
test_flag_pads=False
 
239
remove_pcbPad=True
 
240
close_doc=False
 
241
show_border=False
 
242
show_shapes=False 
 
243
disable_cutting=False
 
244
test_extrude=False
 
245
holes_solid=True
 
246
##ignore_utf8=False not used
 
247
emn_version=3.0
 
248
show_messages=True
 
249
#show_messages=False # mauitest
 
250
 
 
251
global export_board_2step
 
252
#export_board_2step=False
 
253
save_temp_data=False
 
254
 
 
255
current_milli_time = lambda: int(round(time.time() * 1000))
 
256
 
 
257
def clear_console():
 
258
    #clearing previous messages
 
259
    mw=FreeCADGui.getMainWindow()
 
260
    c=mw.findChild(QtGui.QPlainTextEdit, "Python console")
 
261
    c.clear()
 
262
    r=mw.findChild(QtGui.QTextEdit, "Report view")
 
263
    r.clear()
 
264
 
 
265
#if not Mod_ENABLED:
 
266
clear_console()
 
267
    
 
268
# points: [Vector, Vector, ...]
 
269
# faces: [(pi, pi, pi), ], pi: point index
 
270
# color: (Red, Green, Blue), values range from 0 to 1.0
 
271
Mesh = namedtuple('Mesh', ['points', 'faces', 'color', 'transp'])
 
272
 
 
273
from sys import platform as _platform
 
274
 
 
275
import ConfigParser
 
276
 
 
277
def insert(filename, other):
 
278
    if os.path.exists(filename):
 
279
        open(filename)
 
280
    else:
 
281
        FreeCAD.Console.PrintError("File does not exist.\n")
 
282
        reply = QtGui.QMessageBox.information(None,"info", "File does not exist.\n")
 
283
 
 
284
def open(filename):
 
285
    #reply = QtGui.QMessageBox.information(None,"info", filename)
 
286
    #onLoadBoard_cmd(filename)
 
287
    ext = os.path.splitext(os.path.basename(filename))[1]
 
288
    if ext==".kicad_pcb":
 
289
        onLoadBoard(filename)
 
290
    elif ext==".emn":
 
291
        onLoadBoard_idf(filename)
 
292
    elif ext==".kicad_mod":
 
293
        onLoadFootprint(filename)
 
294
 
 
295
def say(msg):
 
296
    FreeCAD.Console.PrintMessage(msg)
 
297
 
 
298
def sayw(msg):
 
299
    FreeCAD.Console.PrintWarning(msg)
 
300
    FreeCAD.Console.PrintWarning('\n')
 
301
    
 
302
def sayerr(msg):
 
303
    FreeCAD.Console.PrintError(msg)
 
304
    FreeCAD.Console.PrintWarning('\n')
 
305
 
 
306
def cfgParsWrite(configFilePath):
 
307
    ##ksu pre-set
 
308
    global models3D_prefix, blacklisted_model_elements, col, colr, colg, colb
 
309
    global bbox, volume_minimum, height_minimum, idf_to_origin, aux_orig
 
310
    global base_orig, base_point, bbox_all, bbox_list, whitelisted_model_elements
 
311
    global fusion, addVirtual, blacklisted_models, exportFusing, min_drill_size
 
312
    global last_fp_path, last_pcb_path, plcmnt, xp, yp, exportFusing, export_board_2step
 
313
 
 
314
    configParser.set('last_footprint_path', 'last_fp_path', last_fp_path)
 
315
    configParser.set('last_pcb_path', 'last_pcb_path', last_pcb_path)
 
316
    if export_board_2step:
 
317
        configParser.set('export', 'export_to_step', "yes")
 
318
    else:
 
319
        configParser.set('export', 'export_to_step', "no")
 
320
    #configParser.set('last_fp_path', ';; last footprint file path used')
 
321
    configParser.set('info', default_ksu_msg[0])
 
322
    configParser.set('prefix3D', default_ksu_msg[1])
 
323
    configParser.set('PcbColor', default_ksu_msg[2])
 
324
    configParser.set('Blacklist', default_ksu_msg[3])
 
325
    configParser.set('BoundingBox', default_ksu_msg[4])
 
326
    configParser.set('Placement', default_ksu_msg[5])
 
327
    configParser.set('Virtual', default_ksu_msg[6])
 
328
    configParser.set('ExportFuse', default_ksu_msg[7])
 
329
    configParser.set('minimum_drill_size', default_ksu_msg[8])
 
330
    configParser.set('last_pcb_path', default_ksu_msg[9])
 
331
    configParser.set('last_footprint_path', default_ksu_msg[10])
 
332
    configParser.set('export', default_ksu_msg[11])
 
333
    # save to the config file
 
334
    with __builtin__.open(configFilePath, 'wb') as configfile:
 
335
        configParser.write(configfile)
 
336
    #configFilePath.close() already closed
 
337
###
 
338
    
 
339
    
 
340
def cfgParsRead(configFilePath):
 
341
    ##ksu pre-set
 
342
    global models3D_prefix, blacklisted_model_elements, col, colr, colg, colb
 
343
    global bbox, volume_minimum, height_minimum, idf_to_origin, aux_orig
 
344
    global base_orig, base_point, bbox_all, bbox_list, whitelisted_model_elements
 
345
    global fusion, addVirtual, blacklisted_models, exportFusing, min_drill_size
 
346
    global last_fp_path, last_pcb_path, plcmnt, xp, yp, exportFusing, export_board_2step
 
347
    #cfg_parameters=[]
 
348
    models3D_prefix = ''
 
349
    blacklisted_model_elements=''
 
350
    #col=''; col='0.0,0.5,0.0,green';  # color
 
351
    col=''; col='0.0,0.0,1.0,blue';  # color
 
352
    bbox=0
 
353
    #(0.6,0.4,0.2) brown
 
354
    volume_minimum=0 #0.8  ##1 #mm^3, 0 skipped #global var default
 
355
    height_minimum=0 #0.8  ##1 #mm, 0 skipped   #global var default
 
356
    ## to debug quickly put show_messages=False
 
357
    ### from release 6091 this flag enables the option to place IDF exported to origin
 
358
    idf_to_origin=True
 
359
    #idf_to_origin=False
 
360
    aux_orig=0;base_orig=0;base_point=0
 
361
    bbox_all=0; bbox_list=0; whitelisted_model_elements=''
 
362
    fusion=False; addVirtual=0
 
363
    configParser.read(configFilePath)
 
364
    models3D_prefix = configParser.get('prefix3D', 'prefix3D_1')
 
365
    if not models3D_prefix.endswith('/'):
 
366
        if not models3D_prefix.endswith('\\'):
 
367
            models3D_prefix+='/'
 
368
    #say(models3D_prefix+'\n')
 
369
    pcb_color = configParser.get('PcbColor', 'pcb_color')
 
370
    bklist = configParser.get('Blacklist', 'bklist')
 
371
    bbox_opt = configParser.get('BoundingBox', 'bbox')
 
372
    plcmnt = configParser.get('Placement', 'placement')
 
373
    virtual = configParser.get('Virtual', 'virt')
 
374
    exportFusing = configParser.get('ExportFuse', 'exportFusing')
 
375
    min_drill_size = float(configParser.get('minimum_drill_size', 'min_drill_size'))
 
376
    last_pcb_path = configParser.get('last_pcb_path', 'last_pcb_path')
 
377
    last_fp_path = configParser.get('last_footprint_path', 'last_fp_path') 
 
378
    export2S = configParser.get('export', 'export_to_STEP') 
 
379
    if "yes" in export2S:
 
380
        export_board_2step=True
 
381
    else:
 
382
        export_board_2step=False
 
383
    if bklist.find('none') !=-1:
 
384
        blacklisted_model_elements=''
 
385
    elif bklist.find('volume') !=-1:
 
386
        vval=bklist.strip('\r\n')
 
387
        vvalue=vval.split("=")
 
388
        volume_minimum=float(vvalue[1])
 
389
        #reply = QtGui.QMessageBox.information(None,"info ...","volume "+str(volume_minimum))
 
390
    elif bklist.find('height') !=-1:
 
391
        vval=bklist.strip('\r\n')
 
392
        vvalue=vval.split("=")
 
393
        height_minimum=float(vvalue[1])
 
394
        #reply = QtGui.QMessageBox.information(None,"info ...","height "+str(height_minimum))
 
395
    else:
 
396
        blacklisted_model_elements=bklist.strip('\r\n')
 
397
        blacklisted_models=blacklisted_model_elements.split(",")
 
398
    col=pcb_color.strip('\r\n')
 
399
    if bbox_opt.upper().find('ALL') !=-1:
 
400
        bbox_all=1
 
401
        whitelisted_model_elements=''
 
402
    else:
 
403
        if bbox_opt.upper().find('LIST') !=-1:
 
404
            bbox_list=1
 
405
            whitelisted_model_elements=bbox_opt.strip('\r\n')
 
406
            #whitelisted_models=whitelisted_model_elements.split(",")        
 
407
    if plcmnt.find('AuxOrigin') !=-1:
 
408
        aux_orig=1
 
409
        #whitelisted_model_elements=''
 
410
    if plcmnt.find('BaseOrigin') !=-1:
 
411
        base_orig=1
 
412
    if plcmnt.find('BasePoint') !=-1:
 
413
        base_point=1
 
414
        basepoint=plcmnt.strip('\r\n')
 
415
        coords_BP=basepoint.split(";")
 
416
        xp=float(coords_BP[1]);yp=float(coords_BP[2])
 
417
    if plcmnt.find('AutoAdjust') !=-1:
 
418
        idf_to_origin=False
 
419
    if virtual.lower().find('addvirtual') !=-1:
 
420
        addVirtual=1
 
421
    if exportFusing.lower().find('fuseall') !=-1:
 
422
        fusion=True
 
423
    say('3D models prefix='+models3D_prefix+'\rpcb color='+col+'\r')
 
424
    #cfg_parameters.append(models3D_prefix)
 
425
    #cfg_parameters.append(col)
 
426
    say('blacklist modules '+blacklisted_model_elements+'\r')
 
427
    #cfg_parameters.append(blacklisted_model_elements)
 
428
    say('volume '+str(volume_minimum)+' heigh '+str(height_minimum)+'\r')
 
429
    #cfg_parameters.append(volume_minimum)
 
430
    say('bounding box option '+str(bbox_all)+' whitelist '+whitelisted_model_elements+'\r')
 
431
    #cfg_parameters.append(bbox_all);cfg_parameters.append(whitelisted_model_elements)
 
432
    say('placement board @ '+plcmnt+'\r')
 
433
    say('last fp path '+last_fp_path+'\r')
 
434
    say('last brd path '+last_pcb_path+'\r')
 
435
    #cfg_parameters.append(plcmnt);cfg_parameters.append(last_fp_path)
 
436
    #cfg_parameters.append(last_pcb_path)
 
437
    say('virtual models '+virtual+'\r')
 
438
    say('export fusing option '+exportFusing+'\r')
 
439
    #cfg_parameters.append(virtual);cfg_parameters.append(exportFusing)
 
440
    say ('minimum drill size '+str(min_drill_size)+'mm\n')
 
441
    say ('export to STEP '+str(export_board_2step)+'\n')
 
442
    #cfg_parameters.append(min_drill_size);
 
443
    ## color
 
444
    #FreeCADGui.ActiveDocument.getObject("Board_outline").ShapeColor = (0.3333,0.3333,0.4980)
 
445
    col= col.split(',')
 
446
    colr=float(col[0]);colg=float(col[1]);colb=float(col[2])
 
447
    ##cfg_parameters = (models3D_prefix,blacklisted_model_elements,col,bbox,volume_minimum,height_minimum
 
448
    #cfg_parameters.append(colr);cfg_parameters.append(colg);cfg_parameters.append(colb)
 
449
    #return cfg_parameters
 
450
##
 
451
 
 
452
def shapeToMesh(shape, color, transp, mesh_deviation, scale=None):
 
453
    #mesh_deviation=0.1 #the smaller the best quality, 1 coarse
 
454
    #say(mesh_deviation+'\n')
 
455
    mesh_data = shape.tessellate(mesh_deviation)
 
456
    points = mesh_data[0]
 
457
    if scale != None:
 
458
        points = map(lambda p: p*scale, points)
 
459
    newMesh= Mesh(points = points,
 
460
                faces = mesh_data[1],
 
461
                color = color, transp=transp)
 
462
    return newMesh
 
463
        
 
464
def exportVRML(objects, filepath):
 
465
    """Export given list of Mesh objects to a VRML file.
 
466
 
 
467
    `Mesh` structure is defined at root."""
 
468
 
 
469
    with __builtin__.open(filepath, 'w') as f:
 
470
        # write the standard VRML header
 
471
        f.write("#VRML V2.0 utf8\n\n")
 
472
        for obj in objects:
 
473
            f.write("Shape { geometry IndexedFaceSet \n{ coordIndex [")
 
474
            # write coordinate indexes for each face
 
475
            f.write(','.join("%d,%d,%d,-1" % f for f in obj.faces))
 
476
            f.write("]\n") # closes coordIndex
 
477
            f.write("coord Coordinate { point [")
 
478
            # write coordinate points for each vertex
 
479
            #f.write(','.join('%.3f %.3f %.3f' % (p.x, p.y, p.z) for p in obj.points))
 
480
            f.write(','.join('%.3f %.3f %.3f' % (p.x, p.y, p.z) for p in obj.points))
 
481
            f.write("]\n}") # closes Coordinate
 
482
            #shape_col=(1.0, 0.0, 0.0)#, 0.0)
 
483
            f.write("}\n") # closes points
 
484
            #say(obj.color)
 
485
            shape_col=obj.color[:-1] #remove last item
 
486
            #say(shape_col)
 
487
            shape_transparency=obj.transp
 
488
            f.write("appearance Appearance{material Material{diffuseColor %f %f %f\n" % shape_col)
 
489
            f.write("transparency %f}}" % shape_transparency)
 
490
            f.write("}\n") # closes Shape
 
491
        say(filepath+' written\n')
 
492
###
 
493
 
 
494
def export(componentObjs, fullfilePathName, scale=None):
 
495
    """ Exports given ComponentModel object using FreeCAD.
 
496
 
 
497
    `componentObjs` : a ComponentObjs list
 
498
    `fullfilePathName` : name of the FC file, extension is important
 
499
    
 
500
    """
 
501
    
 
502
    global exportV
 
503
    exp_name=componentObjs[0].Label
 
504
    path, fname = os.path.split(fullfilePathName)
 
505
    fname=os.path.splitext(fname)[0]
 
506
    if scale != None:
 
507
        filename=path+os.sep+exp_name+'.wrl'
 
508
    else:
 
509
        filename=path+os.sep+exp_name+'_1_1.wrl'
 
510
    say(filename+"\n")
 
511
    exportV=True
 
512
    mesh_deviation_default=0.03 # 0.03 or 0.1
 
513
    mesh_dev=mesh_deviation_default #the smaller the best quality, 1 coarse
 
514
    if os.path.exists(filename):
 
515
        say('file exists\n')
 
516
        QtGui.qApp.restoreOverrideCursor()
 
517
        reply = QtGui.QMessageBox.question(None, "Info", filename+"\nwrl file exists, overwrite?",
 
518
        QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No)
 
519
        if reply == QtGui.QMessageBox.Yes:
 
520
            # this is where the code relevant to a 'Yes' answer goes
 
521
            exportV=True
 
522
            #pass
 
523
        if reply == QtGui.QMessageBox.No:
 
524
            # this is where the code relevant to a 'No' answer goes
 
525
            exportV=False
 
526
            #pass
 
527
    if exportV:
 
528
        reply = QtGui.QInputDialog.getText(None, "Mesh Deviation","Mesh Deviation (the smaller the better quality)",QtGui.QLineEdit.Normal,str(mesh_deviation_default))
 
529
        if reply[1]:
 
530
                # user clicked OK
 
531
                replyText = reply[0]
 
532
                mesh_dev = float (replyText)
 
533
        else:
 
534
                # user clicked Cancel
 
535
                replyText = reply[0] # which will be "" if they clicked Cancel
 
536
                mesh_dev=mesh_deviation_default #the smaller the best quality, 1 coarse
 
537
                #default
 
538
        #say(mesh_dev)
 
539
        color=[]
 
540
        Diffuse_color=[]
 
541
        transparency=[]
 
542
        for obj in componentObjs:
 
543
            #say(obj.Label)
 
544
            color.append(FreeCADGui.ActiveDocument.getObject(obj.Name).ShapeColor)
 
545
            transparency.append(FreeCADGui.ActiveDocument.getObject(obj.Name).Transparency/100.0)
 
546
            #say("color")
 
547
            #say(FreeCADGui.ActiveDocument.getObject(obj.Name).DiffuseColor)
 
548
            Diffuse_color.append(FreeCADGui.ActiveDocument.getObject(obj.Name).DiffuseColor)
 
549
        i=0
 
550
        meshes=[]
 
551
        #say("diffuse color")
 
552
        #say(Diffuse_color)
 
553
        indexColor=0;
 
554
        color_vector=[]
 
555
        applyDiffuse=0
 
556
        for obj in componentObjs:
 
557
            shape1=obj.Shape
 
558
            single_color=Diffuse_color[i];
 
559
            #check lenght color
 
560
            #say("len color")
 
561
            #say(len(single_color))
 
562
            #colors less then faces
 
563
            if(len(single_color)!=len(shape1.Faces)):
 
564
                applyDiffuse=0;
 
565
                #copy color to all faces
 
566
            #else copy singolar colors for faces
 
567
            else:
 
568
                applyDiffuse=1;
 
569
                for color in single_color:
 
570
                    color_vector.append(color)
 
571
            #say("color_vector")
 
572
            #say(color_vector)
 
573
            for index in range(len(shape1.Faces)):
 
574
                #say("color x")
 
575
                #say(color_vector[indexColor])
 
576
                singleFace=shape1.Faces[index]
 
577
                if(applyDiffuse):
 
578
                    #say(color_vector[indexColor])
 
579
                    meshes.append(shapeToMesh(singleFace, color_vector[indexColor], transparency[i], mesh_dev, scale))
 
580
                else:
 
581
                    #say(single_color[0])
 
582
                    meshes.append(shapeToMesh(singleFace, single_color[0], transparency[i], mesh_dev, scale))
 
583
                indexColor=indexColor+1
 
584
                #meshes.append(shapeToMesh(face, Diffuse_color[i], transparency[i], scale))
 
585
            color_vector=[]
 
586
            indexColor=0;
 
587
            i=i+1
 
588
        exportVRML(meshes, filename)
 
589
    return
 
590
###
 
591
 
 
592
def go_export(fPathName):
 
593
    sel = FreeCADGui.Selection.getSelection()
 
594
    if not sel:
 
595
        FreeCAD.Console.PrintWarning("Select something first!\n\n")
 
596
        msg="export VRML from FreeCAD is a python macro that will export simplified VRML of "
 
597
        msg+="a (multi)selected Part or fused Part to VRML optimized to Kicad and compatible with Blender "
 
598
        msg+="the size of VRML is much smaller compared to the one exported from FC Gui "
 
599
        msg+="and the loading/rendering time is also smaller\n"
 
600
        msg+="change mesh deviation to increase quality of VRML\n"
 
601
        say(msg)
 
602
    else:
 
603
        objs = []
 
604
        for obj in sel:
 
605
                objs.append(obj)
 
606
                #say(obj.Label)
 
607
                #say(obj.Name)
 
608
        say(fPathName+'\n')
 
609
        #say(objs)
 
610
        #export(objs, fullFilePathName, scale=None)
 
611
        export(objs, fPathName, 0.3937)
 
612
        exportStep(objs, fPathName)
 
613
###
 
614
def exportStep(objs, ffPathName):
 
615
    #Export fused object
 
616
    global exportS
 
617
    exp_name=objs[0].Label
 
618
    path, fname = os.path.split(ffPathName)
 
619
    #fname=os.path.splitext(fname)[0]
 
620
    fullFilePathNameStep=path+os.sep+exp_name+'.step'
 
621
    exportS=True
 
622
    if os.path.exists(fullFilePathNameStep):
 
623
        say('file exists\n')
 
624
        QtGui.qApp.restoreOverrideCursor()
 
625
        reply = QtGui.QMessageBox.question(None, "Info", fullFilePathNameStep+"\nstep file exists, overwrite?",
 
626
        QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No)
 
627
        if reply == QtGui.QMessageBox.Yes:
 
628
            # this is where the code relevant to a 'Yes' answer goes
 
629
            exportS=True
 
630
            pass
 
631
        if reply == QtGui.QMessageBox.No:
 
632
            # this is where the code relevant to a 'No' answer goes
 
633
            exportS=False
 
634
            pass
 
635
    if exportS:
 
636
        ImportGui.export(objs,fullFilePathNameStep)
 
637
        FreeCAD.activeDocument().recompute()
 
638
    return
 
639
###
 
640
 
 
641
home = expanduser("~")
 
642
#QtGui.QMessageBox.information(None,"info ...","your home path is \r\n"+ home+"\r\n")
 
643
sayw("kicad StepUp version "+str(___ver___))
 
644
say("your home path is "+ home+"\r\n")
 
645
fname_ksu=home+os.sep+'ksu-config.ini'
 
646
ksu_config_fname=fname_ksu
 
647
default_ksu_config_ini="""[info]
 
648
;; kicad StepUp tools config file
 
649
;; each line starting with a semicolon is a comment
 
650
[prefix3D]
 
651
;; put here your KISYS3DMOD path or 3D model prefix path
 
652
;; only ONE prefix is allowed; MUST finish with slash or backslash
 
653
;prefix3D_1 = C:\\Program Files\\KiCad\share\\kicad\\modules\\packages3d\\
 
654
;prefix3D_1 = kicad/share/modules/packages3d/
 
655
prefix3D_1 = C:\\Cad\\Progetti_K\\a_mod\\a_3Dpkg\\
 
656
[PcbColor]
 
657
;; pcb color r,g,b e.g. 0.0,0.5,0.0,light green
 
658
;pcb_color=0.3333,0.3333,0.5,blue
 
659
;pcb_color=0.0,0.5,0.0,light green
 
660
pcb_color=0.0,0.298,1.0,lightblue (0,76,255)
 
661
;pcb_color=0.211,0.305,0.455,darkblue (54,79,116)
 
662
[Blacklist]
 
663
;; put here your model names that you don't want to load (e.g. smallest ones)
 
664
;; separated by a comma (none means all the models will be parsed)
 
665
;; (volume=1 means all models with a volume < 1mm3 will not be included)
 
666
;; (height=1 means all models with a height < 1mm  will not be included)
 
667
;bklist = r_0603,r_0402,c_0402,c_0603
 
668
;bklist = height=1.0
 
669
;bklist = volume=1.0
 
670
;bklist = none
 
671
bklist = none
 
672
[BoundingBox]
 
673
;; bounding box option LIST=>whitelist (not converted to bbox)
 
674
;bbox = LIST dpak-to252,sod80
 
675
;bbox = ALL
 
676
bbox = off default
 
677
[Placement]
 
678
;; placement options
 
679
;placement options: useAuxOrigin, useBaseOrigin, useBasePoint;x;y, usedefault, +AutoAdjust
 
680
;placement = useAuxOrigin
 
681
;placement = useAuxOrigin +AutoAdjust
 
682
;placement = useBasePoint;37.0;50.0;
 
683
;placement = useBasePoint;37.0;50.0; +AutoAdjust
 
684
;placement = useBaseOrigin #place board @ 0,0,0
 
685
;placement = useBaseOrigin +AutoAdjust #place board @ 0,0,0
 
686
;placement = usedefault
 
687
;placement = usedefault +AutoAdjust
 
688
placement = useBaseOrigin #place board @ 0,0,0
 
689
[Virtual]
 
690
;; virtual modules to be or not added to board
 
691
virt = noVirtual
 
692
;virt = addVirtual
 
693
[ExportFuse]
 
694
;; fuse modules to board
 
695
;; be careful ... fusion can be heavy or generate FC crash with a lot of objects
 
696
;; please consider to use bbox or blacklist small objs
 
697
;exportFusing = fuseAll
 
698
exportFusing = nofuse  #default
 
699
[minimum_drill_size]
 
700
;; minimum drill size to be handled 
 
701
;; set 0.0 to handle all sizes
 
702
min_drill_size = 0.0
 
703
[last_pcb_path]
 
704
;; last pcb file path used
 
705
last_pcb_path =
 
706
[last_footprint_path]
 
707
;; last footprint file path used
 
708
last_fp_path =
 
709
[export]
 
710
export_to_STEP = yes
 
711
;; export to STEP 
 
712
;export_to_STEP = yes
 
713
;export_to_STEP = no
 
714
"""
 
715
default_ksu_msg=[]
 
716
default_ksu_msg.append(""";; kicad StepUp tools config file
 
717
;; each line starting with a semicolon is a comment""")
 
718
default_ksu_msg.append(""";; put here your KISYS3DMOD path or 3D model prefix path
 
719
;; only ONE prefix is allowed; MUST finish with slash or backslash
 
720
;prefix3D_1 = C:\\Program Files\\KiCad\share\\kicad\\modules\\packages3d\\
 
721
;prefix3D_1 = kicad/share/modules/packages3d/""")
 
722
default_ksu_msg.append(""";; pcb color r,g,b e.g. 0.0,0.5,0.0,light green
 
723
;pcb_color=0.3333,0.3333,0.5,blue
 
724
;pcb_color=0.0,0.5,0.0,light green
 
725
;pcb_color=0.0,0.298,1.0,lightblue (0,76,255)
 
726
;pcb_color=0.211,0.305,0.455,darkblue (54,79,116)""")
 
727
default_ksu_msg.append(""";; put here your model names that you don't want to load (e.g. smallest ones)
 
728
;; separated by a comma (none means all the models will be parsed)
 
729
;; (volume=1 means all models with a volume < 1mm3 will not be included)
 
730
;; (height=1 means all models with a height < 1mm  will not be included)
 
731
;bklist = r_0603,r_0402,c_0402,c_0603
 
732
;bklist = height=1.0
 
733
;bklist = volume=1.0
 
734
;bklist = none""")
 
735
default_ksu_msg.append(""";; bounding box option LIST=>whitelist (not converted to bbox)
 
736
;bbox = LIST dpak-to252,sod80
 
737
;bbox = ALL
 
738
;bbox = off default""")
 
739
default_ksu_msg.append(""";; placement options
 
740
;placement options: useAuxOrigin, useBaseOrigin, useBasePoint;x;y, usedefault, +AutoAdjust
 
741
;placement = useAuxOrigin
 
742
;placement = useAuxOrigin +AutoAdjust
 
743
;placement = useBasePoint;37.0;50.0;
 
744
;placement = useBasePoint;37.0;50.0; +AutoAdjust
 
745
;placement = useBaseOrigin #place board @ 0,0,0
 
746
;placement = useBaseOrigin +AutoAdjust #place board @ 0,0,0
 
747
;placement = usedefault
 
748
;placement = usedefault +AutoAdjust""")
 
749
default_ksu_msg.append(""";; virtual modules to be or not added to board
 
750
;virt = noVirtual
 
751
;virt = addVirtual""")
 
752
default_ksu_msg.append(""";; fuse modules to board
 
753
;; be careful ... fusion can be heavy or generate FC crash with a lot of objects
 
754
;; please consider to use bbox or blacklist small objs
 
755
;exportFusing = fuseAll
 
756
;exportFusing = nofuse  #default""")
 
757
default_ksu_msg.append(""";; minimum drill size to be processed in mm
 
758
;; set 0.0 to process all sizes
 
759
;min_drill_size = 0.0""")
 
760
default_ksu_msg.append(""";; last pcb file path used
 
761
;last_pcb_path =""")
 
762
default_ksu_msg.append(""";; last footprint file path used
 
763
;last_fp_path =""")
 
764
default_ksu_msg.append(""";; export to STEP 
 
765
;export_to_STEP = yes
 
766
;export_to_STEP = no""")
 
767
 
 
768
def read_ini_file():
 
769
    if os.path.isfile(ksu_config_fname):
 
770
        say("ksu file \'ksu-config.ini\' exists\r\n")
 
771
        ini_content=[]
 
772
        #Kicad_Board_elaborated = open(filename, "r").read()[0:]
 
773
        txtFile = __builtin__.open(ksu_config_fname,"r")
 
774
        ini_content = txtFile.readlines()
 
775
        #ini_content.append(" ")
 
776
        txtFile.close()
 
777
        data=""
 
778
        for item in ini_content:
 
779
            if item.startswith("["):
 
780
                data+="<b><font color=GoldenRod>"+item+"</font></b><br>"
 
781
            elif item.startswith(";"):
 
782
                data+="<font color=blue>"+item+"</font><br>"
 
783
            else:
 
784
                data+="<font color=black>"+item+"</font><br>"
 
785
        #data+=''.join(ini_content)
 
786
        ini_content=re.sub(r'[^\x00-\x7F]+',' ', data)    
 
787
        #msg="""<b>kicad StepUp ver. """
 
788
        #msg+=___ver___+"</b><br>"
 
789
        #msg+="default ksu config file created<br>"
 
790
        #msg+="<b>"+fname+"</b>"
 
791
        #reply = QtGui.QMessageBox.information(None,"Info ...",msg)
 
792
    else:    
 
793
        say("ksu file doesn't exist\r\n")
 
794
        say("making default\r\n")
 
795
        with __builtin__.open(ksu_config_fname,'w') as myfile:
 
796
            myfile.write(default_ksu_config_ini)
 
797
            myfile.close()
 
798
        ini_content=[]
 
799
        txtFile = __builtin__.open(ksu_config_fname,"r")
 
800
        ini_content = txtFile.readlines()
 
801
        #ini_content.append(" ")
 
802
        ini_content
 
803
        txtFile.close() 
 
804
        data=''.join(ini_content)
 
805
        ini_content=re.sub(r'[^\x00-\x7F]+',' ', data)
 
806
        msg="""<b>kicad StepUp ver. """
 
807
        msg+=___ver___+"</b><br>"
 
808
        msg+="default ksu config file created<br>"
 
809
        msg+="<b>"+ksu_config_fname+"</b>"
 
810
        msg+="<br>adapt your <b>3D model DIR path</b> in config file<br>"
 
811
        msg+="see <b><font color=GoldenRod>[prefix3D]</font></b> section"
 
812
        QtGui.qApp.restoreOverrideCursor()
 
813
        reply = QtGui.QMessageBox.information(None,"Info ...",msg)
 
814
    return ini_content
 
815
##
 
816
 
 
817
ini_content=read_ini_file()
 
818
configParser = ConfigParser.RawConfigParser()  
 
819
configParser = ConfigParser.ConfigParser(allow_no_value = True) 
 
820
configFilePath = ksu_config_fname
 
821
cfgParsRead(configFilePath)
 
822
 
 
823
#assign params
 
824
 
 
825
def say_time():
 
826
    end_milli_time = current_milli_time()
 
827
    running_time=(end_milli_time-start_time)/1000
 
828
    msg="running time: "+str(running_time)+"sec\n"
 
829
    say(msg)
 
830
###
 
831
 
 
832
def reset_prop(obj,doc,App,Gui):
 
833
    #say('resetting props\n')
 
834
    ##try:
 
835
    newObj =FreeCAD.ActiveDocument.addObject('Part::Feature',obj.Name)
 
836
    newObj.Shape=FreeCAD.ActiveDocument.getObject(obj.Name).Shape
 
837
    FreeCAD.ActiveDocument.ActiveObject.Label=FreeCAD.ActiveDocument.getObject(obj.Name).Label
 
838
    final_Label=FreeCAD.ActiveDocument.getObject(obj.Name).Label
 
839
    #say(final_Label+'\n')
 
840
    FreeCADGui.ActiveDocument.ActiveObject.ShapeColor=FreeCADGui.ActiveDocument.getObject(obj.Name).ShapeColor
 
841
    FreeCADGui.ActiveDocument.ActiveObject.LineColor=FreeCADGui.ActiveDocument.getObject(obj.Name).LineColor
 
842
    FreeCADGui.ActiveDocument.ActiveObject.PointColor=FreeCADGui.ActiveDocument.getObject(obj.Name).PointColor
 
843
    FreeCADGui.ActiveDocument.ActiveObject.DiffuseColor=FreeCADGui.ActiveDocument.getObject(obj.Name).DiffuseColor
 
844
    FreeCAD.ActiveDocument.recompute()
 
845
    newObjCommon=FreeCAD.activeDocument().addObject("Part::MultiCommon","Common")
 
846
    newObjCommon.Shapes = [FreeCAD.activeDocument().getObject(obj.Name),FreeCAD.activeDocument().getObject(newObj.Name),]
 
847
    FreeCADGui.activeDocument().getObject(obj.Name).Visibility=False
 
848
    FreeCADGui.activeDocument().getObject(newObj.Name).Visibility=False
 
849
    FreeCADGui.ActiveDocument.Common.ShapeColor=FreeCADGui.ActiveDocument.getObject(obj.Name).ShapeColor
 
850
    FreeCADGui.ActiveDocument.Common.DisplayMode=FreeCADGui.ActiveDocument.getObject(obj.Name).DisplayMode
 
851
    FreeCAD.ActiveDocument.recompute()
 
852
    # sleep
 
853
    FreeCAD.ActiveDocument.addObject('Part::Feature','Common').Shape=FreeCAD.ActiveDocument.Common.Shape
 
854
    FreeCAD.ActiveDocument.ActiveObject.Label=final_Label
 
855
    rstObj=FreeCAD.ActiveDocument.ActiveObject
 
856
    #
 
857
    FreeCADGui.ActiveDocument.ActiveObject.ShapeColor=FreeCADGui.ActiveDocument.Common.ShapeColor
 
858
    FreeCADGui.ActiveDocument.ActiveObject.LineColor=FreeCADGui.ActiveDocument.Common.LineColor
 
859
    FreeCADGui.ActiveDocument.ActiveObject.PointColor=FreeCADGui.ActiveDocument.Common.PointColor
 
860
    FreeCADGui.ActiveDocument.ActiveObject.DiffuseColor=FreeCADGui.ActiveDocument.Common.DiffuseColor
 
861
    FreeCAD.ActiveDocument.removeObject("Common")
 
862
    FreeCAD.ActiveDocument.recompute()
 
863
    #
 
864
    return rstObj
 
865
 
 
866
def reset_prop_shapes(obj,doc,App,Gui):
 
867
 
 
868
    s=obj.Shape
 
869
    #say('resetting props #2\n')
 
870
    r=[]
 
871
    t=s.copy()
 
872
    for i in t.childShapes():
 
873
        c=i.copy()
 
874
        c.Placement=t.Placement.multiply(c.Placement)
 
875
        r.append((i,c))
 
876
 
 
877
    w=t.replaceShape(r)
 
878
    w.Placement=FreeCAD.Placement()
 
879
    Part.show(w)
 
880
    #say(w)
 
881
    #say('\n')
 
882
    FreeCADGui.ActiveDocument.ActiveObject.ShapeColor=FreeCADGui.ActiveDocument.Part__Feature.ShapeColor
 
883
    FreeCADGui.ActiveDocument.ActiveObject.LineColor=FreeCADGui.ActiveDocument.Part__Feature.LineColor
 
884
    FreeCADGui.ActiveDocument.ActiveObject.PointColor=FreeCADGui.ActiveDocument.Part__Feature.PointColor
 
885
    FreeCADGui.ActiveDocument.ActiveObject.DiffuseColor=FreeCADGui.ActiveDocument.Part__Feature.DiffuseColor
 
886
    new_label=obj.Label
 
887
    FreeCAD.ActiveDocument.removeObject(obj.Name)
 
888
    FreeCAD.ActiveDocument.recompute()
 
889
    FreeCAD.ActiveDocument.ActiveObject.Label=new_label
 
890
    rstObj=FreeCAD.ActiveDocument.ActiveObject
 
891
    #say(rstObj)
 
892
    #say('\n')
 
893
 
 
894
    return rstObj
 
895
 
 
896
 
 
897
def Display_info(blacklisted_models):
 
898
    global bbox_all, bbox_list, fusion, show_messages, last_pcb_path
 
899
    global height_minimum, volume_minimum, idf_to_origin, ksu_config_fname
 
900
    global board_base_point_x, board_base_point_y, real_board_pos_x, real_board_pos_y
 
901
    say('info message\n')
 
902
    if blacklisted_model_elements != '':
 
903
        sayw("black-listed module "+ '\r\n'.join(map(str, blacklisted_models)))
 
904
        if (show_messages==True):
 
905
            QtGui.qApp.restoreOverrideCursor()
 
906
            reply = QtGui.QMessageBox.information(None,"Info ...","... black-listed module(s)\r\n"+ '\r\n'.join(map(str, blacklisted_models)))
 
907
        #FreeCAD.Console.PrintMessage("black-listed module "+ '\r\n'.join(map(str, blacklisted_models)))    
 
908
    
 
909
    msg="""<b>kicad StepUp</b> ver. """
 
910
    msg+=___ver___
 
911
    #if len(msgpath)>15:
 
912
    #    insert_return(msgpath, 15)
 
913
    if (idf_to_origin==True):
 
914
        new_pos_x=board_base_point_x+real_board_pos_x
 
915
        new_pos_y=board_base_point_y+real_board_pos_y
 
916
    else:
 
917
        new_pos_x=board_base_point_x
 
918
        new_pos_y=board_base_point_y
 
919
    msg+="<br>Board Placed @ "+str(new_pos_x)+";"+str(new_pos_y)+";0.0"
 
920
    msg+="<br>kicad pcb pos: ("+"{0:.3f}".format(real_board_pos_x)+";"+"{0:.3f}".format(real_board_pos_y)+";"+"{0:.2f}".format(0)+")"
 
921
    if (bbox_all==1) or (bbox_list==1):
 
922
        msg+="<br>bounding box modules applied"
 
923
    if (volume_minimum!=0):
 
924
        msg+="<br>modules with volume less then "+str(volume_minimum)+"mm^3 not included"
 
925
    if (height_minimum!=0):
 
926
        msg+="<br>modules with height less then "+str(height_minimum)+"mm not included"    
 
927
    msg+="<br>kicad StepUp config file in:<br><b>"+ksu_config_fname+"</b><br>location."
 
928
    say("Board Placed @ "+str(new_pos_x)+";"+str(new_pos_y)+";0.0\n")
 
929
    say("kicad pcb pos: ("+"{0:.3f}".format(real_board_pos_x)+";"+"{0:.3f}".format(real_board_pos_y)+";"+"{0:.2f}".format(0)+")\n")    
 
930
    if (show_messages==True):
 
931
        QtGui.qApp.restoreOverrideCursor()
 
932
        reply = QtGui.QMessageBox.information(None,"Info ...",msg)
 
933
###
 
934
 
 
935
def Export2MCAD(blacklisted_model_elements):
 
936
    global bbox_all, bbox_list, fusion, show_messages, last_pcb_path
 
937
    global height_minimum, volume_minimum, idf_to_origin, ksu_config_fname
 
938
    global board_base_point_x, board_base_point_y, real_board_pos_x, real_board_pos_y
 
939
    say('exporting to MCAD\n')
 
940
    ## exporting
 
941
    __objs__=[]
 
942
    doc=FreeCAD.ActiveDocument
 
943
    for obj in doc.Objects:
 
944
        # do what you want to automate
 
945
        if (obj.Label!="Board_Geoms") and (obj.Label!="Step_Models"):
 
946
            FreeCADGui.Selection.addSelection(obj)
 
947
            __objs__.append(obj)
 
948
    filePath=last_pcb_path
 
949
    if (bbox_all==1) or (bbox_list==1):
 
950
        fpath=filePath+os.sep+doc.Label+"_bbox"+'.step'
 
951
    else:
 
952
        fpath=filePath+os.sep+doc.Label+'.step'
 
953
    ImportGui.export(__objs__,fpath)
 
954
    #fusion=False
 
955
    ## be careful ... fusion can be heavy or generate FC crash with a lot of objects
 
956
    ## please consider to use bbox or blacklist small objs
 
957
    if (fusion==True):
 
958
        # Fuse objects
 
959
        doc.addObject("Part::MultiFuse","Fusion")
 
960
        doc.Fusion.Shapes = __objs__
 
961
    #    doc.ActiveObject.Label=doc.Name+"_union"
 
962
        doc.recompute()
 
963
        doc.addObject('Part::Feature','Fusion').Shape=FreeCAD.ActiveDocument.Fusion.Shape
 
964
        if (bbox_all==1) or (bbox_list==1):
 
965
            doc.ActiveObject.Label=doc.Name+"_bbox_union"
 
966
        else:
 
967
            doc.ActiveObject.Label=doc.Name+"_union"
 
968
        FreeCADGui.ActiveDocument.ActiveObject.ShapeColor=FreeCADGui.ActiveDocument.Fusion.ShapeColor
 
969
        FreeCADGui.ActiveDocument.ActiveObject.LineColor=FreeCADGui.ActiveDocument.Fusion.LineColor
 
970
        FreeCADGui.ActiveDocument.ActiveObject.PointColor=FreeCADGui.ActiveDocument.Fusion.PointColor
 
971
        FreeCADGui.ActiveDocument.ActiveObject.DiffuseColor=FreeCADGui.ActiveDocument.Fusion.DiffuseColor
 
972
        # Remove the fusion object
 
973
        doc.removeObject("Fusion")
 
974
        doc.recompute()
 
975
        fobjs=[]
 
976
        fused_obj=doc.ActiveObject
 
977
        FreeCAD.Console.PrintMessage(fused_obj)
 
978
        fobjs.append(fused_obj)
 
979
        if (bbox_all==1) or (bbox_list==1):
 
980
            fpath=filePath+os.sep+doc.Label+"_bbox_union"+'.step'
 
981
        else:
 
982
            fpath=filePath+os.sep+doc.Label+"_union"+'.step'
 
983
        FreeCAD.Console.PrintMessage(fpath+" fusion path \r\n")
 
984
        FreeCAD.Console.PrintMessage(fobjs)
 
985
        #Export fused object
 
986
        ImportGui.export(fobjs,fpath)
 
987
        FreeCAD.activeDocument().recompute()
 
988
        del fobjs
 
989
        #ImportGui.export(doc.ActiveObject,filePath+os.sep+doc.Label+'.step')
 
990
    for obj in doc.Objects:
 
991
        # do what you want to automate
 
992
        FreeCADGui.Selection.removeSelection(obj)
 
993
    if blacklisted_model_elements != '':
 
994
        sayw("black-listed module "+ '\r\n'.join(map(str, blacklisted_models)))
 
995
        if (show_messages==True):
 
996
            QtGui.qApp.restoreOverrideCursor()
 
997
            reply = QtGui.QMessageBox.information(None,"Info ...","... black-listed module(s)\r\n"+ '\r\n'.join(map(str, blacklisted_models)))
 
998
        #FreeCAD.Console.PrintMessage("black-listed module "+ '\r\n'.join(map(str, blacklisted_models)))    
 
999
    del __objs__
 
1000
    ## Save to disk in native format
 
1001
    FreeCAD.ActiveDocument=None
 
1002
    FreeCADGui.ActiveDocument=None
 
1003
    FreeCAD.setActiveDocument(doc.Name)
 
1004
    FreeCAD.ActiveDocument=FreeCAD.getDocument(doc.Name)
 
1005
    FreeCADGui.ActiveDocument=FreeCADGui.getDocument(doc.Name)
 
1006
    if (bbox_all==1) or (bbox_list==1):
 
1007
        fpath=filePath+os.sep+doc.Name+"_bbox"
 
1008
    else:
 
1009
        fpath=filePath+os.sep+doc.Name
 
1010
    if (fusion==True):
 
1011
        fpath=fpath+"_union"
 
1012
    say(fpath+".FCStd"+"\n")
 
1013
    FreeCAD.getDocument(doc.Name).saveAs(fpath+".FCStd")
 
1014
    FreeCAD.ActiveDocument.recompute()
 
1015
    FreeCAD.getDocument(doc.Name).Label = doc.Name
 
1016
    FreeCADGui.SendMsgToActiveView("Save")
 
1017
    FreeCAD.getDocument(doc.Name).save()
 
1018
    msgpath=filePath+os.sep+doc.Name
 
1019
    if (bbox_all==1) or (bbox_list==1):
 
1020
        msgpath=msgpath+"_bbox"
 
1021
 
 
1022
    msg="""<b>kicad StepUp</b> ver. """
 
1023
    msg+=___ver___
 
1024
    msg+="<br>file exported<br><b>"+msgpath+'.step</b>'
 
1025
    #if len(msgpath)>15:
 
1026
    #    insert_return(msgpath, 15)
 
1027
    if (fusion==True):
 
1028
        msgpath=msgpath+"_union"
 
1029
        msg+="<br>fused file exported<br><b>"+msgpath+'.step</b>'    
 
1030
    if (idf_to_origin==True):
 
1031
        new_pos_x=board_base_point_x+real_board_pos_x
 
1032
        new_pos_y=board_base_point_y+real_board_pos_y
 
1033
    else:
 
1034
        new_pos_x=board_base_point_x
 
1035
        new_pos_y=board_base_point_y
 
1036
    msg+="<br>Board Placed @ "+str(new_pos_x)+";"+str(new_pos_y)+";0.0"
 
1037
    msg+="<br>kicad pcb pos: ("+"{0:.3f}".format(real_board_pos_x)+";"+"{0:.3f}".format(real_board_pos_y)+";"+"{0:.2f}".format(0)+")"
 
1038
    if (bbox_all==1) or (bbox_list==1):
 
1039
        msg+="<br>bounding box modules applied"
 
1040
    if (volume_minimum!=0):
 
1041
        msg+="<br>modules with volume less then "+str(volume_minimum)+"mm^3 not included"
 
1042
    if (height_minimum!=0):
 
1043
        msg+="<br>modules with height less then "+str(height_minimum)+"mm not included"    
 
1044
    msg+="<br>kicad StepUp config file in:<br><b>"+ksu_config_fname+"</b><br>location."
 
1045
    say("Board Placed @ "+str(new_pos_x)+";"+str(new_pos_y)+";0.0\n")
 
1046
    say("kicad pcb pos: ("+"{0:.3f}".format(real_board_pos_x)+";"+"{0:.3f}".format(real_board_pos_y)+";"+"{0:.2f}".format(0)+")\n")    
 
1047
    if (show_messages==True):
 
1048
        QtGui.qApp.restoreOverrideCursor()
 
1049
        reply = QtGui.QMessageBox.information(None,"Info ...",msg)    
 
1050
###
 
1051
 
 
1052
def Load_models(pcbThickness,modules):
 
1053
    global off_x, off_y, volume_minimum, height_minimum, bbox_all, bbox_list
 
1054
    global whitelisted_model_elements, models3D_prefix, last_pcb_path
 
1055
    #say (modules)
 
1056
    missing_models = ''
 
1057
    for i in range(len(modules)):
 
1058
        step_module=modules[i][0]
 
1059
        #say(modules[i]);say('\n')
 
1060
        #FreeCAD.Console.PrintMessage('step-module '+step_module+'\r\n')
 
1061
        if (step_module.find('${KIPRJMOD}')!=-1):  #local 3D path
 
1062
            #step_module=step_module.replace('${KIPRJMOD}', '.')
 
1063
            step_module=step_module.replace('${KIPRJMOD}', last_pcb_path)
 
1064
            say('adjusting Local Path\r\n')
 
1065
            say('step-module-replaced '+step_module+'\n')
 
1066
        if step_module != 'no3Dmodel':
 
1067
            step_module=step_module[:-3]+'step'
 
1068
            step_module2=step_module[:-4]+'stp'
 
1069
            step_module3=step_module[:-4]+'iges'
 
1070
            step_module4=step_module[:-4]+'igs'
 
1071
            model_name=step_module[:-5]
 
1072
            last_slash_pos1=model_name.rfind('/')
 
1073
            last_slash_pos2=model_name.rfind('\\')
 
1074
            last_slash_pos=max(last_slash_pos1,last_slash_pos2)
 
1075
            model_name=model_name[last_slash_pos+1:]
 
1076
            say('model name '+model_name+'\n')
 
1077
        else:
 
1078
            model_name='no3Dmodel'
 
1079
        blacklisted=0
 
1080
        if blacklisted_model_elements != '':
 
1081
            if blacklisted_model_elements.find(model_name) != -1:
 
1082
                blacklisted=1
 
1083
        ###
 
1084
        if (blacklisted==0):
 
1085
            if step_module != 'no3Dmodel':
 
1086
                module_path='not-found'
 
1087
                step_module=step_module.replace('"', '')  # name with spaces
 
1088
                if os.path.exists(models3D_prefix+step_module):
 
1089
                    module_path=models3D_prefix+step_module
 
1090
                else:
 
1091
                    if os.path.exists(step_module): # absolute path
 
1092
                        module_path=step_module
 
1093
                #adding .stp support
 
1094
                if os.path.exists(models3D_prefix+step_module2) and (module_path=='not-found'):
 
1095
                    module_path=models3D_prefix+step_module2
 
1096
                else:
 
1097
                    if os.path.exists(step_module2) and (module_path=='not-found'): # absolute path
 
1098
                        module_path=step_module2
 
1099
                #adding .iges support
 
1100
                if os.path.exists(models3D_prefix+step_module3) and (module_path=='not-found'):
 
1101
                    module_path=models3D_prefix+step_module3
 
1102
                else:
 
1103
                    if os.path.exists(step_module3) and (module_path=='not-found'): # absolute path
 
1104
                        module_path=step_module3
 
1105
                #adding .igs support
 
1106
                if os.path.exists(models3D_prefix+step_module4) and (module_path=='not-found'):
 
1107
                    module_path=models3D_prefix+step_module4
 
1108
                else:
 
1109
                    if os.path.exists(step_module4) and (module_path=='not-found'): # absolute path
 
1110
                        module_path=step_module4
 
1111
                if module_path!='not-found':
 
1112
                    #FreeCADGui.Selection.removeSelection(FreeCAD.activeDocument().ActiveObject)  mauitemp volume diff
 
1113
                    say("opening "+ module_path+'\n')
 
1114
                    ImportGui.insert(module_path,FreeCAD.ActiveDocument.Name)
 
1115
                    if FreeCAD.ActiveDocument.ActiveObject.Label.endswith('001'):
 
1116
                        msg="""3D STEP model <b><font color=red>"""
 
1117
                        msg+=model_name+"</font> is NOT fused in a single part</b> ...<br>"
 
1118
                        msg+="@ "+module_path+" <br>...stopping execution! <br>Please <b>fix</b> the model."
 
1119
                        QtGui.qApp.restoreOverrideCursor()
 
1120
                        reply = QtGui.QMessageBox.information(None,"Info ...",msg)
 
1121
                        stop
 
1122
                    #say('alive')
 
1123
                    pos_x=modules[i][1]-off_x
 
1124
                    pos_y=modules[i][2]-off_y
 
1125
                    rot=modules[i][3]
 
1126
                    step_layer=modules[i][4]
 
1127
                    #say (str(rot))
 
1128
                    impPart=FreeCAD.ActiveDocument.ActiveObject
 
1129
                    say("module "+step_module+"\n")
 
1130
                    impPart.Label = impPart.Label + '_'
 
1131
                    #say("selection 3D model "+ impPart.Label+'\n')
 
1132
                    impPart=reset_prop_shapes(impPart,FreeCAD.ActiveDocument, FreeCAD,FreeCADGui)
 
1133
                    model3D=impPart.Name
 
1134
                    #say("impPart "+ impPart.Name+'\n')
 
1135
                    obj = FreeCAD.ActiveDocument.getObject(model3D)
 
1136
                    FreeCADGui.Selection.addSelection(obj)
 
1137
                    obj=FreeCAD.ActiveDocument.ActiveObject
 
1138
                    #volume_minimum=1
 
1139
                    myPart=FreeCAD.ActiveDocument.getObject(obj.Name)   #mauitemp min vol
 
1140
                    #sayw(obj.Label)
 
1141
                    #sayw(step_layer);
 
1142
                    #sayw(str(myPart.Shape.Volume))
 
1143
                    #sayw(str(myPart.Shape.BoundBox.ZMax))
 
1144
                    if myPart.Shape.Volume>volume_minimum:  #mauitemp min vol
 
1145
                        if abs(myPart.Shape.BoundBox.ZMax)>height_minimum:  #mauitemp min height
 
1146
                            if (height_minimum!=0):
 
1147
                                say("height > Min height "+ str(myPart.Shape.BoundBox.ZMax) + " "+impPart.Label+'\r\n')
 
1148
                            if (volume_minimum!=0):
 
1149
                                say("Volume > Min Volume "+ str(myPart.Shape.Volume) + " "+impPart.Label+'\r\n')
 
1150
                            if (bbox_all==1) or (bbox_list==1):
 
1151
                                    if whitelisted_model_elements.find(model_name) == -1:
 
1152
                                        bboxName=createSolidBBox(model3D)
 
1153
                            #say(str(bbox_all)+'bbox'+str(bbox_list)+'\n')
 
1154
                            #stop
 
1155
                            if step_layer == 'Top':
 
1156
                                impPart.Placement = FreeCAD.Placement(FreeCAD.Vector(pos_x,pos_y,0),FreeCAD.Rotation(FreeCAD.Vector(0,0,1),rot))
 
1157
                                if (bbox_all==1) or (bbox_list==1):
 
1158
                                    #say('bbox\n')
 
1159
                                    if whitelisted_model_elements.find(model_name) == -1:
 
1160
                                        bbox_col=bbox_default_col
 
1161
                                        #say("bboxName "+ bboxName +'\r\n')
 
1162
                                        #say("bboxName "+str(bboxName.upper().startswith('R'))+'\r\n')
 
1163
                                        if (bboxName.upper().startswith('X')):
 
1164
                                            bbox_col=bbox_x_col
 
1165
                                        if (bboxName.upper().startswith('L')):
 
1166
                                            bbox_col=bbox_l_col
 
1167
                                        if (bboxName.upper().startswith('R')):
 
1168
                                            bbox_col=bbox_r_col
 
1169
                                        if (bboxName.upper().startswith('C')):
 
1170
                                            bbox_col=bbox_c_col
 
1171
                                        if (bboxName.upper().startswith('S')|bboxName.upper().startswith('Q')|bboxName.upper().startswith('D')|bboxName.upper().startswith('T')):
 
1172
                                            bbox_col=bbox_IC_col
 
1173
                                        obj = FreeCAD.ActiveDocument.getObject(bboxName)
 
1174
                                        obj.Placement = FreeCAD.Placement(FreeCAD.Vector(pos_x,pos_y,0),FreeCAD.Rotation(FreeCAD.Vector(0,0,1),rot))
 
1175
                                        FreeCADGui.ActiveDocument.getObject(bboxName).ShapeColor=bbox_col
 
1176
                                        FreeCADGui.Selection.addSelection(obj)
 
1177
                                        #say("selection 3D model "+ obj.Name+'\r\n')
 
1178
                                        FreeCAD.ActiveDocument.getObject("Step_Models").addObject(obj)
 
1179
                                FreeCADGui.Selection.addSelection(impPart)
 
1180
                                FreeCAD.ActiveDocument.getObject("Step_Models").addObject(impPart)
 
1181
                                if (bbox_all==1) or (bbox_list==1):
 
1182
                                    if whitelisted_model_elements.find(model_name) == -1:
 
1183
                                        FreeCAD.activeDocument().removeObject(impPart.Name)
 
1184
                            #FreeCAD.activeDocument().removeObject(impPart.Name)
 
1185
                            ###
 
1186
                            else:
 
1187
                            #Bottom
 
1188
                            #Bottom
 
1189
                                impPart.Placement = FreeCAD.Placement(FreeCAD.Vector(pos_x,pos_y,-pcbThickness),FreeCAD.Rotation(FreeCAD.Vector(0,1,0),180))
 
1190
                                #obj.Placement = impPart.Placement
 
1191
                                shape=impPart.Shape.copy()
 
1192
                                shape.Placement=impPart.Placement;
 
1193
                                shape.rotate((pos_x,pos_y,-pcbThickness),(0,0,1),-rot+180)
 
1194
                                impPart.Placement=shape.Placement
 
1195
                                if (bbox_all==1) or (bbox_list==1):
 
1196
                                    if whitelisted_model_elements.find(model_name) == -1:
 
1197
                                        bbox_col=bbox_default_col
 
1198
                                        if (bboxName.upper().startswith('X')):
 
1199
                                            bbox_col=bbox_x_col
 
1200
                                        if (bboxName.upper().startswith('L')):
 
1201
                                            bbox_col=bbox_l_col
 
1202
                                        if (bboxName.upper().startswith('R')):
 
1203
                                            bbox_col=bbox_r_col
 
1204
                                        if (bboxName.upper().startswith('C')):
 
1205
                                            bbox_col=bbox_c_col
 
1206
                                        if (bboxName.upper().startswith('S')|bboxName.upper().startswith('Q')|bboxName.upper().startswith('D')|bboxName.upper().startswith('T')):
 
1207
                                            bbox_col=bbox_IC_col
 
1208
                                        obj = FreeCAD.ActiveDocument.getObject(bboxName)
 
1209
                                        FreeCADGui.Selection.addSelection(obj)
 
1210
                                        obj.Placement = FreeCAD.Placement(FreeCAD.Vector(pos_x,pos_y,-pcbThickness),FreeCAD.Rotation(FreeCAD.Vector(0,1,0),180))
 
1211
                                        shape2=obj.Shape.copy()
 
1212
                                        shape2.Placement=obj.Placement;
 
1213
                                        shape2.rotate((pos_x,pos_y,-pcbThickness),(0,0,1),-rot+180)
 
1214
                                        obj.Placement=shape2.Placement
 
1215
                                        FreeCADGui.ActiveDocument.getObject(bboxName).ShapeColor=bbox_col
 
1216
                                        FreeCADGui.Selection.addSelection(obj)
 
1217
                                        FreeCAD.ActiveDocument.getObject(obj.Name)
 
1218
                                        FreeCAD.ActiveDocument.getObject("Step_Models").addObject(obj)
 
1219
                                FreeCADGui.Selection.addSelection(impPart)
 
1220
                                FreeCAD.ActiveDocument.getObject(impPart.Name)
 
1221
                                FreeCAD.ActiveDocument.getObject("Step_Models").addObject(impPart)
 
1222
                                if (bbox_all==1) or (bbox_list==1):
 
1223
                                    if whitelisted_model_elements.find(model_name) == -1:
 
1224
                                        FreeCAD.activeDocument().removeObject(impPart.Name)
 
1225
                                #Part.show(shape)
 
1226
                                #Part.show(shape2)
 
1227
                                #say("todo ...\n")
 
1228
                        else:  #mauitemp min height
 
1229
                            FreeCAD.activeDocument().removeObject(obj.Name)
 
1230
                    else:  #mauitemp min vol
 
1231
                        FreeCAD.activeDocument().removeObject(obj.Name)
 
1232
                ###
 
1233
                else:
 
1234
                    say("error missing "+ models3D_prefix+step_module+'\r\n')
 
1235
                    test = missing_models.find(step_module)
 
1236
                    if test is -1:
 
1237
                        missing_models += models3D_prefix+step_module+'\r\n' #matched
 
1238
            ###
 
1239
        ###
 
1240
    ###
 
1241
    #sleep
 
1242
    FreeCAD.ActiveDocument.recompute()
 
1243
    if missing_models != '':
 
1244
        QtGui.qApp.restoreOverrideCursor()
 
1245
        reply = QtGui.QMessageBox.information(None,"Error ...","... missing module(s)\r\n"+ missing_models)
 
1246
    #if blacklisted_model_elements != '':
 
1247
    #    FreeCAD.Console.PrintMessage("black-listed module "+ '\n'.join(map(str, blacklisted_models)))
 
1248
    #    reply = QtGui.QMessageBox.information(None,"Info ...","... black-listed module(s)\n"+ '\n'.join(map(str, blacklisted_models)))
 
1249
    #    #FreeCAD.Console.PrintMessage("black-listed module "+ '\n'.join(map(str, blacklisted_models)))
 
1250
    return blacklisted_model_elements
 
1251
###
 
1252
 
 
1253
 
 
1254
def LoadKicadBoard (board_fname):
 
1255
    # checking FC version requirement
 
1256
    ######################################################################
 
1257
    #say("FC Version \r\n")
 
1258
    #say(FreeCAD.Version())
 
1259
    global start_time, fusion
 
1260
    FC_majorV=FreeCAD.Version()[0]
 
1261
    FC_minorV=FreeCAD.Version()[1]
 
1262
    say('FC Version '+FC_majorV+FC_minorV+'\r\n')    
 
1263
    msg1="use ONLY FreeCAD STABLE version 0.15 or later\r\n"
 
1264
    #msg1+="to generate your STEP and VRML models\r\nFC 016 dev version results are still unpredictable"
 
1265
    msg1+="to generate your STEP and VRML models\r\n"
 
1266
    if int(FC_majorV) <= 0:
 
1267
        if int(FC_minorV) < 15:
 
1268
            QtGui.qApp.restoreOverrideCursor()
 
1269
            reply = QtGui.QMessageBox.information(None,"Warning! ...",msg1)    
 
1270
    msg=''
 
1271
    if (fusion==True):
 
1272
        msg+="you have chosen: fuse modules to board\r\nbe careful ... fusion can be heavy or generate FC crash"
 
1273
        msg+="when fusing a lot of objects\r\nplease consider to use bbox or blacklist small objects\r\n\r\n"    
 
1274
    ##start_time=current_milli_time()
 
1275
    xMax=0; xmin=0; yMax=0; ymin=0
 
1276
    Levels = {}
 
1277
    Edge_Cuts_lvl=0;Top_lvl=0
 
1278
    Kicad_Board_elaborated,Levels,Edge_Cuts_lvl,Top_lvl,PCBVersion,pcbThickness = Elaborate_Kicad_Board(board_fname)
 
1279
    say('PCBThickness'+str(pcbThickness)+' mm\n')
 
1280
    modules = []
 
1281
    #sayw(str(Top_lvl)+' top_lvl')
 
1282
    #stop
 
1283
    modules = getParts(modules,Top_lvl,Kicad_Board_elaborated,Levels)
 
1284
    #pads=[]
 
1285
    #for i in range(len(modules)):
 
1286
    #    for j in range(len(modules[i])):
 
1287
    #        #print len(modules[i])
 
1288
    #        print modules[i][j]
 
1289
    return pcbThickness,modules,Kicad_Board_elaborated
 
1290
### end LoadKicadBoard
 
1291
 
 
1292
def getPads(board_elab,pcbThickness):
 
1293
    # pad
 
1294
    TopPadList=[]
 
1295
    BotPadList=[]
 
1296
    HoleList=[]
 
1297
    THPList=[]
 
1298
    for module in re.findall(r'\[start\]\(module(.+?)\)\[stop\]', board_elab, re.MULTILINE|re.DOTALL):
 
1299
        [X1, Y1, ROT] = re.search(r'\(at\s+([0-9\.-]*?)\s+([0-9\.-]*?)(\s+[0-9\.-]*?|)\)', module).groups()
 
1300
        #
 
1301
        X1 = float(X1)
 
1302
        Y1 = float(Y1) * (-1)
 
1303
        if ROT == '':
 
1304
            ROT = 0.0
 
1305
        else:
 
1306
            ROT = float(ROT)
 
1307
        #say('module pos & rot '+str(X1)+' '+str(Y1)+' '+str(ROT)+'\n')
 
1308
        #
 
1309
        for pad in getPadsList(module):
 
1310
            #say (pad)
 
1311
            #   pads.append({'x': x, 'y': y, 'rot': rot, 'padType': pType, 'padShape': pShape, 'rx': drill_x, 'ry': drill_y, 'dx': dx, 'dy': dy, 'holeType': hType, 'xOF': xOF, 'yOF': yOF, 'layers': layers})
 
1312
            pType = pad['padType']
 
1313
            pShape = pad['padShape']
 
1314
            xs = pad['x'] + X1
 
1315
            ys = pad['y'] + Y1
 
1316
            dx = pad['dx']
 
1317
            dy = pad['dy']
 
1318
            hType = pad['holeType']
 
1319
            drill_x = pad['rx']
 
1320
            drill_y = pad['ry']
 
1321
            xOF = pad['xOF']
 
1322
            yOF = pad['yOF']
 
1323
            rot = pad['rot']
 
1324
            if ROT != 0:
 
1325
                rot -= ROT
 
1326
            rx=drill_x
 
1327
            ry=drill_y
 
1328
            rx=float(rx)
 
1329
            ry=float(ry)
 
1330
            numberOfLayers = pad['layers'].split(' ')
 
1331
            #if pType=="thru_hole":
 
1332
            #pad shape - circle/rec/oval/trapezoid
 
1333
            perc=0
 
1334
            if pShape=="circle" or pShape=="oval":
 
1335
                pShape="oval"
 
1336
                perc=100
 
1337
                # pad type - SMD/thru_hole/connect
 
1338
            if dx>rx and dy>ry:
 
1339
                #say(pType+"\r\n")
 
1340
                #say(str(dx)+"+"+str(rx)+" dx,rx\r\n")
 
1341
                #say(str(dy)+"+"+str(ry)+" dy,ry\r\n")
 
1342
                #say(str(xOF)+"+"+str(yOF)+" xOF,yOF\r\n")
 
1343
                x1=xs+xOF
 
1344
                y1=ys-yOF #yoffset opposite
 
1345
                #say(str(x1)+"+"+str(y1)+" x1,y1\r\n")
 
1346
                top=False
 
1347
                bot=False
 
1348
                if 'F.Cu' in numberOfLayers:
 
1349
                    top=True
 
1350
                if '*.Cu' in numberOfLayers:
 
1351
                    top=True
 
1352
                    bot=True
 
1353
                if 'B.Cu' in numberOfLayers:
 
1354
                    bot=True
 
1355
            if rx!=0:
 
1356
                #say(str(min_drill_size));say(' ');say(rx);say(' ');say(str(ry));say('\n')
 
1357
                if (rx >= min_drill_size) or (ry >= min_drill_size):
 
1358
                    obj=createHole3(xs,ys,rx,ry,"oval",pcbThickness) #need to be separated instructions
 
1359
                    #say(HoleList)
 
1360
                    if rot!=0:
 
1361
                        rotateObj(obj, [xs, ys, rot])
 
1362
                    rotateObj(obj, [X1, Y1, ROT])
 
1363
                    HoleList.append(obj)    
 
1364
            ### cmt- #todo: pad type trapez
 
1365
    return HoleList
 
1366
###
 
1367
def getPads_flat(board_elab):
 
1368
    # pad
 
1369
    TopPadList=[]
 
1370
    BotPadList=[]
 
1371
    HoleList=[]
 
1372
    THPList=[]
 
1373
    for module in re.findall(r'\[start\]\(module(.+?)\)\[stop\]', board_elab, re.MULTILINE|re.DOTALL):
 
1374
        [X1, Y1, ROT] = re.search(r'\(at\s+([0-9\.-]*?)\s+([0-9\.-]*?)(\s+[0-9\.-]*?|)\)', module).groups()
 
1375
        #
 
1376
        X1 = float(X1)
 
1377
        Y1 = float(Y1) * (-1)
 
1378
        if ROT == '':
 
1379
            ROT = 0.0
 
1380
        else:
 
1381
            ROT = float(ROT)
 
1382
        #say('module pos & rot '+str(X1)+' '+str(Y1)+' '+str(ROT)+'\n')
 
1383
        #
 
1384
        for pad in getPadsList(module):
 
1385
            #say (pad)
 
1386
            #say("\r\n")
 
1387
            #   pads.append({'x': x, 'y': y, 'rot': rot, 'padType': pType, 'padShape': pShape, 'rx': drill_x, 'ry': drill_y, 'dx': dx, 'dy': dy, 'holeType': hType, 'xOF': xOF, 'yOF': yOF, 'layers': layers})
 
1388
            pType = pad['padType']
 
1389
            pShape = pad['padShape']
 
1390
            xs = pad['x'] + X1
 
1391
            ys = pad['y'] + Y1
 
1392
            dx = pad['dx']
 
1393
            dy = pad['dy']
 
1394
            hType = pad['holeType']
 
1395
            drill_x = pad['rx']
 
1396
            drill_y = pad['ry']
 
1397
            xOF = pad['xOF']
 
1398
            yOF = pad['yOF']
 
1399
            rot = pad['rot']
 
1400
            if ROT != 0:
 
1401
                rot -= ROT
 
1402
            rx=drill_x
 
1403
            ry=drill_y
 
1404
            rx=float(rx)
 
1405
            ry=float(ry)
 
1406
            numberOfLayers = pad['layers'].split(' ')
 
1407
            #say(numberOfLayers +'\n')
 
1408
            #if pType=="thru_hole":
 
1409
            #pad shape - circle/rec/oval/trapezoid
 
1410
            perc=0
 
1411
            if pShape=="circle" or pShape=="oval":
 
1412
                pShape="oval"
 
1413
                perc=100
 
1414
                # pad type - SMD/thru_hole/connect
 
1415
            if dx>rx and dy>ry:
 
1416
                #say(pType+"\r\n")
 
1417
                #say(str(dx)+"+"+str(rx)+" dx,rx\r\n")
 
1418
                #say(str(dy)+"+"+str(ry)+" dy,ry\r\n")
 
1419
                #say(str(xOF)+"+"+str(yOF)+" xOF,yOF\r\n")
 
1420
                x1=xs+xOF
 
1421
                y1=ys-yOF #yoffset opposite
 
1422
                #say(str(x1)+"+"+str(y1)+" x1,y1\r\n")
 
1423
                top=False
 
1424
                bot=False
 
1425
                if 'F.Cu' in numberOfLayers:
 
1426
                    top=True
 
1427
                if '*.Cu' in numberOfLayers:
 
1428
                    top=True
 
1429
                    bot=True
 
1430
                if 'B.Cu' in numberOfLayers:
 
1431
                    bot=True
 
1432
            if rx!=0:
 
1433
                #say(str(min_drill_size));say(' ');say(rx);say(' ');say(str(ry));say('\n')
 
1434
                #if (rx > min_drill_size):
 
1435
                if (rx >= min_drill_size) or (ry >= min_drill_size):
 
1436
                    #obj=createHole3(xs,ys,rx,ry,"oval",pcbThickness) #need to be separated instructions
 
1437
                    obj=createHole4(xs,ys,rx,ry,"oval") #need to be separated instructions
 
1438
                    #say(HoleList)
 
1439
                    if rot!=0:
 
1440
                        rotateObj(obj, [xs, ys, rot])
 
1441
                    rotateObj(obj, [X1, Y1, ROT])
 
1442
                    HoleList.append(obj)
 
1443
            ### cmt- #todo: pad type trapez
 
1444
    return HoleList
 
1445
###
 
1446
 
 
1447
def Elaborate_Kicad_Board(filename):
 
1448
    global xMax, xmin, yMax, ymin
 
1449
    Levels={}
 
1450
    content=[]
 
1451
    txtFile = __builtin__.open(filename,"r")
 
1452
    content = txtFile.readlines()
 
1453
    content.append(" ")
 
1454
    txtFile.close()
 
1455
    data=''.join(content)
 
1456
    content=re.sub(r'[^\x00-\x7F]+',' ', data)
 
1457
    #say(len(content))
 
1458
    Kicad_Board_elaborated = content #''.join(content)
 
1459
    if save_temp_data:
 
1460
        home = expanduser("~")
 
1461
        t1_name=home+os.sep+'test.txt'
 
1462
        f = __builtin__.open(t1_name,'w')
 
1463
        f.write(Kicad_Board_elaborated) # python will convert \n to os.linesep
 
1464
        f.close() # you can omit in most cases as the destructor will call it        
 
1465
    #say(len(Kicad_Board_elaborated))
 
1466
    #stop
 
1467
    version=getPCBVersion(Kicad_Board_elaborated)
 
1468
    pcbThickness=getPCBThickness(Kicad_Board_elaborated)
 
1469
    say('kicad_pcb version ' +str(version)+'\n')
 
1470
    if version < 3:
 
1471
        QtGui.qApp.restoreOverrideCursor()
 
1472
        reply = QtGui.QMessageBox.information(None,"Error ...","... KICAD pcb version "+ str(version)+" not supported \r\n"+"\r\nplease open and save your board with the latest kicad version")
 
1473
        sys.exit("pcb version not supported")
 
1474
    if version==3:
 
1475
        Edge_Cuts_lvl=28
 
1476
        Top_lvl=15
 
1477
    if version>=4:
 
1478
        Edge_Cuts_lvl=44
 
1479
        Top_lvl=0
 
1480
    # say(Kicad_Board)
 
1481
    modified = ''
 
1482
    j = 0; txt = ''; start = 0; s=0; prev_char="_"
 
1483
    closing_char=""
 
1484
    #print len(Kicad_Board_elaborated)
 
1485
    for i in Kicad_Board_elaborated[1:]:
 
1486
        if i in ['"', "'"] and s == 0:
 
1487
            closing_char=i
 
1488
            if prev_char!="\\":
 
1489
                s = 1
 
1490
        elif i in [closing_char] and s == 1:
 
1491
            if prev_char!="\\":
 
1492
                s = 0
 
1493
        if s == 0:
 
1494
            if i == '(':
 
1495
                j += 1
 
1496
                start = 1
 
1497
            elif i == ')':
 
1498
                j -= 1
 
1499
        txt += i
 
1500
        prev_char=i
 
1501
        if j == 0 and start == 1:
 
1502
            modified += '[start]' + txt.strip() + '[stop]'
 
1503
            txt = ''
 
1504
            start = 0
 
1505
    #say(len(modified))
 
1506
    #stop #maui
 
1507
    layers = re.search(r'\[start\]\(layers(.+?)\)\[stop\]', modified, re.MULTILINE|re.DOTALL).group(0)
 
1508
    for k in re.findall(r'\((.*?) (.*?) .*?\)', layers):
 
1509
        Levels[k[1]] = int(k[0])
 
1510
        if Levels[k[1]] == Edge_Cuts_lvl: ##Edge.Cuts pcb version 4
 
1511
            #myfile3.write(str(k)[8:-2]+'\r\n')
 
1512
            pcbEdgeName=str(k)[8:-2]
 
1513
    if save_temp_data:
 
1514
        home = expanduser("~")
 
1515
        t2_name=home+os.sep+'testM.txt'
 
1516
        f = __builtin__.open(t2_name,'w')
 
1517
        f.write(modified) # python will convert \n to os.linesep
 
1518
        f.close() # you can omit in most cases as the destructor will call it
 
1519
    return modified,Levels,Edge_Cuts_lvl,Top_lvl,version,pcbThickness
 
1520
### end Elaborate_Kicad_Board
 
1521
 
 
1522
def getParts(PCB_Models,Top_lvl,Kicad_Board_elaborated,Levels):
 
1523
    global addVirtual
 
1524
    PCB_Models = []
 
1525
    for i in re.findall(r'\[start\]\(module(.+?)\)\[stop\]', Kicad_Board_elaborated, re.MULTILINE|re.DOTALL):
 
1526
        ### print i
 
1527
        [x, y, rot] = re.search(r'\(at\s+([0-9\.-]*?)\s+([0-9\.-]*?)(\s+[0-9\.-]*?|)\)', i).groups()
 
1528
        layer = re.search(r'\(layer\s+(.+?)\)', i).groups()[0]
 
1529
        x = float(x)
 
1530
        y = float(y) * (-1)
 
1531
        if rot == '':
 
1532
            rot = 0.0
 
1533
        else:
 
1534
            rot = float(rot)
 
1535
        #rot=rot-rotz  #adding vrml module z-rotation
 
1536
        ### print layer
 
1537
        if Levels[layer] == Top_lvl:  # top
 
1538
            side = "Top"
 
1539
        else:
 
1540
            side = "Bottom"
 
1541
            rot *= -1
 
1542
        #model = re.search(r'\(model\s+(.+?)\.wrl',i)
 
1543
        model_name='no3Dmodel'
 
1544
        #side='noLayer'
 
1545
        model_list= re.findall(r'\(model\s+(.+?)\.wrl',i)
 
1546
        for j in range(0,len(model_list)):
 
1547
            rotz_vrml = re.findall(r'\(rotate\s+(.+?)\)', i)
 
1548
            rotz=''
 
1549
            if rotz_vrml:
 
1550
                rotz=rotz_vrml[j]
 
1551
                #say("rotz:"+rotz+"\r\n")
 
1552
                #rotz=rotz[13:-1]
 
1553
                rotz=rotz[5:]
 
1554
                #say("rotz:"+rotz+"\r\n")
 
1555
                temp=rotz.split(" ")
 
1556
                #say("rotz temp:"+temp[2]+"\r\n")
 
1557
                rotz=temp[2]
 
1558
                #say("rotate vrml: "+rotz+"\r\n")
 
1559
            if rotz=='':
 
1560
                rotz=0.0
 
1561
            else:
 
1562
                rotz=float(rotz)
 
1563
            rot=rot-rotz  #adding vrml module z-rotation
 
1564
            model=model_list[j]+'.wrl'
 
1565
            #say (model+'\r')
 
1566
            #virtual = re.search(r'\(attr\s+(.+?)virtual\)',i)
 
1567
            virtual=0
 
1568
            if (i.find("virtual")!=-1):
 
1569
                virtual=1
 
1570
            if (virtual==1 and addVirtual==0):
 
1571
                model_name='no3Dmodel'
 
1572
                side='noLayer'
 
1573
            else:
 
1574
                if model:
 
1575
                    # print model.group(0)
 
1576
                    #model_name=model.group(0)[6:]
 
1577
                    #model_name=model[6:]
 
1578
                    model_name=model
 
1579
                    #model_name=model_name[1:]
 
1580
                    #print model_name
 
1581
                else:
 
1582
                    model_name='no3Dmodel'
 
1583
                    side='noLayer'
 
1584
                line = []
 
1585
                line.append(model_name)
 
1586
                line.append(x)
 
1587
                line.append(y)
 
1588
                line.append(rot)
 
1589
                line.append(side)
 
1590
                PCB_Models.append(line)
 
1591
        ##virtual = re.search(r'\(attr\s+(.+?)virtual\)',i)
 
1592
    ####
 
1593
    # print i
 
1594
    # print PCB_EL
 
1595
    return PCB_Models
 
1596
### end getParts
 
1597
 
 
1598
def getPCBThickness(Board):
 
1599
    #print len(Kicad_Board)
 
1600
    return float(re.findall(r'\(thickness (.+?)\)', Board)[0])
 
1601
 
 
1602
def getPCBVersion(Board):
 
1603
    return int(re.findall(r'\(kicad_pcb \(version (.+?)\)', Board)[0])
 
1604
 
 
1605
def getPCBArea(Kicad_Board):
 
1606
    area = (re.findall(r'\(area (.+?)\)', Kicad_Board)[0])
 
1607
    # print area
 
1608
    return area
 
1609
 
 
1610
def createSolidBBox(model3D):
 
1611
    selEx=model3D
 
1612
    selEx = FreeCADGui.Selection.getSelectionEx()
 
1613
    objs = [selobj.Object for selobj in selEx]
 
1614
    if len(objs) == 1:
 
1615
        s = objs[0].Shape
 
1616
        name=objs[0].Label
 
1617
        FreeCAD.Console.PrintMessage(name+" name \r\n")
 
1618
        # boundBox
 
1619
        boundBox_ = s.BoundBox
 
1620
        boundBoxLX = boundBox_.XLength
 
1621
        boundBoxLY = boundBox_.YLength
 
1622
        boundBoxLZ = boundBox_.ZLength
 
1623
        a = str(boundBox_)
 
1624
        a,b = a.split('(')
 
1625
        c = b.split(',')
 
1626
        oripl_X = float(c[0])
 
1627
        oripl_Y = float(c[1])
 
1628
        oripl_Z = float(c[2])
 
1629
        #say(str(boundBox_)+"\r\n")
 
1630
        #say("Rectangle : "+str(boundBox_.XLength)+" x "+str(boundBox_.YLength)+" x "+str(boundBox_.ZLength)+"\r\n")
 
1631
        #say("_____________________"+"\r\n")
 
1632
        #say("x: "+str(oripl_X)+" y: "+str(oripl_Y)+"z: "+str(oripl_Z)+"\r\n")
 
1633
        obj=FreeCAD.ActiveDocument.addObject('Part::Feature',name)
 
1634
        obj.Shape=Part.makeBox(boundBox_.XLength, boundBox_.YLength, boundBox_.ZLength, FreeCAD.Vector(oripl_X,oripl_Y,oripl_Z), FreeCAD.Vector(0,0,01))
 
1635
        # Part.show(cube)
 
1636
        #say("cube name "+ obj.Name+'\r\n')
 
1637
    else:
 
1638
        FreeCAD.Console.PrintMessage("Select a single part object !"+"\r\n")
 
1639
    #end bbox macro
 
1640
    name=obj.Name
 
1641
    #say("bbox name "+name+"\n")
 
1642
    return name
 
1643
    del objs
 
1644
### end createSolidBBox  
 
1645
 
 
1646
def findPcbCenter(pcbName):
 
1647
    pcb = FreeCAD.ActiveDocument.getObject(pcbName)
 
1648
    s=pcb.Shape
 
1649
    name=pcb.Label
 
1650
    # boundBox
 
1651
    boundBox_ = s.BoundBox
 
1652
    boundBoxLX = boundBox_.XLength
 
1653
    boundBoxLY = boundBox_.YLength
 
1654
    boundBoxLZ = boundBox_.ZLength
 
1655
    center = s.BoundBox.Center
 
1656
    #say(center)
 
1657
    #say("["+str(center.x)+"],["+str(center.y)+"] center of pcb\r\n")
 
1658
    a = str(boundBox_)
 
1659
    a,b = a.split('(')
 
1660
    c = b.split(',')
 
1661
    oripl_X = float(c[0])
 
1662
    oripl_Y = float(c[1])
 
1663
    oripl_Z = float(c[2])
 
1664
    #say(str(boundBox_)+"\r\n")
 
1665
    #say("Rectangle : "+str(boundBox_.XLength)+" x "+str(boundBox_.YLength)+" x "+str(boundBox_.ZLength)+"\r\n")
 
1666
    #say("_____________________"+"\r\n")
 
1667
    #say("x: "+str(oripl_X)+" y: "+str(oripl_Y)+"z: "+str(oripl_Z)+"\r\n")
 
1668
    center_x=center.x; center_y=center.y
 
1669
    bb_x=boundBox_.XLength; bb_y=boundBox_.YLength
 
1670
    return center_x, center_y, bb_x, bb_y
 
1671
### end findPcbCenter
 
1672
 
 
1673
def getArc_minMax(xC,xA,yC,yA,alpha):
 
1674
    # x1=xA start point; x2=xC center; xB end point; alpha=angle
 
1675
    global xMax, xmin, yMax, ymin
 
1676
    j=0
 
1677
    R=sqrt((xA-xC)**2+(yA-yC)**2)
 
1678
    #say('R = '+str(R))
 
1679
    if (xA>=xC) and (yA<yC):
 
1680
        beta=atan(abs(xA-xC)/abs(yA-yC))
 
1681
        j=1; ABeta=(alpha+beta)
 
1682
        #say(str(degrees(beta))+" beta "+ str(degrees(ABeta))+" ABeta\r\n")
 
1683
        #cases if (xA>xC) and (yA<yC):
 
1684
        if ABeta >= beta and ABeta <= pi/2:
 
1685
            xB=R*sin(alpha+beta)+xC
 
1686
            xMax=max(xB,xMax)
 
1687
            xmin= min(xA,xmin)
 
1688
            yB=yC-R*cos(alpha+beta)
 
1689
            yMax= max(yB, yMax)
 
1690
            ymin= min(yA, ymin)
 
1691
        if ABeta >pi/2 and ABeta <=pi:
 
1692
            xMax = max(R+xC,xMax)
 
1693
            xB=R*sin(alpha+beta)+xC
 
1694
            xmin = min(xA, xB, xmin)
 
1695
            # yB = yC+R*cos(pi-(alpha+beta))
 
1696
            yB=yC-R*cos(alpha+beta)
 
1697
            yMax = max(yB, yMax)
 
1698
            ymin = min(yA, ymin)
 
1699
        if ABeta >pi and ABeta <=3/2*pi:
 
1700
            xB=R*sin(alpha+beta)+xC
 
1701
            xMax=max(R+xC,xMax)
 
1702
            xmin = min(xB,xmin)
 
1703
            yB=yC-R*cos(alpha+beta)
 
1704
            yMax = max(yC+R, yMax)
 
1705
            ymin = min(yA, ymin)
 
1706
        if ABeta >3/2*pi and ABeta <= 2*pi:
 
1707
            xB=R*sin(alpha+beta)+xC
 
1708
            xMax=max(R+xC,xMax)
 
1709
            xmin = min(xC-R,xmin)
 
1710
            yB=yC-R*cos(alpha+beta)
 
1711
            yMax = max(yC+R, yMax)
 
1712
            ymin = min(yA, yB, ymin)
 
1713
        if ABeta >2*pi and ABeta <= 2*pi+beta:
 
1714
            xmin = min(xC-R,xmin)
 
1715
            xMax = max(R+xC,xMax)
 
1716
            ymin = min(yC-R, ymin)
 
1717
            yMax = max(yC+R, yMax)
 
1718
    if (xA>xC) and (yA>=yC):
 
1719
        beta=atan(abs(yA-yC)/abs(xA-xC))
 
1720
        j=2; ABeta=(alpha+beta)
 
1721
        #say(str(degrees(beta))+" beta "+ str(degrees(ABeta))+" ABeta\r\n")
 
1722
        yB=yC+R*sin(ABeta)
 
1723
        xB=xC+R*cos(ABeta)
 
1724
        if ABeta >= beta and ABeta <= pi/2:
 
1725
            xMax=max(xA,xMax)
 
1726
            xmin= min(xB,xmin)
 
1727
            yMax= max(yB, yMax)
 
1728
            ymin= min(yA, ymin)
 
1729
        if ABeta > pi/2 and ABeta <= pi:
 
1730
            xmin= min(xB,xmin)
 
1731
            xMax=max(xA,xMax)
 
1732
            ymin= min(yA, yB, ymin)
 
1733
            yMax= max(yC+R, yMax)
 
1734
        if ABeta > pi and ABeta <= 3/2*pi:
 
1735
            xmin= min(xC-R,xmin)
 
1736
            xMax=max(xA,xMax)
 
1737
            ymin= min(yB, ymin)
 
1738
            yMax= max(yC+R, yMax)
 
1739
        if ABeta > 3/2*pi and ABeta <= 2*pi:
 
1740
            xmin= min(xC-R,xmin)
 
1741
            xMax= max(xA,xB,xMax)
 
1742
            ymin= min(yC-R, ymin)
 
1743
            yMax= max(yC+R, yMax)
 
1744
        if ABeta > 2*pi and ABeta <= beta+2*pi:
 
1745
            xmin= min(xC-R,xmin)
 
1746
            xMax= max(xC+R,xMax)
 
1747
            ymin= min(yC-R, ymin)
 
1748
            yMax= max(yC+R, yMax)
 
1749
    if (xA<=xC) and (yA>yC):
 
1750
        beta=atan(abs(xA-xC)/abs(yA-yC))
 
1751
        j=3; ABeta=(alpha+beta)
 
1752
        #say(str(degrees(beta))+" beta "+ str(degrees(ABeta))+" ABeta\r\n")
 
1753
        yB=yC+R*cos(ABeta)
 
1754
        xB=xC-R*sin(ABeta)
 
1755
        if ABeta >= beta and ABeta <= pi/2:
 
1756
            xMax= max(xA,xMax)
 
1757
            xmin= min(xB,xmin)
 
1758
            yMax= max(yA, yMax)
 
1759
            ymin= min(yB, ymin)
 
1760
        if ABeta > pi/2 and ABeta <= pi:
 
1761
            xmin= min(xC-R,xmin)
 
1762
            xMax= max(xA,xB,xMax)
 
1763
            ymin= min(yB,ymin)
 
1764
            yMax= max(yA,yMax)
 
1765
        if ABeta > pi and ABeta <= 3/2*pi:
 
1766
            xmin= min(xC-R,xmin)
 
1767
            xMax= max(xB,xMax)
 
1768
            ymin= min(yC-R, ymin)
 
1769
            yMax= max(yA, yMax)
 
1770
        if ABeta > 3/2*pi and ABeta <= 2*pi:
 
1771
            xmin= min(xC-R,xmin)
 
1772
            xMax= max(xC+R,xMax)
 
1773
            ymin= min(yC-R, ymin)
 
1774
            yMax= max(yA,yB, yMax)
 
1775
        if ABeta > 2*pi and ABeta <= beta+2*pi:
 
1776
            xmin= min(xC-R,xmin)
 
1777
            xMax= max(xC+R,xMax)
 
1778
            ymin= min(yC-R, ymin)
 
1779
            yMax= max(yC+R, yMax)
 
1780
    if (xA<xC) and (yA<=yC):
 
1781
        beta=atan(abs(yA-yC)/abs(xA-xC))
 
1782
        j=4; ABeta=(alpha+beta)
 
1783
        #say(str(degrees(beta))+" beta "+ str(degrees(ABeta))+" ABeta\r\n")
 
1784
        yB=yC-R*sin(ABeta)
 
1785
        xB=xC-R*cos(ABeta)
 
1786
        if ABeta >= beta and ABeta <= pi/2:
 
1787
            xMax= max(xB,xMax)
 
1788
            xmin= min(xA,xmin)
 
1789
            yMax= max(yA, yMax)
 
1790
            ymin= min(yB, ymin)
 
1791
        if ABeta > pi/2 and ABeta <= pi:
 
1792
            xmin= min(xA,xmin)
 
1793
            xMax= max(xB,xMax)
 
1794
            ymin= min(yC-R,ymin)
 
1795
            yMax= max(yA,yB,yMax)
 
1796
        if ABeta > pi and ABeta <= 3/2*pi:
 
1797
            xmin= min(xA,xmin)
 
1798
            xMax= max(xC+R,xMax)
 
1799
            ymin= min(yC-R, ymin)
 
1800
            yMax= max(yB, yMax)
 
1801
        if ABeta > 3/2*pi and ABeta <= 2*pi:
 
1802
            xmin= min(xA,xB,xmin)
 
1803
            xMax= max(xC+R,xMax)
 
1804
            ymin= min(yC-R,ymin)
 
1805
            yMax= max(yC+R, yMax)
 
1806
        if ABeta > 2*pi and ABeta <= beta+2*pi:
 
1807
            xmin= min(xC-R,xmin)
 
1808
            xMax= max(xC+R,xMax)
 
1809
            ymin= min(yC-R, ymin)
 
1810
            yMax= max(yC+R, yMax)
 
1811
    #say(str(j)+" case j\r\n")
 
1812
    #say('xC='+str(xC)+';yC='+str(yC)+';xA='+str(xA)+';yA='+str(yA)+'\r\n')
 
1813
    #print x1,x2,y1,y2
 
1814
    #calculating xmin of arc
 
1815
    R=sqrt((xA-xC)**2+(yA-yC)**2)
 
1816
    #say('R = '+str(R))
 
1817
    #say(str(xMax)+" xMax\r\n")
 
1818
    #say(str(xmin)+" xmin\r\n")
 
1819
    # print xMax, xmin, yMax, ymin
 
1820
    # print pcbarcs[n]
 
1821
    #print (pcbarcs[n][8:].split(' ')[0])
 
1822
    return 0
 
1823
### end getArc_minMax
 
1824
 
 
1825
def mid_point(prev_vertex,vertex,angle):
 
1826
    """mid_point(prev_vertex,vertex,angle)-> mid_vertex
 
1827
       returns mid point on arc of angle between prev_vertex and vertex"""
 
1828
    angle=radians(angle/2)
 
1829
    basic_angle=atan2(vertex.y-prev_vertex.y,vertex.x-prev_vertex.x)-pi/2
 
1830
    shift=(1-cos(angle))*hypot(vertex.y-prev_vertex.y,vertex.x-prev_vertex.x)/2/sin(angle)
 
1831
    midpoint=Base.Vector((vertex.x+prev_vertex.x)/2+shift*cos(basic_angle),(vertex.y+prev_vertex.y)/2+shift*sin(basic_angle),0)
 
1832
    return midpoint
 
1833
###
 
1834
 
 
1835
def Per_point(prev_vertex,vertex):
 
1836
    """Per_point(center,vertex)->per point
 
1837
 
 
1838
       returns opposite perimeter point of circle"""
 
1839
    #basic_angle=atan2(prev_vertex.y-vertex.y,prev_vertex.x-vertex.x)
 
1840
    #shift=hypot(prev_vertex.y-vertex.y,prev_vertex.x-vertex.x)
 
1841
    #perpoint=Base.Vector(prev_vertex.x+shift*cos(basic_angle),prev_vertex.y+shift*sin(basic_angle),0)
 
1842
    perpoint=Base.Vector(2*prev_vertex.x-vertex.x,2*prev_vertex.y-vertex.y,0)
 
1843
    return perpoint
 
1844
###    
60
1845
 
61
1846
#os.system("ps -C 'kicad-SteUp-tool' -o pid=|xargs kill -9")
62
1847
 
63
1848
# UI Class definitions
64
 
 
 
1849
##if _platform == "linux" or _platform == "linux2":
 
1850
##   # linux
 
1851
##elif _platform == "darwin":
 
1852
##   # MAC OS X
 
1853
##elif _platform == "win32":
 
1854
##   # Windows
 
1855
 
 
1856
#####################################
 
1857
# Function infoDialog 
 
1858
#####################################
 
1859
def infoDialog(msg):
 
1860
    #QtGui.qFreeCAD.setOverrideCursor(QtCore.Qt.WaitCursor)
 
1861
    QtGui.qFreeCAD.restoreOverrideCursor()
 
1862
    QtGui.qApp.restoreOverrideCursor()
 
1863
    diag = QtGui.QMessageBox(QtGui.QMessageBox.Information,u"Info Message",msg )
 
1864
    diag.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
 
1865
    diag.exec_()
 
1866
    QtGui.qFreeCAD.restoreOverrideCursor()
 
1867
 
 
1868
 
 
1869
##  getAuxAxisOrigin
 
1870
def getAuxAxisOrigin():
 
1871
    match = re.search(r'\(aux_axis_origin (.+?) (.+?)\)', Kicad_Board)
 
1872
    return [float(match.group(1)), float(match.group(2))];
 
1873
 
 
1874
 
 
1875
#####################################
 
1876
# Main Class
 
1877
#####################################
65
1878
class RotateXYZGuiClass(QtGui.QWidget):
66
1879
    """"""
67
1880
    def closeEvent(self, e):
68
1881
        msg="""<b>Do you want to quit?</b>
69
1882
            <font color='white'>****************************************************************************</font><br>
70
 
            <i>Have you saved your STEP module</i><br>
71
 
            <i>with the aligned Placement?</i>
 
1883
            <i>Have you saved your STEP artwork?</i><br>
72
1884
            """
73
1885
        #confirm on exit
74
 
        res = QtGui.QMessageBox.question(None,"Close",msg,QtGui.QMessageBox.Yes|QtGui.QMessageBox.No)
 
1886
        QtGui.qApp.restoreOverrideCursor()
 
1887
        self.setGeometry(25, 250, 500, 500)
 
1888
        #self.setWindowState(QtCore.Qt.WindowMinimized)
 
1889
        res=''
 
1890
        if test_flag_exit==False:
 
1891
            QtGui.qApp.restoreOverrideCursor()
 
1892
            res = QtGui.QMessageBox.question(None,"Close",msg,QtGui.QMessageBox.Yes|QtGui.QMessageBox.No)
75
1893
        if res is QtGui.QMessageBox.No:
76
1894
            e.ignore()
77
 
 
 
1895
            #self.setWindowState(QtCore.Qt.WindowActive)
 
1896
        doc=FreeCAD.ActiveDocument
 
1897
        if doc!= None:
 
1898
            FreeCAD.setActiveDocument(doc.Name)
 
1899
        #FreeCAD.ActiveDocument=FreeCAD.getDocument(doc.Label)
 
1900
        #FreeCADGui.ActiveDocument=FreeCADGui.getDocument(doc.Label)
 
1901
            if close_doc==True:
 
1902
                FreeCAD.closeDocument(doc.Name)
 
1903
            say(doc.Label+'\n')
 
1904
        
78
1905
    def link(self, linkStr):
79
1906
        QtGui.QDesktopServices.openUrl(QtCore.QUrl(linkStr))
80
1907
 
84
1911
    def initUI(self):
85
1912
        self.result = userCancelled
86
1913
        # set up a monospace font for the Labels to match button dimension
87
 
 
 
1914
        global export_board_2step
88
1915
        # create our window
89
1916
        # define window        xLoc,yLoc,xDim,yDim
90
 
        self.setGeometry(25, 250, 500, 440)
 
1917
        self.setGeometry(25, 250, 500, 500)
91
1918
        #self.setWindowTitle("Move, Rotate and Scale model XYZ")
92
1919
        self.setWindowTitle("kicad StepUp 3D tools")
93
1920
        self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
170
1997
        self.label20.linkActivated.connect(self.link)
171
1998
        self.label20.setText('<a href="https://github.com/easyw/kicad-3d-models-in-freecad/tree/master/cadquery/FCAD_script_generator">3D models</a>')
172
1999
        self.label20.move(410,410)
173
 
 
 
2000
        self.label23 = QtGui.QLabel("               ", self)
 
2001
        self.label23.linkActivated.connect(self.link)
 
2002
        self.label23.setText('<a href="https://github.com/easyw/kicad-3d-mcad-models">kicad MCAD<br>3D libraries</a>')
 
2003
        self.label23.move(410,430)
 
2004
        #
 
2005
        ##
 
2006
        home = expanduser("~")
 
2007
        ini_file_full_path='<b>'+home+os.sep+'ksu-config.ini</b>'
 
2008
        self.label24 = QtGui.QLabel(ini_file_full_path, self)
 
2009
        self.label24.move(500,20)
 
2010
        self.textEdit = QtGui.QTextEdit(self)
 
2011
        self.textEdit.setGeometry(QtCore.QRect(500, 40, 380, 440))
 
2012
        self.textEdit.setObjectName("textEdit")
 
2013
        self.textEdit.setReadOnly(True)
 
2014
        #self.textEdit.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse)            #
 
2015
        #self.textEdit.setText("TexEdit ")
 
2016
        self.textEdit.setText(ini_content)
 
2017
        #self.textEdit.setToolTip("ksu config ini file")
 
2018
        self.textEdit.verticalScrollBar().setValue(0)                                      # verticalScrollBar Position
 
2019
        self.textEdit.verticalScrollBar().setSliderPosition(0)                             # Slider Position
 
2020
        #self.textEdit.horizontalScrollBar.setValue(0)
 
2021
        # verticalScrollBar Position
 
2022
        #self.textEdit.horizontalScrollBar().setSliderPosition(0)                             # Slider Position
 
2023
        #self.textEdit.textChanged.connect(self.on_textEdit_Changed)                         #connection on_textEdit_Changed        
 
2024
        ##
 
2025
        
174
2026
        # text input field
175
2027
        self.textInputX = QtGui.QLineEdit(self)
176
2028
        #self.textInput.setInputMask("+-999.")
239
2091
        MoveToZ.setMinimumWidth(100)
240
2092
        MoveToZ.move(250, 100)
241
2093
        ###
242
 
        # Test button
243
 
        ##TestB = QtGui.QPushButton('Test', self)
244
 
        ##TestB.clicked.connect(self.onTest)
245
 
        ##TestB.setFixedWidth(40)
246
 
        ##TestB.move(440, 20)
 
2094
        # Cfg button
 
2095
        CfgB = QtGui.QPushButton('Config', self)
 
2096
        CfgB.clicked.connect(self.onCfg)
 
2097
        CfgB.setFixedWidth(50)
 
2098
        CfgB.move(430, 20)
 
2099
        # Hide button
 
2100
        HideB = QtGui.QPushButton('<<<', self)
 
2101
        HideB.clicked.connect(self.onHide)
 
2102
        HideB.setFixedWidth(50)
 
2103
        HideB.move(430, 60)
247
2104
        ###
248
 
        # TranslateX button
 
2105
        # Help button
 
2106
        HelpB = QtGui.QPushButton('Help', self)
 
2107
        HelpB.clicked.connect(self.onHelp)
 
2108
        HelpB.setFixedWidth(50)
 
2109
        HelpB.move(430, 100)
 
2110
        ###        # TranslateX button
249
2111
        TranslateX = QtGui.QPushButton('Translate X', self)
250
2112
        TranslateX.clicked.connect(self.onTranslateX)
251
2113
        TranslateX.setMinimumWidth(100)
262
2124
        TranslateZ.move(130, 240)
263
2125
 
264
2126
        # Scale Obj button
265
 
        ScaleVRML = QtGui.QPushButton('Scale to kicad\r\nVRML (1/2.54)', self)
 
2127
        ScaleVRML = QtGui.QPushButton("Export to kicad: STEP\r\n&& scaled VRML 1/2.54", self)
266
2128
        ScaleVRML.clicked.connect(self.onScaleVRML)
267
2129
        ScaleVRML.setMinimumWidth(150)
268
2130
        ScaleVRML.setMinimumHeight(40)
270
2132
 
271
2133
        # Load Footprint button
272
2134
        LoadFootprint = QtGui.QPushButton('Load kicad\r\nFootprint module', self)
273
 
        LoadFootprint.clicked.connect(self.onLoadFootprint)
 
2135
        LoadFootprint.clicked.connect(self.onLoadFootprint_click)
274
2136
        LoadFootprint.setMinimumWidth(150)
275
2137
        LoadFootprint.setMinimumHeight(40)
276
2138
        LoadFootprint.move(250, 390)
346
2208
        self.checkBox_1.setChecked(True)  # Check by default True or False
347
2209
        self.checkBox_1.clicked.connect(self.on_checkBox_1_clicked)  # connect on def "on_checkBox_1_clicked"
348
2210
 
 
2211
        # section checkBox export step
 
2212
        self.checkBox_2 = QtGui.QCheckBox('exp2\nstep', self)                                    # create object QRadioButton in groupBox
 
2213
        self.checkBox_2.setGeometry(QtCore.QRect(165, 425, 165, 60))
 
2214
        self.checkBox_2.setObjectName(('export all to step')) # name of object
 
2215
        if export_board_2step==False:
 
2216
            #export_board_2step=False
 
2217
            self.checkBox_2.setChecked(False)  # Check by default True or False
 
2218
        else:
 
2219
            self.checkBox_2.setChecked(True)  # Check by default True or False
 
2220
        #export_board_2step=True
 
2221
        self.checkBox_2.clicked.connect(self.on_checkBox_2_clicked)  # connect on def "on_checkBox_1_clicked"
 
2222
        
 
2223
        # Load Kicad Board button
 
2224
        LoadBoard = QtGui.QPushButton('Load kicad\nBoard *.kicad_pcb', self)
 
2225
        LoadBoard.clicked.connect(self.onLoadBoard_click)
 
2226
        LoadBoard.setMinimumWidth(180)
 
2227
        LoadBoard.setMinimumHeight(40)
 
2228
        LoadBoard.move(220, 440)
 
2229
        
 
2230
        # Load IDF Board button
 
2231
        LoadBoardIdf = QtGui.QPushButton('Load kicad Board\nwith IDF *.emn', self)
 
2232
        LoadBoardIdf.clicked.connect(self.onLoadBoard_idf_click)
 
2233
        LoadBoardIdf.setMinimumWidth(140)
 
2234
        LoadBoardIdf.setMinimumHeight(40)
 
2235
        LoadBoardIdf.move(20, 440)
 
2236
        
 
2237
        default_value='/'
 
2238
        module_3D_dir=os.getenv('KISYS3DMOD', default_value)
 
2239
        module_3D_dir=module_3D_dir+'/'
 
2240
        label_3d=module_3D_dir
 
2241
 
349
2242
        # cancel button
350
2243
        ## cancelButton = QtGui.QPushButton('Cancel', self)
351
2244
        ## cancelButton.clicked.connect(self.onCancel)
371
2264
        self.label19.setFont(font)
372
2265
        self.label20.setFont(font)
373
2266
        self.label21.setFont(font)
 
2267
        self.label23.setFont(font)
 
2268
        self.label24.setFont(font)
374
2269
        self.label30.setFont(font)
375
2270
        self.textInputX.setFont(font)
376
2271
        self.textInputY.setFont(font)
392
2287
        TranslateZ.setFont(font)
393
2288
        ScaleVRML.setFont(font)
394
2289
        LoadFootprint.setFont(font)
 
2290
        LoadBoard.setFont(font)
 
2291
        LoadBoardIdf.setFont(font)
 
2292
        CfgB.setFont(font)
 
2293
        HideB.setFont(font)
 
2294
        HelpB.setFont(font)
395
2295
        ResetPlacement.setFont(font)
396
2296
        GetPos.setFont(font)
397
2297
        CenterX.setFont(font)
402
2302
        PutOnZ.setFont(font)
403
2303
        CreateAxis.setFont(font)
404
2304
        self.checkBox_1.setFont(font)
 
2305
        self.checkBox_2.setFont(font)
 
2306
        #self.checkBox_3.setFont(font)
405
2307
        self.labelVerMsg.setFont(font)
406
2308
        checkCollisions.setFont(font)
407
 
 
 
2309
        self.textEdit.setFont(font)
 
2310
        
408
2311
        # now make the window visible
409
2312
        self.show()
410
2313
        #
411
2314
 
412
2315
    def on_checkBox_1_clicked(self):
413
2316
        global resetP
414
 
        App.Console.PrintMessage("checkbox clicked"+"\r\n")
 
2317
        say("reset position clicked"+"\r\n")
415
2318
        if self.checkBox_1.isChecked():
416
2319
            resetP=True
417
2320
        else:
418
2321
            resetP=False
419
2322
 
 
2323
    def on_checkBox_2_clicked(self):
 
2324
        global export_board_2step
 
2325
        if self.checkBox_2.isChecked():
 
2326
            export_board_2step=True
 
2327
            cfgParsWrite(configFilePath)
 
2328
        else:
 
2329
            export_board_2step=False
 
2330
            cfgParsWrite(configFilePath)
 
2331
        say("export to STEP "+str(export_board_2step)+"\r\n")
 
2332
 
420
2333
    def onRotateX(self):
421
 
        App.Console.PrintMessage("RotateX!"+"\r\n")
 
2334
        FreeCAD.Console.PrintMessage("RotateX!"+"\r\n")
422
2335
        alpha=self.textInputRX.text()
423
2336
        alpha=alpha.replace(',', '.')
424
2337
        angle=alpha.split('.')
429
2342
        self.label11.setText("Y:"+str(position[1]))
430
2343
        self.label12.setText("Z:"+str(position[2]))
431
2344
    def onRotateY(self):
432
 
        App.Console.PrintMessage("RotateY!"+"\r\n")
 
2345
        FreeCAD.Console.PrintMessage("RotateY!"+"\r\n")
433
2346
        alpha=self.textInputRY.text()
434
2347
        alpha=alpha.replace(',', '.')
435
2348
        angle=alpha.split('.')
440
2353
        self.label11.setText("Y:"+str(position[1]))
441
2354
        self.label12.setText("Z:"+str(position[2]))
442
2355
    def onRotateZ(self):
443
 
        App.Console.PrintMessage("RotateZ!"+"\r\n")
 
2356
        FreeCAD.Console.PrintMessage("RotateZ!"+"\r\n")
444
2357
        alpha=self.textInputRZ.text()
445
2358
        alpha=alpha.replace(',', '.')
446
2359
        angle=alpha.split('.')
453
2366
    def onTranslateX(self):
454
2367
        v=self.textInputX.text()
455
2368
        v=v.replace(',', '.')
456
 
        App.Console.PrintMessage(v+"\r\n")
 
2369
        FreeCAD.Console.PrintMessage(v+"\r\n")
457
2370
        routineT_XYZ('x',v)
458
2371
        position=get_position()
459
2372
        self.label10.setText("X:"+str(position[0]))
462
2375
    def onTranslateY(self):
463
2376
        v=self.textInputY.text()
464
2377
        v=v.replace(',', '.')
465
 
        App.Console.PrintMessage(v+"\r\n")
 
2378
        FreeCAD.Console.PrintMessage(v+"\r\n")
466
2379
        routineT_XYZ('y',v)
467
2380
        position=get_position()
468
2381
        self.label10.setText("X:"+str(position[0]))
471
2384
    def onTranslateZ(self):
472
2385
        v=self.textInputZ.text()
473
2386
        v=v.replace(',', '.')
474
 
        App.Console.PrintMessage(v+"\r\n")
 
2387
        FreeCAD.Console.PrintMessage(v+"\r\n")
475
2388
        routineT_XYZ('z',v)
476
2389
        position=get_position()
477
2390
        self.label10.setText("X:"+str(position[0]))
480
2393
    def onMoveToX(self):
481
2394
        v=self.textInputMX.text()
482
2395
        v=v.replace(',', '.')
483
 
        App.Console.PrintMessage(v+"\r\n")
 
2396
        FreeCAD.Console.PrintMessage(v+"\r\n")
484
2397
        routineM_XYZ('x',v)
485
2398
        position=get_position()
486
2399
        self.label10.setText("X:"+str(position[0]))
489
2402
    def onMoveToY(self):
490
2403
        v=self.textInputMY.text()
491
2404
        v=v.replace(',', '.')
492
 
        App.Console.PrintMessage(v+"\r\n")
 
2405
        FreeCAD.Console.PrintMessage(v+"\r\n")
493
2406
        routineM_XYZ('y',v)
494
2407
        position=get_position()
495
2408
        self.label10.setText("X:"+str(position[0]))
498
2411
    def onMoveToZ(self):
499
2412
        v=self.textInputMZ.text()
500
2413
        v=v.replace(',', '.')
501
 
        App.Console.PrintMessage(v+"\r\n")
 
2414
        FreeCAD.Console.PrintMessage(v+"\r\n")
502
2415
        routineM_XYZ('z',v)
503
2416
        position=get_position()
504
2417
        self.label10.setText("X:"+str(position[0]))
505
2418
        self.label11.setText("Y:"+str(position[1]))
506
2419
        self.label12.setText("Z:"+str(position[2]))
507
 
    def onTest(self):
508
 
        #createPad2(0,0,3,5,0.2,0.4,2,3,'oval','top')
509
 
        ##pad pos x,y; pad size x,y; drillcenter x,y; drill size x,y, layer
510
 
        #createPad2(0,0,5,5,0.2,0.4,3,3,'oval','bot')
511
 
        createPad3(1,0,5,5,1,0,3,3,'oval','top')
512
 
        createPad3(-1,0,5,5,-1,0,3,3,'oval','bot')
513
 
        ##pad pos x,y; pad size x,y; drillcenter x,y; drill size x,y, type, layer
514
 
        #createPad2(0,0,5,7,0,0,0,0,'oval','top')
515
 
 
516
 
        #createPad2(0,0,5,5,0.2,0.4,3,3,'oval','top')
517
 
        #mytest=addPadLong2(.5, .7, 1, 2, 100, 0, 0)
518
 
        #Part.show(mytest)
519
 
        #pad center x,y pad dimension dx,dy, type, z offset, hole presence
 
2420
    def onCfg(self):
 
2421
        #QtGui.QMessageBox.information(None,"info ...","your home path is \r\n"+ home+"\r\n")
 
2422
        say("your home path is "+ expanduser("~")+"\r\n")
 
2423
        self.setGeometry(25, 250, 900, 500)
 
2424
        ini_content=read_ini_file()
 
2425
        self.textEdit.setText(ini_content)
 
2426
        cfgParsRead(configFilePath)
 
2427
        
 
2428
    def onHide(self):
 
2429
        self.setGeometry(25, 250, 500, 500)
 
2430
        global configFilePath, ini_content
 
2431
        ini_content=read_ini_file()
 
2432
        self.textEdit.setText(ini_content)
 
2433
        #configParser.read(configFilePath)
 
2434
        cfgParsRead(configFilePath)
 
2435
        #bklist = configParser.get('Blacklist', 'bklist')
 
2436
        #say(configFilePath+'\n')
 
2437
        #say(bklist+'\n')
 
2438
    def onHelp(self):
 
2439
        self.setGeometry(25, 250, 900, 500)
 
2440
        sayw("kicad StepUp version "+str(___ver___))
 
2441
        help_txt="""<font color=GoldenRod><b>kicad StepUp version """+___ver___+"""</font></b><br>"""
 
2442
        help_txt+="""<b>Kicad StepUp</b> is a tool set to easily export your kicad pcb EDA (board and 3D parts) to STEP model.<br>"""
 
2443
        help_txt+="The artwork can be used for MCAD interchange and collaboration, and for enclosure design.<br>"
 
2444
        help_txt+="The 3D visualization of components on board assemblies in kicad 3dviewer, will be the same in your mechanical software, "
 
2445
        help_txt+="because of the STEP interchange format.<br>"
 
2446
        help_txt+="<br><b>First of all:</b> configure your path to 3D models in <br><i><b>ksu-config.ini</b></i> file<br>"
 
2447
        help_txt+="useful buttons:<br><b>Load kicad Board</b> -> will load directly board and parts in FreeCAD<br>"
 
2448
        help_txt+="<b>Load kicad Footprint module</b> -> will load directly kicad footprint in FreeCAD to easily align the 3D model to footprint<br>"
 
2449
        help_txt+="<b>Export to kicad STEP & scaled VRML</b> -> will convert MCAD model to STEP and VRML to be used by Kicad and kicad StepUp<br>"
 
2450
        help_txt+="<b>Load kicad Board with IDF</b> -> will load kicad board and parts in FreeCAD coming from IDF exported board from kicad<br>"
 
2451
        help_txt+="for a more detailed help have a look at <br><b>kicadStepUp-starter-Guide.pdf</b><br><br>"
 
2452
        help_txt+="Designing in kicad native 3d-viewer will produce a fully aligned STEP MCAD version "
 
2453
        help_txt+="with the same view of kicad 3d render.<br>"
 
2454
        help_txt+="Moreover, KiCad StepUp tool set will let you to load the kicad footprint inside FreeCAD and align the 3D part with a visual real time feedback "
 
2455
        help_txt+="of the 3d model and footprint reciprocal position.<br>"
 
2456
        help_txt+="With this tool is possible to download a part from on-line libraries, align the model to kicad footprint "
 
2457
        help_txt+="and export the model to wrl, for immediate 3d-viewer alignment in pcbnew.<br>"
 
2458
        help_txt+="Now the two words are connected for a better collaboration; just <b>design in kicad EDA</b> and transfer "
 
2459
        help_txt+="the artwork to <b>MCAD (FreeCAD)</b> smoothly.<br>"
 
2460
        help_txt+="<b>The workflow is very simple</b> and maintains the usual way to work with kicad:<br>"
 
2461
        help_txt+="Add models to your library creating 3D models in FreeCAD, or getting models from online libs "
 
2462
        help_txt+="or from the parametric 3D lib expressly done to kicad <u>https://github.com/easyw/kicad-3d-mcad-models</u><br>"
 
2463
        help_txt+="Once you have your 3D MCAD model, you need to have a copy of that in STEP and VRML format. "
 
2464
        help_txt+="This is possible just exporting the model with FreeCAD then just put your model in the same folder in which "
 
2465
        help_txt+="normally you are used to put vrml models, and the script will assembly the MCAD board and models as in 3d-viewer of kicad."       
 
2466
        help_txt+="<br><b>NB<br>STEP model has to be fused in single object<br>(union of objects)</b>"
 
2467
        self.textEdit.setText(help_txt)
 
2468
        #say('onHelp')
 
2469
        #reply = QtGui.QMessageBox.question(None, "", "step file exists, overwrite?",QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No)
520
2470
    def onGetPosition(self):
521
 
        App.Console.PrintMessage("GetPosition!"+"\r\n")
 
2471
        FreeCAD.Console.PrintMessage("GetPosition!"+"\r\n")
522
2472
        position=get_position()
523
 
        ## self.label10.setText("X:"+str(get_position()[0])+"Pl:"+str(get_position()[3]))
524
 
        ## self.label11.setText("Y:"+str(get_position()[1])+"Pl:"+str(get_position()[4]))
525
 
        ## self.label12.setText("Z:"+str(get_position()[2])+"Pl:"+str(get_position()[5]))
526
2473
        self.label10.setText("X:"+str(position[0]))
527
2474
        self.label11.setText("Y:"+str(position[1]))
528
2475
        self.label12.setText("Z:"+str(position[2]))
529
2476
 
530
 
    ### TBFIXED!!! label lenght
531
2477
    def onCenterX(self):
532
 
        App.Console.PrintMessage("centering\r\n")
 
2478
        FreeCAD.Console.PrintMessage("centering\r\n")
533
2479
        routineC_XYZ('x')
534
2480
        position=get_position()
535
2481
        self.label10.setText("X:"+str(position[0]))
536
2482
        self.label11.setText("Y:"+str(position[1]))
537
2483
        self.label12.setText("Z:"+str(position[2]))
538
2484
    def onCenterY(self):
539
 
        App.Console.PrintMessage("centering\r\n")
 
2485
        FreeCAD.Console.PrintMessage("centering\r\n")
540
2486
        routineC_XYZ('y')
541
2487
        position=get_position()
542
2488
        self.label10.setText("X:"+str(position[0]))
543
2489
        self.label11.setText("Y:"+str(position[1]))
544
2490
        self.label12.setText("Z:"+str(position[2]))
545
2491
    def onCenterZ(self):
546
 
        App.Console.PrintMessage("centering\r\n")
 
2492
        FreeCAD.Console.PrintMessage("centering\r\n")
547
2493
        routineC_XYZ('z')
548
2494
        position=get_position()
549
2495
        self.label10.setText("X:"+str(position[0]))
550
2496
        self.label11.setText("Y:"+str(position[1]))
551
2497
        self.label12.setText("Z:"+str(position[2]))
552
2498
    def onPutOnX(self):
553
 
        App.Console.PrintMessage("putting on Plane X\r\n")
 
2499
        FreeCAD.Console.PrintMessage("putting on Plane X\r\n")
554
2500
        routineP_XYZ('x')
555
2501
        position=get_position()
556
2502
        self.label10.setText("X:"+str(position[0]))
557
2503
        self.label11.setText("Y:"+str(position[1]))
558
2504
        self.label12.setText("Z:"+str(position[2]))
559
2505
    def onPutOnY(self):
560
 
        App.Console.PrintMessage("putting on Plane Y\r\n")
 
2506
        FreeCAD.Console.PrintMessage("putting on Plane Y\r\n")
561
2507
        routineP_XYZ('y')
562
2508
        position=get_position()
563
2509
        self.label10.setText("X:"+str(position[0]))
564
2510
        self.label11.setText("Y:"+str(position[1]))
565
2511
        self.label12.setText("Z:"+str(position[2]))
566
2512
    def onPutOnZ(self):
567
 
        App.Console.PrintMessage("putting on Plane Z\r\n")
 
2513
        FreeCAD.Console.PrintMessage("putting on Plane Z\r\n")
568
2514
        routineP_XYZ('z')
569
2515
        position=get_position()
570
2516
        self.label10.setText("X:"+str(position[0]))
577
2523
    #     self.result = userOK
578
2524
    #     self.close()
579
2525
    def onScaleVRML(self):
580
 
        App.Console.PrintMessage("ScaleToVRML!"+"\r\n")
 
2526
        FreeCAD.Console.PrintMessage("ScaleToVRML!"+"\r\n")
 
2527
        self.setGeometry(25, 250, 500, 500)
581
2528
        result=routineScaleVRML()
582
2529
        position=get_position()
583
2530
        self.label10.setText("X:"+str(position[0]))
588
2535
            self.labelInfoMsg.setText(msg)
589
2536
 
590
2537
    def onResetPlacement(self):
591
 
        #App.Console.PrintMessage("reset Placement proprierties!"+"\r\n")
 
2538
        #FreeCAD.Console.PrintMessage("reset Placement proprierties!"+"\r\n")
592
2539
        routineResetPlacement()
593
2540
        position=get_position()
594
2541
        self.label10.setText("X:"+str(position[0]))
596
2543
        self.label12.setText("Z:"+str(position[2]))
597
2544
 
598
2545
    def onCollisions(self):
 
2546
        self.setGeometry(25, 250, 500, 500)
599
2547
        collisions=routineCollisions()
600
2548
        if collisions==0:
601
2549
            self.label17.setText("No")
609
2557
            self.label17.setText(" ")
610
2558
            self.label18.setText(" ")
611
2559
            self.label19.setText(" ")
612
 
 
613
 
 
614
 
    def onLoadFootprint(self):
615
 
        #name=QtGui.QFileDialog.getOpenFileName(this,tr("Open Image"), "/home/jana", tr("Image Files (*.png *.jpg *.bmp)"))[0]
616
 
        #global module_3D_dir
617
 
        global last_file_path, test_flag
 
2560
###
 
2561
    def onSelFolder(self):
618
2562
        default_value='/'
619
2563
        module_3D_dir=os.getenv('KISYS3DMOD', default_value)
620
 
        module_3D_dir=module_3D_dir+'/../'
 
2564
        module_3D_dir=module_3D_dir+'/'
621
2565
        ## getting 3D models path
622
2566
        # print 'KISYS3DMOD='
623
 
        App.Console.PrintMessage('KISYS3DMOD='+os.getenv('KISYS3DMOD', default_value)+' '+module_3D_dir+' \r\n')
 
2567
        #FreeCAD.Console.PrintMessage('KISYS3DMOD='+os.getenv('KISYS3DMOD', default_value)+' '+module_3D_dir+' \r\n')
624
2568
        if not os.path.isdir(module_3D_dir):
625
2569
            module_3D_dir="/"
626
 
        if last_file_path=='':
627
 
            last_file_path=module_3D_dir
628
 
        if test_flag==False:
629
 
            name=QtGui.QFileDialog.getOpenFileName(self, "Open File...", last_file_path,
630
 
                "kicad module files (*.kicad_mod)")[0]
631
 
        else:
632
 
            name="C:/temp/test.kicad_mod"
633
 
        if len(name) > 0:
634
 
            txtFile = open(name,"r")
635
 
            content = txtFile.readlines()
636
 
            content.append(" ")
637
 
            last_file_path=os.path.dirname(txtFile.name)
638
 
            txtFile.close()
639
 
 
640
 
            #content=name #temp maui
641
 
            data = [line.decode("utf-8", "ignore") for line in content]
642
 
            content = data
643
 
            #FreeCAD.Console.PrintMessage(content)
644
 
            #FreeCAD.Console.PrintMessage(data)
645
 
            routineDrawFootPrint(content,name)
646
 
            #txtFile.close()
647
 
 
 
2570
        # Save folder select
 
2571
        dialog = QtGui.QFileDialog.getExistingDirectory(self,"Open 3D prefix folder",
 
2572
                                                            module_3D_dir, QtGui.QFileDialog.ShowDirsOnly)
 
2573
        destiny_folder = str(dialog) 
 
2574
        destiny_folder=destiny_folder.replace('\\','/')
 
2575
        test1="C:/Cad/Progetti_K"
 
2576
        self.label_3d_prefix.setText(destiny_folder[:25])
 
2577
        FreeCAD.Console.PrintMessage(destiny_folder+ '\r\n')
 
2578
 
 
2579
    def onLoadBoard_idf_click(self):
 
2580
        self.setGeometry(25, 250, 500, 500)
 
2581
        sayw("kicad StepUp version "+str(___ver___))
 
2582
        ini_content=read_ini_file()
 
2583
        self.textEdit.setText(ini_content)
 
2584
        cfgParsRead(configFilePath)
 
2585
        onLoadBoard_idf()
 
2586
    ###    
 
2587
 
 
2588
###
 
2589
    def onLoadBoard_click(self):
 
2590
        self.setGeometry(25, 250, 500, 500)
 
2591
        sayw("kicad StepUp version "+str(___ver___))
 
2592
        ini_content=read_ini_file()
 
2593
        self.textEdit.setText(ini_content)
 
2594
        cfgParsRead(configFilePath)
 
2595
        onLoadBoard()
 
2596
    ###    
 
2597
###
 
2598
    def onLoadFootprint_click(self):
 
2599
        self.setGeometry(25, 250, 500, 500)
 
2600
        sayw("kicad StepUp version "+str(___ver___))
 
2601
        onLoadFootprint()
 
2602
###
648
2603
 
649
2604
    def mouseMoveEvent(self,event):
650
2605
        self.labelInfoMsg.setText('')
652
2607
            self.label30.setText("X: "+str(event.x()) + " Y: "+str(event.y()))
653
2608
 
654
2609
    def onCreateAxis(self):
655
 
        App.Console.PrintMessage("Create Axis!"+"\r\n")
656
 
        if App.ActiveDocument.getObject("axis")== None:
 
2610
        FreeCAD.Console.PrintMessage("Create Axis!"+"\r\n")
 
2611
        if FreeCAD.ActiveDocument.getObject("axis")== None:
657
2612
            create_axis()
658
2613
        ## self.label10.setText("X:"+str(get_position()[0])+"Pl:"+str(get_position()[3]))
659
2614
        ## self.label11.setText("Y:"+str(get_position()[1])+"Pl:"+str(get_position()[4]))
660
2615
        ## self.label12.setText("Z:"+str(get_position()[2])+"Pl:"+str(get_position()[5]))
661
2616
 
662
 
 
663
2617
# Class definitions
664
2618
 
665
2619
# Function definitions
 
2620
def onLoadFootprint(file_name=None):
 
2621
    #name=QtGui.QFileDialog.getOpenFileName(this,tr("Open Image"), "/home/jana", tr("Image Files (*.png *.jpg *.bmp)"))[0]
 
2622
    #global module_3D_dir
 
2623
    global last_fp_path, test_flag
 
2624
    global configParser, configFilePath, start_time
 
2625
    #self.setGeometry(25, 250, 500, 500)
 
2626
    clear_console()
 
2627
    default_value='/'
 
2628
    module_3D_dir=os.getenv('KISYS3DMOD', default_value)
 
2629
    module_3D_dir=module_3D_dir+'/../'
 
2630
    ## getting 3D models path
 
2631
    # print 'KISYS3DMOD='
 
2632
    say('KISYS3DMOD='+os.getenv('KISYS3DMOD', default_value)+'\n'+module_3D_dir+'\n')
 
2633
    if not os.path.isdir(module_3D_dir):
 
2634
        module_3D_dir="/"
 
2635
    if last_fp_path=='':
 
2636
        last_fp_path=module_3D_dir
 
2637
    if file_name!=None:
 
2638
        #export_board_2step=True #for cmd line force exporting to STEP
 
2639
        name=file_name
 
2640
    elif test_flag==False:
 
2641
    #if test_flag==False:
 
2642
        Filter=""
 
2643
        ##if _platform == "darwin":
 
2644
        ##    ##workaround for OSX not opening native fileopen
 
2645
        ##    name=QtGui.QFileDialog.getOpenFileName(self, 'Open file',
 
2646
        ##         last_file_path,"kicad module files (*.kicad_mod)",
 
2647
        ##         options=QtGui.QFileDialog.DontUseNativeDialog )[0]
 
2648
        ##else:
 
2649
        ##    name=QtGui.QFileDialog.getOpenFileName(self, "Open File...", last_file_path,
 
2650
        ##        "kicad module files (*.kicad_mod)")[0]
 
2651
        #path = FreeCAD.ConfigGet("AppHomePath")
 
2652
        #path = FreeCAD.ConfigGet("UserAppData")
 
2653
        #path=last_file_path
 
2654
        #try:
 
2655
        #    name, Filter = PySide.QtGui.QFileDialog.getOpenFileName(None, "Open File", last_file_path, "*.kicad_mod")#PySide
 
2656
        #except Exception:
 
2657
        #    FreeCAD.Console.PrintError("Error : " + str(name) + "\n")
 
2658
        name, Filter = PySide.QtGui.QFileDialog.getOpenFileName(None, "Open File...",
 
2659
             last_fp_path, "*.kicad_mod")
 
2660
    else:
 
2661
        name="C:/Cad/Progetti_K/ksu-test/test.kicad_mod"
 
2662
    if len(name) > 0:
 
2663
        txtFile = __builtin__.open(name,"r")
 
2664
        content = txtFile.readlines()
 
2665
        content.append(" ")
 
2666
        last_fp_path=os.path.dirname(txtFile.name)
 
2667
        txtFile.close()
 
2668
        configParser.set('last_footprint_path', 'last_fp_path', last_fp_path)
 
2669
        #configParser.set('last_fp_path', ';; last footprint file path used')
 
2670
        configParser.set('info', default_ksu_msg[0])
 
2671
        configParser.set('prefix3D', default_ksu_msg[1])
 
2672
        configParser.set('PcbColor', default_ksu_msg[2])
 
2673
        configParser.set('Blacklist', default_ksu_msg[3])
 
2674
        configParser.set('BoundingBox', default_ksu_msg[4])
 
2675
        configParser.set('Placement', default_ksu_msg[5])
 
2676
        configParser.set('Virtual', default_ksu_msg[6])
 
2677
        configParser.set('ExportFuse', default_ksu_msg[7])
 
2678
        configParser.set('minimum_drill_size', default_ksu_msg[8])
 
2679
        configParser.set('last_pcb_path', default_ksu_msg[9])
 
2680
        configParser.set('last_footprint_path', default_ksu_msg[10])
 
2681
        configParser.set('export', default_ksu_msg[11])
 
2682
        # save to the config file
 
2683
        with __builtin__.open(configFilePath, 'wb') as configfile:
 
2684
            configParser.write(configfile)
 
2685
        #configFilePath.close() already closed
 
2686
        data=''.join(content)
 
2687
        content=re.sub(r'[^\x00-\x7F]+',' ', data)
 
2688
        #FreeCAD.Console.PrintMessage(content)
 
2689
        #FreeCAD.Console.PrintMessage(data)
 
2690
        routineDrawFootPrint(content,name)
 
2691
        #txtFile.close()
 
2692
###
 
2693
def onLoadBoard_idf(file_name=None):
 
2694
    #name=QtGui.QFileDialog.getOpenFileName(this,tr("Open Image"), "/home/jana", tr("Image Files (*.png *.jpg *.bmp)"))[0]
 
2695
    #global module_3D_dir
 
2696
    global models3D_prefix, blacklisted_model_elements, col, colr, colg, colb
 
2697
    global bbox, volume_minimum, height_minimum, idf_to_origin, aux_orig
 
2698
    global base_orig, base_point, bbox_all, bbox_list, whitelisted_model_elements
 
2699
    global fusion, addVirtual, blacklisted_models, exportFusing, min_drill_size
 
2700
    global last_fp_path, last_pcb_path, plcmnt, xp, yp, exportFusing
 
2701
    global last_pcb_path, test_flag, configParser, configFilePath, start_time
 
2702
    global aux_orig, base_orig, base_point, idf_to_origin, off_x, off_y, export_board_2step
 
2703
    global real_board_pos_x, real_board_pos_y, board_base_point_x, board_base_point_y
 
2704
    #self.setGeometry(25, 250, 500, 500)
 
2705
    clear_console()
 
2706
    default_value='/'
 
2707
    module_3D_dir=os.getenv('KISYS3DMOD', default_value)
 
2708
    module_3D_dir=module_3D_dir+'/../'
 
2709
    ## getting 3D models path
 
2710
    # print 'KISYS3DMOD='
 
2711
    say('KISYS3DMOD='+os.getenv('KISYS3DMOD', default_value)+'\n'+module_3D_dir+'\n')
 
2712
    if not os.path.isdir(module_3D_dir):
 
2713
        module_3D_dir="/"
 
2714
    if not os.path.isdir(last_pcb_path):
 
2715
        last_pcb_path="./"
 
2716
    if file_name!=None:
 
2717
        #export_board_2step=True #for cmd line force exporting to STEP
 
2718
        name=file_name
 
2719
    elif test_flag==False:
 
2720
        Filter=""
 
2721
        ##if _platform == "darwin":
 
2722
        ##    ##workaround for OSX not opening native fileopen
 
2723
        ##    name=QtGui.QFileDialog.getOpenFileName(self, 'Open file',
 
2724
        ##         last_file_path,"kicad module files (*.kicad_mod)",
 
2725
        ##         options=QtGui.QFileDialog.DontUseNativeDialog )[0]
 
2726
        ##else:
 
2727
        ##    name=QtGui.QFileDialog.getOpenFileName(self, "Open File...", last_file_path,
 
2728
        ##        "kicad module files (*.kicad_mod)")[0]
 
2729
        #path = FreeCAD.ConfigGet("AppHomePath")
 
2730
        #path = FreeCAD.ConfigGet("UserAppData")
 
2731
        #path=last_file_path
 
2732
        #try:
 
2733
        #    name, Filter = PySide.QtGui.QFileDialog.getOpenFileName(None, "Open File", last_file_path, "*.kicad_mod")#PySide
 
2734
        #except Exception:
 
2735
        #    FreeCAD.Console.PrintError("Error : " + str(name) + "\n")
 
2736
        
 
2737
        #minimize main window
 
2738
        ## self.setWindowState(QtCore.Qt.WindowMinimized)
 
2739
        ## infoDialog('ciao')
 
2740
        ## reply = QtGui.QInputDialog.getText(None, "Hello","Enter your thoughts for the day:")
 
2741
        ## if reply[1]:
 
2742
        ##         # user clicked OK
 
2743
        ##         replyText = reply[0]
 
2744
        ## else:
 
2745
        ##         # user clicked Cancel
 
2746
        ##         replyText = reply[0] # which will be "" if they clicked Cancel
 
2747
        ## #restore main window
 
2748
        ## self.setWindowState(QtCore.Qt.WindowActive)
 
2749
        name, Filter = PySide.QtGui.QFileDialog.getOpenFileName(None, "Open IDF File...",
 
2750
             last_pcb_path, "*.emn")
 
2751
    else:
 
2752
        name="C:/Cad/Progetti_K/ksu-test/test.emn"
 
2753
        FreeCAD.Console.PrintMessage('opening '+name+'\n')
 
2754
    if len(name) > 0:
 
2755
        if os.path.isfile(name):
 
2756
            say('opening '+name+'\n')
 
2757
            path, fname = os.path.split(name)
 
2758
            fname=os.path.splitext(fname)[0]
 
2759
            #fpth = os.path.dirname(os.path.abspath(__file__))
 
2760
            fpth = os.path.dirname(os.path.abspath(name))
 
2761
            #filePath = os.path.split(os.path.realpath(__file__))[0]
 
2762
            say ('my file path '+fpth+'\n')
 
2763
            if fpth == "":
 
2764
                fpth = "."
 
2765
            last_pcb_path = fpth
 
2766
            #last_pcb_path=path
 
2767
            # update existing value
 
2768
            #say(default_ksu_msg)
 
2769
            configParser.set('last_pcb_path', 'last_pcb_path', path)
 
2770
            #configParser.set('last_pcb_path', ';; last pcb board path')
 
2771
            configParser.set('info', default_ksu_msg[0])
 
2772
            configParser.set('prefix3D', default_ksu_msg[1])
 
2773
            configParser.set('PcbColor', default_ksu_msg[2])
 
2774
            configParser.set('Blacklist', default_ksu_msg[3])
 
2775
            configParser.set('BoundingBox', default_ksu_msg[4])
 
2776
            configParser.set('Placement', default_ksu_msg[5])
 
2777
            configParser.set('Virtual', default_ksu_msg[6])
 
2778
            configParser.set('ExportFuse', default_ksu_msg[7])
 
2779
            configParser.set('minimum_drill_size', default_ksu_msg[8])
 
2780
            configParser.set('last_pcb_path', default_ksu_msg[9])
 
2781
            configParser.set('last_footprint_path', default_ksu_msg[10])
 
2782
            configParser.set('export', default_ksu_msg[11])
 
2783
            # save to the config file
 
2784
            with __builtin__.open(configFilePath, 'wb') as configfile:
 
2785
                configParser.write(configfile)
 
2786
            #configFilePath.close() already closed
 
2787
            doc=FreeCAD.newDocument(fname)
 
2788
            #last_file_path=os.path.dirname(fname)
 
2789
            start_time=current_milli_time()
 
2790
            routineDrawIDF(doc,name)
 
2791
        else:
 
2792
            say(name+' missing\r')
 
2793
            stop
 
2794
        ##Placing board at configured position
 
2795
        # pos objs x,-y
 
2796
        # pos board xm+(xM-xm)/2
 
2797
        # pos board -(ym+(yM-ym)/2)        
 
2798
        center_x, center_y, bb_x, bb_y = findPcbCenter("Pcb")
 
2799
        ## using PcbCenter
 
2800
        xMax=center_x+bb_x/2
 
2801
        xmin=center_x-bb_x/2
 
2802
        yMax=center_y+bb_y/2
 
2803
        ymin=center_y-bb_y/2
 
2804
        off_x=0; off_y=0  #offset of the board & modules
 
2805
        if (aux_orig==1):
 
2806
            xp=getAuxAxisOrigin()[0]; yp=-getAuxAxisOrigin()[1]  #offset of the board & modules
 
2807
            ##off_x=-xp+xmin+(xMax-xmin)/2; off_y=-yp-(ymin+(yMax-ymin)/2)  #offset of the board & modules
 
2808
            off_x=-xp+center_x;off_y=-yp+center_y
 
2809
        if (base_orig==1):
 
2810
            ##off_x=xmin+(xMax-xmin)/2; off_y=-(ymin+(yMax-ymin)/2)  #offset of the board & modules
 
2811
            off_x=center_x;off_y=center_y
 
2812
        if (base_point==1):
 
2813
            ##off_x=-xp+xmin+(xMax-xmin)/2; off_y=-yp-(ymin+(yMax-ymin)/2)  #offset of the board & modules
 
2814
            #off_x=-xp+center_x;off_y=-yp+center_y
 
2815
            off_x=-xp+center_x;off_y=-yp+center_y
 
2816
        ## test maui board_base_point_x=(xMax-xmin)/2-off_x
 
2817
        ## test maui board_base_point_y=-((yMax-ymin)/2)-off_y
 
2818
        #real_board_pos_x=xmin+(xMax-xmin)/2
 
2819
        #real_board_pos_y=-(ymin+(yMax-ymin)/2)
 
2820
        ## using PcbCenter
 
2821
        real_board_pos_x=center_x
 
2822
        real_board_pos_y=center_y
 
2823
        # doc = FreeCAD.ActiveDocument
 
2824
        if idf_to_origin == True:
 
2825
            board_base_point_x=-off_x
 
2826
            board_base_point_y=-off_y
 
2827
        else:
 
2828
        ## using PcbCenter
 
2829
            #board_base_point_x=xmin+(xMax-xmin)/2-off_x
 
2830
            #board_base_point_y=-(ymin+(yMax-ymin)/2)-off_y
 
2831
            board_base_point_x=center_x-off_x
 
2832
            board_base_point_y=center_y-off_y
 
2833
        # not to be used by .kicad_pcb
 
2834
        msg=""
 
2835
        if idf_to_origin==True:
 
2836
            msg+="IDF board has to be exported to Xref=0; Yref=0\r\n\r\n"
 
2837
            # msg+="IDF board has NOT to be exported to real placement\r\npcbnew version < 6091\r\n\r\n"
 
2838
        else:
 
2839
            msg+="IDF board has to be exported to real placement (Auto Adjust)\r\n\r\n"
 
2840
            # msg+="IDF board has NOT to be exported to Xref=0; Yref=0\r\npcbnew version >=6091\r\n\r\n"
 
2841
        if (show_messages==True):
 
2842
            QtGui.qApp.restoreOverrideCursor()
 
2843
            reply = QtGui.QMessageBox.information(None,"info", msg)
 
2844
        FreeCAD.ActiveDocument.getObject("Pcb").Placement = FreeCAD.Placement(FreeCAD.Vector(board_base_point_x,board_base_point_y,0),FreeCAD.Rotation(FreeCAD.Vector(0,0,1),0))
 
2845
        ## FreeCAD.ActiveDocument.getObject("Pcb").Placement = FreeCAD.Placement(FreeCAD.Vector(-off_x,-off_y,0),FreeCAD.Rotation(FreeCAD.Vector(0,0,1),0))
 
2846
        FreeCADGui.SendMsgToActiveView("ViewFit")
 
2847
        #ImportGui.insert(u"./c0603.step","demo_5D_vrml_from_step")
 
2848
        doc.addObject("App::DocumentObjectGroup", "Step_Models")
 
2849
        modules=[]
 
2850
        name_kicad_pcb=name[:-3]+"kicad_pcb"
 
2851
        pcbThickness,modules,board_elab=LoadKicadBoard(name_kicad_pcb)
 
2852
        #say(modules)
 
2853
        #say('Alive4 prob time\n')
 
2854
        #end_milli_time = current_milli_time()
 
2855
        #say(str(start_time)+'*'+str(end_milli_time)+'start-end\n')
 
2856
        say_time()
 
2857
        blacklisted_model_elements=Load_models(pcbThickness,modules)
 
2858
        if export_board_2step:
 
2859
            #say('aliveTrue')
 
2860
            Export2MCAD(blacklisted_model_elements)
 
2861
        else:
 
2862
            #say('aliveFalse')
 
2863
            Display_info(blacklisted_model_elements)
 
2864
        say_time()
 
2865
        #stop
 
2866
###
 
2867
def onLoadBoard(file_name=None):
 
2868
    #name=QtGui.QFileDialog.getOpenFileName(this,tr("Open Image"), "/home/jana", tr("Image Files (*.png *.jpg *.bmp)"))[0]
 
2869
    #global module_3D_dir
 
2870
    global test_flag, last_pcb_path, configParser, configFilePath, start_time
 
2871
    global aux_orig, base_orig, base_point, idf_to_origin, off_x, off_y, export_board_2step
 
2872
    global real_board_pos_x, real_board_pos_y, board_base_point_x, board_base_point_y
 
2873
    global models3D_prefix, blacklisted_model_elements, col, colr, colg, colb
 
2874
    global bbox, volume_minimum, height_minimum, idf_to_origin, aux_orig
 
2875
    global base_orig, base_point, bbox_all, bbox_list, whitelisted_model_elements
 
2876
    global fusion, addVirtual, blacklisted_models, exportFusing, min_drill_size
 
2877
    global last_fp_path, last_pcb_path, plcmnt, xp, yp, exportFusing
 
2878
    default_value='/'
 
2879
    clear_console()
 
2880
    #lastPcb_dir='C:/Cad/Progetti_K/ksu-test'
 
2881
    #say(lastPcb_dir+' last Pcb dir\r\n')
 
2882
    if not os.path.isdir(last_pcb_path):
 
2883
        last_pcb_path="./"
 
2884
    #say(last_pcb_path+'\n')
 
2885
    if file_name!=None:
 
2886
        #export_board_2step=True #for cmd line force exporting to STEP
 
2887
        name=file_name
 
2888
    elif test_flag==False:
 
2889
        Filter=""
 
2890
        #minimize main window
 
2891
        #self.setWindowState(QtCore.Qt.WindowMinimized)
 
2892
        #infoDialog('ciao')
 
2893
        #reply = QtGui.QInputDialog.getText(None, "Hello","Enter your thoughts for the day:")
 
2894
        #if reply[1]:
 
2895
        #        # user clicked OK
 
2896
        #        replyText = reply[0]
 
2897
        #else:
 
2898
        #        # user clicked Cancel
 
2899
        #        replyText = reply[0] # which will be "" if they clicked Cancel
 
2900
        #restore main window
 
2901
        #self.setWindowState(QtCore.Qt.WindowActive)
 
2902
        name, Filter = PySide.QtGui.QFileDialog.getOpenFileName(None, "Open kicad PCB File...",
 
2903
             last_pcb_path, "*.kicad_pcb")
 
2904
    else:
 
2905
        name="C:/Cad/Progetti_K/ksu-test/test.kicad_pcb"
 
2906
    if len(name) > 0:
 
2907
        if os.path.isfile(name):
 
2908
            say('opening '+name+'\n')
 
2909
            path, fname = os.path.split(name)
 
2910
            fname=os.path.splitext(fname)[0]
 
2911
            #fpth = os.path.dirname(os.path.abspath(__file__))
 
2912
            fpth = os.path.dirname(os.path.abspath(name))
 
2913
            #filePath = os.path.split(os.path.realpath(__file__))[0]
 
2914
            say ('my file path '+fpth+'\n')
 
2915
            if fpth == "":
 
2916
                fpth = "."
 
2917
            last_pcb_path = fpth
 
2918
            #last_pcb_path=path
 
2919
            # update existing value
 
2920
            #say(default_ksu_msg)
 
2921
            configParser.set('last_pcb_path', 'last_pcb_path', path)
 
2922
            #configParser.set('last_pcb_path', ';; last pcb board path')
 
2923
            configParser.set('info', default_ksu_msg[0])
 
2924
            configParser.set('prefix3D', default_ksu_msg[1])
 
2925
            configParser.set('PcbColor', default_ksu_msg[2])
 
2926
            configParser.set('Blacklist', default_ksu_msg[3])
 
2927
            configParser.set('BoundingBox', default_ksu_msg[4])
 
2928
            configParser.set('Placement', default_ksu_msg[5])
 
2929
            configParser.set('Virtual', default_ksu_msg[6])
 
2930
            configParser.set('ExportFuse', default_ksu_msg[7])
 
2931
            configParser.set('minimum_drill_size', default_ksu_msg[8])
 
2932
            configParser.set('last_pcb_path', default_ksu_msg[9])
 
2933
            configParser.set('last_footprint_path', default_ksu_msg[10])
 
2934
            configParser.set('export', default_ksu_msg[11])
 
2935
            # save to the config file
 
2936
            with __builtin__.open(configFilePath, 'wb') as configfile:
 
2937
                configParser.write(configfile)
 
2938
            #configFilePath.close() already closed
 
2939
            doc=FreeCAD.newDocument(fname)
 
2940
            modules=[]
 
2941
            start_time=current_milli_time()
 
2942
            pcbThickness,modules,board_elab=LoadKicadBoard(name)
 
2943
            routineDrawPCB(pcbThickness,board_elab)
 
2944
        else:
 
2945
            say(name+' missing\r')
 
2946
            stop
 
2947
        ##Placing board at configured position
 
2948
        # pos objs x,-y
 
2949
        # pos board xm+(xM-xm)/2
 
2950
        # pos board -(ym+(yM-ym)/2)        
 
2951
        center_x, center_y, bb_x, bb_y = findPcbCenter("Pcb")
 
2952
        ## using PcbCenter
 
2953
        xMax=center_x+bb_x/2
 
2954
        xmin=center_x-bb_x/2
 
2955
        yMax=center_y+bb_y/2
 
2956
        ymin=center_y-bb_y/2
 
2957
        off_x=0; off_y=0  #offset of the board & modules
 
2958
        if (aux_orig==1):
 
2959
            xp=getAuxAxisOrigin()[0]; yp=-getAuxAxisOrigin()[1]  #offset of the board & modules
 
2960
            ##off_x=-xp+xmin+(xMax-xmin)/2; off_y=-yp-(ymin+(yMax-ymin)/2)  #offset of the board & modules
 
2961
            off_x=-xp+center_x;off_y=-yp+center_y
 
2962
        if (base_orig==1):
 
2963
            ##off_x=xmin+(xMax-xmin)/2; off_y=-(ymin+(yMax-ymin)/2)  #offset of the board & modules
 
2964
            off_x=center_x;off_y=center_y
 
2965
        if (base_point==1):
 
2966
            ##off_x=-xp+xmin+(xMax-xmin)/2; off_y=-yp-(ymin+(yMax-ymin)/2)  #offset of the board & modules
 
2967
            #off_x=-xp+center_x;off_y=-yp+center_y
 
2968
            off_x=-xp+center_x;off_y=-yp+center_y
 
2969
        ## test maui board_base_point_x=(xMax-xmin)/2-off_x
 
2970
        ## test maui board_base_point_y=-((yMax-ymin)/2)-off_y
 
2971
        #real_board_pos_x=xmin+(xMax-xmin)/2
 
2972
        #real_board_pos_y=-(ymin+(yMax-ymin)/2)
 
2973
        ## using PcbCenter
 
2974
        real_board_pos_x=center_x
 
2975
        real_board_pos_y=center_y
 
2976
        # doc = FreeCAD.ActiveDocument
 
2977
        if idf_to_origin == True:
 
2978
            board_base_point_x=-off_x
 
2979
            board_base_point_y=-off_y
 
2980
        else:
 
2981
        ## using PcbCenter
 
2982
            #board_base_point_x=xmin+(xMax-xmin)/2-off_x
 
2983
            #board_base_point_y=-(ymin+(yMax-ymin)/2)-off_y
 
2984
            board_base_point_x=center_x-off_x
 
2985
            board_base_point_y=center_y-off_y
 
2986
        FreeCAD.ActiveDocument.getObject("Pcb").Placement = FreeCAD.Placement(FreeCAD.Vector(board_base_point_x,board_base_point_y,0),FreeCAD.Rotation(FreeCAD.Vector(0,0,1),0))
 
2987
        ## FreeCAD.ActiveDocument.getObject("Pcb").Placement = FreeCAD.Placement(FreeCAD.Vector(-off_x,-off_y,0),FreeCAD.Rotation(FreeCAD.Vector(0,0,1),0))
 
2988
        FreeCADGui.SendMsgToActiveView("ViewFit")
 
2989
        #ImportGui.insert(u"./c0603.step","demo_5D_vrml_from_step")
 
2990
        doc.addObject("App::DocumentObjectGroup", "Step_Models")
 
2991
        say_time()
 
2992
        Load_models(pcbThickness,modules)
 
2993
        if export_board_2step:
 
2994
            #say('aliveTrue')
 
2995
            Export2MCAD(blacklisted_model_elements)
 
2996
        else:
 
2997
            #say('aliveFalse')
 
2998
            Display_info(blacklisted_model_elements)
 
2999
        say_time()
 
3000
        #stop
 
3001
###
 
3002
 
666
3003
def routineR_XYZ(axe,alpha):
667
3004
    global resetP
668
 
    print 'routine Rotate XYZ'
669
 
    Gui.activateWorkbench("PartWorkbench")
670
 
    #Gui.SendMsgToActiveView("ViewFit")
671
 
    ##Gui.activeDocument().activeView().viewTop()
 
3005
    say('routine Rotate XYZ\n')
 
3006
    FreeCADGui.activateWorkbench("PartWorkbench")
 
3007
    #FreeCADGui.SendMsgToActiveView("ViewFit")
 
3008
    ##FreeCADGui.activeDocument().activeView().viewTop()
672
3009
    doc = FreeCAD.ActiveDocument
673
 
    App.Console.PrintMessage("hereXYZ !"+"\r\n")
 
3010
    #FreeCAD.Console.PrintMessage("hereXYZ !"+"\r\n")
674
3011
    selEx = FreeCADGui.Selection.getSelectionEx()
675
3012
    objs = [selobj.Object for selobj in selEx]
676
3013
    if len(objs) == 1:
687
3024
        oripl_X = float(c[0])
688
3025
        oripl_Y = float(c[1])
689
3026
        oripl_Z = float(c[2])
690
 
        #App.Console.PrintMessage("bbx: "+str(boundBoxLX)+" bby: "+str(boundBoxLY)+"bbz: "+str(boundBoxLZ)+"\r\n")
691
 
        #App.Console.PrintMessage("x: "+str(oripl_X)+" y: "+str(oripl_Y)+"z: "+str(oripl_Z)+"\r\n")
 
3027
        #say("bbx: "+str(boundBoxLX)+" bby: "+str(boundBoxLY)+"bbz: "+str(boundBoxLZ)+"\r\n")
 
3028
        #say("x: "+str(oripl_X)+" y: "+str(oripl_Y)+"z: "+str(oripl_Z)+"\r\n")
692
3029
        #shape.rotate((oripl_X,oripl_Y,oripl_Z),(1,0,0),90)
693
3030
        angle=alpha
694
3031
        if axe=='x':
702
3039
            shape.rotate((oripl_X+boundBoxLX/2,oripl_Y+boundBoxLY/2,oripl_Z+boundBoxLZ/2),(0,0,1),int(angle))
703
3040
        #Part.show(shape)
704
3041
        objs[0].Placement=shape.Placement
705
 
        Gui.Selection.addSelection(objs[0])
706
 
        App.activeDocument().recompute()
 
3042
        FreeCADGui.Selection.addSelection(objs[0])
 
3043
        FreeCAD.activeDocument().recompute()
707
3044
        if resetP==True:
708
3045
            routineResetPlacement()
709
 
        App.Console.PrintMessage("end of rotineZ!"+"\r\n")
 
3046
        #say("end of rotineZ!"+"\r\n")
710
3047
    else:
711
 
        App.Console.PrintMessage("Select ONE single part object !\r\n"+"\r\n")
 
3048
        say("Select ONE single part object !\r\n"+"\r\n")
712
3049
        #QtGui.QMessageBox.information(None,"Info ...","Select ONE single part object !\r\n"+"\r\n")
713
3050
###  end RotateXYZ
714
3051
 
715
3052
def routineT_XYZ(axe,v):
716
3053
    global resetP
717
 
    print 'routine Translate XYZ'
718
 
    Gui.activateWorkbench("PartWorkbench")
719
 
    #Gui.SendMsgToActiveView("ViewFit")
720
 
    ##Gui.activeDocument().activeView().viewTop()
 
3054
    say('routine Translate XYZ\n')
 
3055
    FreeCADGui.activateWorkbench("PartWorkbench")
 
3056
    #FreeCADGui.SendMsgToActiveView("ViewFit")
 
3057
    ##FreeCADGui.activeDocument().activeView().viewTop()
721
3058
    doc = FreeCAD.ActiveDocument
722
3059
    selEx = FreeCADGui.Selection.getSelectionEx()
723
3060
    objs = [selobj.Object for selobj in selEx]
726
3063
        shape=s.copy()
727
3064
        shape.Placement=s.Placement;
728
3065
        #shape.rotate((oripl_X,oripl_Y,oripl_Z),(1,0,0),90)
729
 
        App.Console.PrintMessage("axe "+axe+", value "+v+"\r\n")
 
3066
        #say("axe "+axe+", value "+v+"\r\n")
730
3067
        if axe=='x':
731
3068
            shape.translate((float(v),0,0))
732
3069
        if axe=='y':
735
3072
            shape.translate((0,0,float(v)))
736
3073
        #Part.show(shape)
737
3074
        objs[0].Placement=shape.Placement
738
 
        Gui.Selection.addSelection(objs[0])
739
 
        App.activeDocument().recompute()
 
3075
        FreeCADGui.Selection.addSelection(objs[0])
 
3076
        FreeCAD.activeDocument().recompute()
740
3077
        if resetP==True:
741
3078
            routineResetPlacement()
742
 
        App.Console.PrintMessage("end of rotineT!"+"\r\n")
 
3079
        #say("end of rotineT!"+"\r\n")
743
3080
    else:
744
 
        App.Console.PrintMessage("Select ONE single part object !\r\n"+"\r\n")
 
3081
        say("Select ONE single part object !\r\n"+"\r\n")
745
3082
        #QtGui.QMessageBox.information(None,"Info ...","Select ONE single part object !\r\n"+"\r\n")
746
3083
###  end TranslateXYZ
747
3084
 
748
3085
def routineResetPlacement():
749
3086
    objs=[]
750
 
    Gui.activateWorkbench("PartWorkbench")
751
 
    #Gui.SendMsgToActiveView("ViewFit")
752
 
    ##Gui.activeDocument().activeView().viewTop()
 
3087
    FreeCADGui.activateWorkbench("PartWorkbench")
 
3088
    #FreeCADGui.SendMsgToActiveView("ViewFit")
 
3089
    ##FreeCADGui.activeDocument().activeView().viewTop()
753
3090
    doc = FreeCAD.ActiveDocument
754
3091
    selEx = FreeCADGui.Selection.getSelectionEx()
755
3092
    objs = [selobj.Object for selobj in selEx]
756
3093
    #print 'here'
757
3094
    if len(objs) == 1:
758
 
        print 'routine reset Placement properties'
 
3095
        say('routine reset Placement properties\n')
759
3096
 
760
3097
        s=objs[0].Shape
761
3098
        r=[]
766
3103
            r.append((i,c))
767
3104
 
768
3105
        w=t.replaceShape(r)
769
 
        w.Placement=App.Placement()
 
3106
        w.Placement=FreeCAD.Placement()
770
3107
        Part.show(w)
771
 
        FreeCAD.Console.PrintMessage(w)
 
3108
        #say(w)
772
3109
 
773
 
        Gui.ActiveDocument.ActiveObject.ShapeColor=Gui.ActiveDocument.getObject(objs[0].Name).ShapeColor
774
 
        Gui.ActiveDocument.ActiveObject.LineColor=Gui.ActiveDocument.getObject(objs[0].Name).LineColor
775
 
        Gui.ActiveDocument.ActiveObject.PointColor=Gui.ActiveDocument.getObject(objs[0].Name).PointColor
776
 
        Gui.ActiveDocument.ActiveObject.DiffuseColor=Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor
777
 
        Gui.ActiveDocument.ActiveObject.Transparency=Gui.ActiveDocument.getObject(objs[0].Name).Transparency
 
3110
        FreeCADGui.ActiveDocument.ActiveObject.ShapeColor=FreeCADGui.ActiveDocument.getObject(objs[0].Name).ShapeColor
 
3111
        FreeCADGui.ActiveDocument.ActiveObject.LineColor=FreeCADGui.ActiveDocument.getObject(objs[0].Name).LineColor
 
3112
        FreeCADGui.ActiveDocument.ActiveObject.PointColor=FreeCADGui.ActiveDocument.getObject(objs[0].Name).PointColor
 
3113
        FreeCADGui.ActiveDocument.ActiveObject.DiffuseColor=FreeCADGui.ActiveDocument.getObject(objs[0].Name).DiffuseColor
 
3114
        FreeCADGui.ActiveDocument.ActiveObject.Transparency=FreeCADGui.ActiveDocument.getObject(objs[0].Name).Transparency
778
3115
 
779
3116
        new_label=objs[0].Label
780
 
        App.ActiveDocument.removeObject(objs[0].Name)
781
 
        App.ActiveDocument.recompute()
782
 
        App.ActiveDocument.ActiveObject.Label=new_label
783
 
        rObj=App.ActiveDocument.ActiveObject
 
3117
        FreeCAD.ActiveDocument.removeObject(objs[0].Name)
 
3118
        FreeCAD.ActiveDocument.recompute()
 
3119
        FreeCAD.ActiveDocument.ActiveObject.Label=new_label
 
3120
        rObj=FreeCAD.ActiveDocument.ActiveObject
784
3121
        del objs
785
 
        Gui.Selection.addSelection(rObj)
786
 
        #App.activeDocument().recompute()
787
 
        App.Console.PrintMessage("end of rotineRP!"+"\r\n")
788
 
 
 
3122
        FreeCADGui.Selection.addSelection(rObj)
 
3123
        #FreeCAD.activeDocument().recompute()
 
3124
        #say("end of rotineRP!"+"\r\n")
789
3125
    else:
790
 
        App.Console.PrintMessage("Select ONE single part object !\r\n"+"\r\n")
 
3126
        say("Select ONE single part object !\r\n"+"\r\n")
791
3127
        #QtGui.QMessageBox.information(None,"Info ...","Select ONE single part object !\r\n"+"\r\n")
792
3128
        del objs
793
 
 
794
3129
### end reset prop
795
3130
 
796
3131
def routineScaleVRML():
 
3132
    global exportV, exportS
 
3133
    say('routine Scale to VRML 1/2.54\n')
 
3134
    doc = FreeCAD.ActiveDocument
 
3135
    selEx = FreeCADGui.Selection.getSelectionEx()
 
3136
    objs = [selobj.Object for selobj in selEx]
 
3137
    if len(objs) == 1:
 
3138
        say('exporting\n')
 
3139
        fullFilePathName=doc.FileName
 
3140
        if fullFilePathName=="":
 
3141
            home = expanduser("~")
 
3142
            fullFilePathName=home+os.sep+doc.Label+'.FCStd'
 
3143
            say('path not found, saving to '+fullFilePathName+'\n')
 
3144
            #say(fullFilePathName)
 
3145
        else:
 
3146
            say(fullFilePathName+'\n')
 
3147
        go_export(fullFilePathName)
 
3148
        path, fname = os.path.split(fullFilePathName)
 
3149
        #fname=os.path.splitext(fname)[0]
 
3150
        fname=objs[0].Label
 
3151
        if exportV or exportS:
 
3152
            msg="""<b>export STEP & scaled VRML file for kicad!</b>
 
3153
            <font color='white'>****************************************************************************</font><br>
 
3154
            <i>exporting folder: </i><br>- <b>"""+path
 
3155
            msg+="""</b><br><i>exporting filename: </i><br>"""
 
3156
            if exportV:
 
3157
                msg+="""- <b>"""+fname+""".wrl<br>"""
 
3158
            if exportS:
 
3159
                msg+="""</b>- <b>"""+fname+""".step</b>"""
 
3160
            #msg="export scaled VRML file for kicad!\r\n"
 
3161
            #msg=msg+"****************************************************************************"
 
3162
            msg=msg+"<br><br><i>3D settings in kicad Module Editor:</i><br>"
 
3163
            msg=msg+"<b>- scale 1 1 1\r\n- offset 0 0 0<br>- rotation 0 0 "+str(rot_wrl)+"</b>"
 
3164
            ##self.setWindowState(QtCore.Qt.WindowMinimized)
 
3165
            QtGui.qApp.restoreOverrideCursor()
 
3166
            QtGui.QMessageBox.information(None,"Info ...",msg)
 
3167
            ##self.setWindowState(QtCore.Qt.WindowActive)
 
3168
            say('done\n')
 
3169
    else:
 
3170
        say("Select ONE single part object !\r\n"+"\r\n")
 
3171
        #QtGui.QMessageBox.information(None,"Info ...","Select ONE single part object !\r\n"+"\r\n")
 
3172
    return 0    
 
3173
###
 
3174
 
 
3175
###
 
3176
def routineScaleVRML_1():
797
3177
    global rot_wrl
798
 
    print 'routine Scale to VRML 1/2.54'
799
 
    Gui.activateWorkbench("PartWorkbench")
800
 
    #Gui.SendMsgToActiveView("ViewFit")
801
 
    ##Gui.activeDocument().activeView().viewTop()
 
3178
    say('routine Scale to VRML 1/2.54\n')
 
3179
    FreeCADGui.activateWorkbench("PartWorkbench")
 
3180
    #FreeCADGui.SendMsgToActiveView("ViewFit")
 
3181
    ##FreeCADGui.activeDocument().activeView().viewTop()
802
3182
    doc = FreeCAD.ActiveDocument
803
3183
    selEx = FreeCADGui.Selection.getSelectionEx()
804
3184
    objs = [selobj.Object for selobj in selEx]
805
3185
    if len(objs) == 1:
806
 
        objS=App.ActiveDocument.getObject(objs[0].Name).Shape
807
 
        #Gui.ActiveDocument.getObject(objs[0].Name).BoundingBox = True
808
 
        final_Label=App.ActiveDocument.getObject(objs[0].Name).Label
809
 
        myobjG=Gui.ActiveDocument.getObject(objs[0].Name)
810
 
        myobjA=App.ActiveDocument.getObject(objs[0].Name)
811
 
        mynewdoc=App.newDocument()
812
 
        App.ActiveDocument.addObject('Part::Feature',objs[0].Name).Shape=objS
 
3186
        objS=FreeCAD.ActiveDocument.getObject(objs[0].Name).Shape
 
3187
        #FreeCADGui.ActiveDocument.getObject(objs[0].Name).BoundingBox = True
 
3188
        final_Label=FreeCAD.ActiveDocument.getObject(objs[0].Name).Label
 
3189
        myobjG=FreeCADGui.ActiveDocument.getObject(objs[0].Name)
 
3190
        myobjA=FreeCAD.ActiveDocument.getObject(objs[0].Name)
 
3191
        mynewdoc=FreeCAD.newDocument()
 
3192
        FreeCAD.ActiveDocument.addObject('Part::Feature',objs[0].Name).Shape=objS
813
3193
 
814
3194
        #print 'here'
815
 
        myobjA1=App.ActiveDocument.ActiveObject
 
3195
        myobjA1=FreeCAD.ActiveDocument.ActiveObject
816
3196
        #myobjA1.Label=final_Label
817
 
        myobjG1=Gui.ActiveDocument.ActiveObject
 
3197
        myobjG1=FreeCADGui.ActiveDocument.ActiveObject
818
3198
        myobjG1.ShapeColor=myobjG.ShapeColor
819
3199
        myobjG1.LineColor=myobjG.LineColor
820
3200
        myobjG1.PointColor=myobjG.PointColor
821
3201
        myobjG1.DiffuseColor=myobjG.DiffuseColor
822
3202
        myobjG1.Transparency=myobjG.Transparency
823
 
        App.ActiveDocument.recompute()
 
3203
        FreeCAD.ActiveDocument.recompute()
824
3204
 
825
 
        App.ActiveDocument.ActiveObject.Label=final_Label+'_vrml'
 
3205
        FreeCAD.ActiveDocument.ActiveObject.Label=final_Label+'_vrml'
826
3206
        print final_Label+'_vrml\r\n'
827
 
        #Gui.ActiveDocument.getObject(objs[0].Name).Visibility=False
 
3207
        #FreeCADGui.ActiveDocument.getObject(objs[0].Name).Visibility=False
828
3208
 
829
 
        App.ActiveDocument.recompute()
830
 
        vrml_obj = Draft.scale(App.ActiveDocument.ActiveObject,delta=App.Vector(0.3937,0.3937,0.3937),center=App.Vector(0,0,0),legacy=True)
831
 
        App.ActiveDocument.recompute()
832
 
        #App.ActiveDocument.ActiveObject.ViewObject.DisplayMode = 'Shaded'
833
 
        Gui.ActiveDocument.ActiveObject.BoundingBox = False
834
 
        #App.ActiveDocument.ActiveObject.ViewObject.DisplayMode = 'Shaded'
 
3209
        FreeCAD.ActiveDocument.recompute()
 
3210
        vrml_obj = Draft.scale(FreeCAD.ActiveDocument.ActiveObject,delta=FreeCAD.Vector(0.3937,0.3937,0.3937),center=FreeCAD.Vector(0,0,0),legacy=True)
 
3211
        FreeCAD.ActiveDocument.recompute()
 
3212
        #FreeCAD.ActiveDocument.ActiveObject.ViewObject.DisplayMode = 'Shaded'
 
3213
        FreeCADGui.ActiveDocument.ActiveObject.BoundingBox = False
 
3214
        #FreeCAD.ActiveDocument.ActiveObject.ViewObject.DisplayMode = 'Shaded'
835
3215
        #vrml_obj.ViewObject.DisplayMode = u'Shaded'
836
3216
        shade_val='Shaded'
837
 
        #App.ActiveDocument.ActiveObject.ViewObject.DisplayMode = 'Shaded'
838
 
        App.ActiveDocument.ActiveObject.ViewObject.DisplayMode = 1 #Shaded
839
 
        Gui.SendMsgToActiveView("ViewFit")
 
3217
        #FreeCAD.ActiveDocument.ActiveObject.ViewObject.DisplayMode = 'Shaded'
 
3218
        FreeCAD.ActiveDocument.ActiveObject.ViewObject.DisplayMode = 1 #Shaded
 
3219
        FreeCADGui.SendMsgToActiveView("ViewFit")
840
3220
        msg="""<b>export scaled VRML file for kicad!</b>
841
3221
            <font color='white'>****************************************************************************</font><br>
842
3222
            <i>3D settings in kicad Module Editor:</i><br>
846
3226
        #msg=msg+"****************************************************************************"
847
3227
        #msg=msg+"\r\n3D settings in kicad Module Editor:\r\n"
848
3228
        #msg=msg+"- scale 1 1 1\r\n- offset 0 0 0\r\n- rotation 0 0 "+str(rot_wrl)
 
3229
        self.setWindowState(QtCore.Qt.WindowMinimized)
 
3230
        QtGui.qApp.restoreOverrideCursor()
849
3231
        QtGui.QMessageBox.information(None,"Info ...",msg)
850
 
 
 
3232
        self.setWindowState(QtCore.Qt.WindowActive)
851
3233
    else:
852
 
        App.Console.PrintMessage("Select ONE single part object !\r\n"+"\r\n")
 
3234
        say("Select ONE single part object !\r\n"+"\r\n")
853
3235
        #QtGui.QMessageBox.information(None,"Info ...","Select ONE single part object !\r\n"+"\r\n")
854
3236
    return 0
855
3237
 
856
 
###  end ScaleVRML
857
 
def MsgBoxRich(self):
858
 
        qmsgBox = QtGui.QMessageBox()
859
 
        qmsgBox.setStyleSheet('QMessageBox {background-color: #2b5b84; color: white;}\nQPushButton{color: white; font-size: 16px; background-color: #1d1d1d; border-radius: 10px; padding: 10px; text-align: center;}\n QPushButton:hover{color: #2b5b84;}')
860
 
        QtGui.QMessageBox.about(qmsgBox, 'SuperPyQtCalculator',
861
 
            """<font color='white'><p><b>SuperPyQtCalculator</b></p>
862
 
            <p><b>Version:</b> {0}</p>
863
 
            <p><b>Author: </b> {1}</p>
864
 
            <p><b>Web:</b></font><a href='www.linuxmusica.com'><font color='black'>Linux Music 3.0</font></a></p>
865
 
            <font color='white'><p><b>Email: </b>lopeztobal@gmail.com</p>
866
 
            <p><b>Copyright:</b>  &copy; 2014 Qtrac Ltd.
867
 
            All rights reserved.
868
 
            <p>This application can be used to calculate
869
 
            simple math science operations.</p>
870
 
            <p><b>You are using:</b></p>
871
 
            <p>Python {2} - Qt {3} - PyQt {4} on {5}</p></font>""")
872
 
###
 
3238
###  end ScaleVRML_1
873
3239
def routineC_XYZ(axe):
874
3240
    global resetP
875
 
    print 'routine center position'
 
3241
    say('routine center position\n')
876
3242
    #if self.checkBox_1.isChecked():
877
3243
    #    routineResetPlacement()
878
 
    Gui.activateWorkbench("PartWorkbench")
879
 
    #Gui.SendMsgToActiveView("ViewFit")
880
 
    ##Gui.activeDocument().activeView().viewTop()
 
3244
    FreeCADGui.activateWorkbench("PartWorkbench")
 
3245
    #FreeCADGui.SendMsgToActiveView("ViewFit")
 
3246
    ##FreeCADGui.activeDocument().activeView().viewTop()
881
3247
    doc = FreeCAD.ActiveDocument
882
 
    App.Console.PrintMessage("Centering on Axe XYZ !"+"\r\n")
 
3248
    say("Centering on Axe XYZ !"+"\r\n")
883
3249
    selEx = FreeCADGui.Selection.getSelectionEx()
884
3250
    objs = [selobj.Object for selobj in selEx]
885
3251
    if len(objs) == 1:
886
3252
        s = objs[0].Shape
887
3253
        shape=s.copy()
888
3254
        #shape.Placement=s.Placement;
889
 
        shape.Placement= App.Placement(App.Vector(0,0,0),App.Rotation(App.Vector(0,0,1),0))
 
3255
        shape.Placement= FreeCAD.Placement(FreeCAD.Vector(0,0,0),FreeCAD.Rotation(FreeCAD.Vector(0,0,1),0))
890
3256
        boundBox_ = s.BoundBox
891
3257
        boundBoxLX = boundBox_.XLength
892
3258
        boundBoxLY = boundBox_.YLength
893
3259
        boundBoxLZ = boundBox_.ZLength
894
 
        App.Console.PrintMessage("bbox: "+str(boundBox_)+"\r\n")
 
3260
        say("bbox: "+str(boundBox_)+"\r\n")
895
3261
 
896
3262
        a = str(boundBox_)
897
3263
        a,b = a.split('(')
899
3265
        oripl_X = float(c[0])
900
3266
        oripl_Y = float(c[1])
901
3267
        oripl_Z = float(c[2])
902
 
        App.Console.PrintMessage("bbx: "+str(boundBoxLX)+" bby: "+str(boundBoxLY)+"bbz: "+str(boundBoxLZ)+"\r\n")
903
 
        App.Console.PrintMessage("x: "+str(oripl_X)+" y: "+str(oripl_Y)+"z: "+str(oripl_Z)+"\r\n")
 
3268
        #say("bbx: "+str(boundBoxLX)+" bby: "+str(boundBoxLY)+"bbz: "+str(boundBoxLZ)+"\r\n")
 
3269
        #say("x: "+str(oripl_X)+" y: "+str(oripl_Y)+"z: "+str(oripl_Z)+"\r\n")
904
3270
 
905
3271
        p=s.Placement
906
 
        App.Console.PrintMessage("PlacementBase  : "+str(p)+"\r\n")
907
 
        #App.Console.PrintMessage(str(p.Base[0])+' '+str(p.Base[1])+' '+str(p.Base[2])+"\r\n")
 
3272
        #say("PlacementBase  : "+str(p)+"\r\n")
 
3273
        #say(str(p.Base[0])+' '+str(p.Base[1])+' '+str(p.Base[2])+"\r\n")
908
3274
        if axe=='x':
909
3275
            #shape.translate((0,0,0))
910
3276
            diffPl=-oripl_X-boundBoxLX/2
920
3286
            shape.translate((p.Base[0],p.Base[1],diffPl))
921
3287
            #shape.translate(Base.Vector(0,0,diffPl))
922
3288
        ### to zero posX -bboxX/2
923
 
        App.Console.PrintMessage("x: "+str(oripl_X)+" y: "+str(oripl_Y)+"z: "+str(oripl_Z)+"\r\n")
924
 
        App.Console.PrintMessage("axe "+axe+" placement"+str(diffPl)+"\r\n")
 
3289
        #say("x: "+str(oripl_X)+" y: "+str(oripl_Y)+"z: "+str(oripl_Z)+"\r\n")
 
3290
        #say("axe "+axe+" placement"+str(diffPl)+"\r\n")
925
3291
        #Part.show(shape)
926
3292
        objs[0].Placement=shape.Placement
927
 
        Gui.Selection.addSelection(objs[0])
928
 
        App.activeDocument().recompute()
929
 
        App.Console.PrintMessage("x: "+str(oripl_X)+"\r\ny: "+str(oripl_Y)+"\r\nz: "+str(oripl_Z)+"\r\n")
 
3293
        FreeCADGui.Selection.addSelection(objs[0])
 
3294
        FreeCAD.activeDocument().recompute()
 
3295
        #say("x: "+str(oripl_X)+"\r\ny: "+str(oripl_Y)+"\r\nz: "+str(oripl_Z)+"\r\n")
930
3296
        if resetP==True:
931
3297
            routineResetPlacement()
932
 
            #App.Console.PrintMessage("pos reset done\r\n")
933
 
        #App.Console.PrintMessage("done\r\n")
934
 
 
 
3298
            #say("pos reset done\r\n")
 
3299
        #say("done\r\n")
935
3300
    else:
936
 
        App.Console.PrintMessage("Select an object !"+"\r\n")
 
3301
        say("Select an object !"+"\r\n")
937
3302
        #QtGui.QMessageBox.information(None,"Info ...","Select an object !"+"\r\n")
938
3303
###  end routineC_XYZ
939
3304
 
940
3305
def routineP_XYZ(axe):
941
3306
    global resetP
942
 
    print 'routine put on axe'
 
3307
    say('routine put on axe\n')
943
3308
    #routineResetPlacement()
944
 
    Gui.activateWorkbench("PartWorkbench")
945
 
    #Gui.SendMsgToActiveView("ViewFit")
946
 
    ##Gui.activeDocument().activeView().viewTop()
 
3309
    FreeCADGui.activateWorkbench("PartWorkbench")
 
3310
    #FreeCADGui.SendMsgToActiveView("ViewFit")
 
3311
    ##FreeCADGui.activeDocument().activeView().viewTop()
947
3312
    doc = FreeCAD.ActiveDocument
948
 
    App.Console.PrintMessage("Put on Axe XYZ !"+"\r\n")
 
3313
    say("Put on Axe XYZ !"+"\r\n")
949
3314
    selEx = FreeCADGui.Selection.getSelectionEx()
950
3315
    objs = [selobj.Object for selobj in selEx]
951
3316
    if len(objs) == 1:
952
3317
        s = objs[0].Shape
953
3318
        shape=s.copy()
954
3319
        #shape.Placement=s.Placement;
955
 
        shape.Placement= App.Placement(App.Vector(0,0,0),App.Rotation(App.Vector(0,0,1),0))
 
3320
        shape.Placement= FreeCAD.Placement(FreeCAD.Vector(0,0,0),FreeCAD.Rotation(FreeCAD.Vector(0,0,1),0))
956
3321
        boundBox_ = s.BoundBox
957
3322
        boundBoxLX = boundBox_.XLength
958
3323
        boundBoxLY = boundBox_.YLength
964
3329
        oripl_Y = float(c[1])
965
3330
        oripl_Z = float(c[2])
966
3331
        p=s.Placement
967
 
        App.Console.PrintMessage("PlacementBase  : "+str(p)+"\r\n")
968
 
        #App.Console.PrintMessage(str(p.Base[0])+' '+str(p.Base[1])+' '+str(p.Base[2])+"\r\n")
 
3332
        say("PlacementBase  : "+str(p)+"\r\n")
 
3333
        #say(str(p.Base[0])+' '+str(p.Base[1])+' '+str(p.Base[2])+"\r\n")
969
3334
        if axe=='x':
970
3335
            #shape.translate((0,0,0))
971
3336
            diffPl=p.Base[0]-oripl_X
981
3346
            shape.translate((p.Base[0],p.Base[1],diffPl))
982
3347
            #shape.translate(Base.Vector(0,0,diffPl))
983
3348
        ### to zero posX -bboxX/2
984
 
        App.Console.PrintMessage("x: "+str(oripl_X)+" y: "+str(oripl_Y)+"z: "+str(oripl_Z)+"\r\n")
985
 
        App.Console.PrintMessage("axe "+axe+" placement"+str(diffPl)+"\r\n")
 
3349
        #say("x: "+str(oripl_X)+" y: "+str(oripl_Y)+"z: "+str(oripl_Z)+"\r\n")
 
3350
        #say("axe "+axe+" placement"+str(diffPl)+"\r\n")
986
3351
        #Part.show(shape)
987
3352
        objs[0].Placement=shape.Placement
988
 
        Gui.Selection.addSelection(objs[0])
989
 
        App.activeDocument().recompute()
990
 
        App.Console.PrintMessage("x: "+str(oripl_X)+"\r\ny: "+str(oripl_Y)+"\r\nz: "+str(oripl_Z)+"\r\n")
991
 
        #routineResetPlacement()
992
 
        #App.Console.PrintMessage("placement "+str(p[0]))
 
3353
        FreeCADGui.Selection.addSelection(objs[0])
 
3354
        FreeCAD.activeDocument().recompute()
 
3355
        #say("x: "+str(oripl_X)+"\r\ny: "+str(oripl_Y)+"\r\nz: "+str(oripl_Z)+"\r\n")
 
3356
        #say("placement "+str(p[0]))
993
3357
        #return [oripl_X, oripl_Y, oripl_Z,p.Base[0],p.Base[1],p.Base[2]];
994
3358
        if resetP==True:
995
3359
            routineResetPlacement()
996
 
 
997
3360
    else:
998
 
        App.Console.PrintMessage("Select ONE single part object !\r\n"+"\r\n")
 
3361
        say("Select ONE single part object !\r\n"+"\r\n")
999
3362
        #QtGui.QMessageBox.information(None,"Info ...","Select ONE single part object !\r\n"+"\r\n")
1000
3363
###  end routineP_XYZ
1001
3364
 
1002
3365
def get_position():
1003
3366
    global min_val
1004
 
    print 'routine get base position'
1005
 
    Gui.activateWorkbench("PartWorkbench")
1006
 
    #Gui.SendMsgToActiveView("ViewFit")
1007
 
    ##Gui.activeDocument().activeView().viewTop()
 
3367
    say('routine get base position\n')
 
3368
    FreeCADGui.activateWorkbench("PartWorkbench")
 
3369
    #FreeCADGui.SendMsgToActiveView("ViewFit")
 
3370
    ##FreeCADGui.activeDocument().activeView().viewTop()
1008
3371
    doc = FreeCAD.ActiveDocument
1009
 
    #App.Console.PrintMessage("hereXYZ !"+"\r\n")
 
3372
    #say("hereXYZ !"+"\r\n")
1010
3373
    selEx = FreeCADGui.Selection.getSelectionEx()
1011
3374
    objs = [selobj.Object for selobj in selEx]
1012
3375
    if len(objs) == 1:
1021
3384
        oripl_X = float(c[0])
1022
3385
        oripl_Y = float(c[1])
1023
3386
        oripl_Z = float(c[2])
1024
 
        Gui.Selection.addSelection(objs[0])
1025
 
        App.activeDocument().recompute()
1026
 
        App.Console.PrintMessage("x: "+str(oripl_X)+"\r\ny: "+str(oripl_Y)+"\r\nz: "+str(oripl_Z)+"\r\n")
 
3387
        FreeCADGui.Selection.addSelection(objs[0])
 
3388
        FreeCAD.activeDocument().recompute()
 
3389
        #say("x: "+str(oripl_X)+"\r\ny: "+str(oripl_Y)+"\r\nz: "+str(oripl_Z)+"\r\n")
1027
3390
        p=s.Placement
1028
 
        App.Console.PrintMessage("PlacementBase  : "+str(p)+"\n\n")
1029
 
        App.Console.PrintMessage(str(p.Base[0])+' '+str(p.Base[1])+' '+str(p.Base[2])+"\r\n")
 
3391
        #say("PlacementBase  : "+str(p)+"\n\n")
 
3392
        #say(str(p.Base[0])+' '+str(p.Base[1])+' '+str(p.Base[2])+"\r\n")
1030
3393
        ### to zero posX -bboxX/2
1031
 
        #App.Console.PrintMessage("placement "+str(p[0]))
 
3394
        #say("placement "+str(p[0]))
1032
3395
        #min_val=10e-16
1033
 
        App.Console.PrintMessage("min_val "+str(min_val)+'\r\n')
 
3396
        #say("min_val "+str(min_val)+'\r\n')
1034
3397
        if abs(oripl_X) < min_val:
1035
3398
            oripl_X=0
1036
3399
        if abs(oripl_Y) < min_val:
1040
3403
        return [oripl_X, oripl_Y, oripl_Z,p.Base[0],p.Base[1],p.Base[2]];
1041
3404
 
1042
3405
    else:
1043
 
        App.Console.PrintMessage("Select ONE single part object !\r\n"+"\r\n")
 
3406
        say("Select ONE single part object !\r\n"+"\r\n")
1044
3407
        #QtGui.QMessageBox.information(None,"Info ...","Select ONE single part object !\r\n"+"\r\n")
 
3408
        QtGui.qApp.restoreOverrideCursor()
1045
3409
        diag = QtGui.QMessageBox(QtGui.QMessageBox.Icon.Critical,
1046
3410
                                'Error in selection                                                                ."+"\r\n"',
1047
3411
                                'Select ONE single part object !')
1048
3412
        diag.setWindowModality(QtCore.Qt.ApplicationModal)
1049
3413
        diag.exec_()
1050
 
 
1051
3414
###  end get position
1052
3415
 
1053
3416
def routineM_XYZ(axe,v):
1054
3417
    global resetP
1055
 
    mydoc=App.ActiveDocument
1056
 
    print 'routine Move to point XYZ'
1057
 
    Gui.activateWorkbench("PartWorkbench")
1058
 
    #Gui.SendMsgToActiveView("ViewFit")
1059
 
    ##Gui.activeDocument().activeView().viewTop()
 
3418
    mydoc=FreeCAD.ActiveDocument
 
3419
    say('routine Move to point XYZ\n')
 
3420
    FreeCADGui.activateWorkbench("PartWorkbench")
 
3421
    #FreeCADGui.SendMsgToActiveView("ViewFit")
 
3422
    ##FreeCADGui.activeDocument().activeView().viewTop()
1060
3423
    doc = FreeCAD.ActiveDocument
1061
3424
    selEx = FreeCADGui.Selection.getSelectionEx()
1062
3425
    objs = [selobj.Object for selobj in selEx]
1075
3438
        shape=s.copy()
1076
3439
        shape.Placement=s.Placement;p=s.Placement
1077
3440
        #shape.rotate((oripl_X,oripl_Y,oripl_Z),(1,0,0),90)
1078
 
        App.Console.PrintMessage("axe "+axe+", value "+v+"\r\n")
 
3441
        #say("axe "+axe+", value "+v+"\r\n")
1079
3442
        if axe=='x':
1080
3443
            #if abs(float(v)-p.Base[0])>min_val:
1081
3444
            shape.translate((float(v)-oripl_X,0,0))
1085
3448
            shape.translate((0,0,float(v)-oripl_Z))
1086
3449
        #Part.show(shape)
1087
3450
        objs[0].Placement=shape.Placement
1088
 
        Gui.Selection.addSelection(objs[0])
1089
 
        App.activeDocument().recompute()
 
3451
        FreeCADGui.Selection.addSelection(objs[0])
 
3452
        FreeCAD.activeDocument().recompute()
1090
3453
        if resetP==True:
1091
3454
            routineResetPlacement()
1092
 
        App.Console.PrintMessage("end of rotineM!"+"\r\n")
 
3455
        #say("end of rotineM!"+"\r\n")
1093
3456
    else:
1094
 
        App.Console.PrintMessage("Select an object !"+"\r\n")
 
3457
        say("Select an object !"+"\r\n")
1095
3458
        #QtGui.QMessageBox.information(None,"Info ...","Select ONE single part object !\r\n"+"\r\n")
1096
3459
###  end Move to Point XYZ
1097
3460
 
1098
3461
def routineCollisions():
1099
 
 
1100
3462
    global conflict_tolerance
1101
3463
    def error_dialog(msg):
1102
3464
        """Create a simple dialog QMessageBox with an error message"""
1103
3465
        FreeCAD.Console.PrintError(msg + '\n')
 
3466
        QtGui.qApp.restoreOverrideCursor()
1104
3467
        diag = QtGui.QMessageBox(QtGui.QMessageBox.Icon.Critical,
1105
3468
                                'Error in checking Collisions                                                       ."+"\r\n"',
1106
3469
                                msg)
1107
3470
        diag.setWindowModality(QtCore.Qt.ApplicationModal)
1108
3471
        diag.exec_()
1109
3472
 
1110
 
    if len(FreeCAD.Gui.Selection.getSelectionEx()) < 2:
 
3473
    if len(FreeCADGui.Selection.getSelectionEx()) < 2:
1111
3474
        error_dialog('Select at least two objects')
1112
3475
        collisions=2
1113
3476
        return collisions
1114
3477
 
1115
3478
    object_list = []
1116
3479
    collisions=0
1117
 
    for obj in FreeCAD.Gui.Selection.getSelectionEx():
 
3480
    for obj in FreeCADGui.Selection.getSelectionEx():
1118
3481
        object_list.append(obj.Object)
1119
3482
 
1120
3483
    for i, object_a in enumerate(object_list):
1121
3484
        for object_b in object_list[(i + 1):]:
1122
 
            FreeCAD.Console.PrintMessage(object_a.Label+" "+object_b.Label+"\r\n")
 
3485
            say(object_a.Label+" "+object_b.Label+"\r\n")
1123
3486
            shape_a = object_a.Shape
1124
3487
            shape_b = object_b.Shape
1125
3488
            label_a = object_a.Label
1127
3490
            try:
1128
3491
                common = shape_a.common(shape_b)
1129
3492
                if common.Volume > conflict_tolerance:
1130
 
                    FreeCAD.Console.PrintMessage(
 
3493
                    say(
1131
3494
                        'Volume of the intersection between {} and {}: {}\n'.format(
1132
3495
                            label_a,
1133
3496
                            label_b,
1145
3508
                    object_b.ViewObject.Visibility=False
1146
3509
                    collisions=1
1147
3510
                else:
1148
 
                    FreeCAD.Console.PrintMessage(
 
3511
                    say(
1149
3512
                        'No intersection between {} and {}\n'.format(
1150
3513
                            label_a,
1151
3514
                            label_b))
1152
3515
                    #collisions=0
1153
3516
            except Exception, e:
1154
3517
                FreeCAD.Console.PrintWarning(u"{0}\n".format(e))
1155
 
            #FreeCAD.Console.PrintMessage("here_collision\r\n")
 
3518
            #say("here_collision\r\n")
1156
3519
    return collisions
1157
3520
 
1158
3521
### end Collisions
1159
3522
 
1160
3523
def create_axis():
1161
3524
 
1162
 
    App.ActiveDocument.addObject("App::DocumentObjectGroup", "axis")
 
3525
    FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup", "axis")
1163
3526
    #Z axis
1164
 
    App.ActiveDocument.addObject("Part::Box","AxisBoxZ")
1165
 
    App.ActiveDocument.ActiveObject.Label = "CubeZ"
1166
 
    App.ActiveDocument.addObject("Part::Cone","AxisConeZ")
1167
 
    App.ActiveDocument.ActiveObject.Label = "ConeZ"
1168
 
    App.ActiveDocument.getObject("AxisBoxZ").Width = '0 mm'
1169
 
    App.ActiveDocument.getObject("AxisBoxZ").Width = '0.1 mm'
1170
 
    App.ActiveDocument.getObject("AxisBoxZ").Length = '0 mm'
1171
 
    App.ActiveDocument.getObject("AxisBoxZ").Length = '0.2 mm'
1172
 
    App.ActiveDocument.getObject("AxisConeZ").Radius1 = '0 mm'
1173
 
    App.ActiveDocument.getObject("AxisConeZ").Radius1 = '0.4 mm'
1174
 
    App.ActiveDocument.getObject("AxisConeZ").Radius2 = '0 mm'
1175
 
    App.ActiveDocument.getObject("AxisConeZ").Radius2 = '0.1 mm'
1176
 
    App.ActiveDocument.getObject("AxisConeZ").Placement = App.Placement(App.Vector(0,0,9),App.Rotation(App.Vector(0,0,1),0))
1177
 
    App.ActiveDocument.getObject("AxisConeZ").Height = '5 mm'
1178
 
    App.ActiveDocument.getObject("AxisBoxZ").Placement = App.Placement(App.Vector(-0.1,-0.05,0),App.Rotation(App.Vector(0,0,1),0))
1179
 
    Gui.ActiveDocument.getObject("AxisConeZ").ShapeColor = (0.0000,0.0000,1.0000)
1180
 
    Gui.ActiveDocument.getObject("AxisBoxZ").ShapeColor = (0.0000,0.0000,1.0000)
1181
 
    App.activeDocument().addObject("Part::MultiFuse","FusionAxisZ")
1182
 
    App.activeDocument().FusionAxisZ.Shapes = [App.activeDocument().AxisBoxZ,App.activeDocument().AxisConeZ,]
1183
 
    Gui.activeDocument().AxisBoxZ.Visibility=False
1184
 
    Gui.activeDocument().AxisConeZ.Visibility=False
1185
 
    Gui.ActiveDocument.FusionAxisZ.ShapeColor=Gui.ActiveDocument.AxisBoxZ.ShapeColor
1186
 
    Gui.ActiveDocument.FusionAxisZ.DisplayMode=Gui.ActiveDocument.AxisBoxZ.DisplayMode
1187
 
    App.ActiveDocument.recompute()
1188
 
    App.ActiveDocument.addObject('Part::Feature','FusionAxisZ1').Shape=App.ActiveDocument.FusionAxisZ.Shape
1189
 
    App.ActiveDocument.ActiveObject.Label = "Z"
 
3527
    FreeCAD.ActiveDocument.addObject("Part::Box","AxisBoxZ")
 
3528
    FreeCAD.ActiveDocument.ActiveObject.Label = "CubeZ"
 
3529
    FreeCAD.ActiveDocument.addObject("Part::Cone","AxisConeZ")
 
3530
    FreeCAD.ActiveDocument.ActiveObject.Label = "ConeZ"
 
3531
    FreeCAD.ActiveDocument.getObject("AxisBoxZ").Width = '0 mm'
 
3532
    FreeCAD.ActiveDocument.getObject("AxisBoxZ").Width = '0.1 mm'
 
3533
    FreeCAD.ActiveDocument.getObject("AxisBoxZ").Length = '0 mm'
 
3534
    FreeCAD.ActiveDocument.getObject("AxisBoxZ").Length = '0.2 mm'
 
3535
    FreeCAD.ActiveDocument.getObject("AxisConeZ").Radius1 = '0 mm'
 
3536
    FreeCAD.ActiveDocument.getObject("AxisConeZ").Radius1 = '0.4 mm'
 
3537
    FreeCAD.ActiveDocument.getObject("AxisConeZ").Radius2 = '0 mm'
 
3538
    FreeCAD.ActiveDocument.getObject("AxisConeZ").Radius2 = '0.1 mm'
 
3539
    FreeCAD.ActiveDocument.getObject("AxisConeZ").Placement = FreeCAD.Placement(FreeCAD.Vector(0,0,9),FreeCAD.Rotation(FreeCAD.Vector(0,0,1),0))
 
3540
    FreeCAD.ActiveDocument.getObject("AxisConeZ").Height = '5 mm'
 
3541
    FreeCAD.ActiveDocument.getObject("AxisBoxZ").Placement = FreeCAD.Placement(FreeCAD.Vector(-0.1,-0.05,0),FreeCAD.Rotation(FreeCAD.Vector(0,0,1),0))
 
3542
    FreeCADGui.ActiveDocument.getObject("AxisConeZ").ShapeColor = (0.0000,0.0000,1.0000)
 
3543
    FreeCADGui.ActiveDocument.getObject("AxisBoxZ").ShapeColor = (0.0000,0.0000,1.0000)
 
3544
    FreeCAD.activeDocument().addObject("Part::MultiFuse","FusionAxisZ")
 
3545
    FreeCAD.activeDocument().FusionAxisZ.Shapes = [FreeCAD.activeDocument().AxisBoxZ,FreeCAD.activeDocument().AxisConeZ,]
 
3546
    FreeCADGui.activeDocument().AxisBoxZ.Visibility=False
 
3547
    FreeCADGui.activeDocument().AxisConeZ.Visibility=False
 
3548
    FreeCADGui.ActiveDocument.FusionAxisZ.ShapeColor=FreeCADGui.ActiveDocument.AxisBoxZ.ShapeColor
 
3549
    FreeCADGui.ActiveDocument.FusionAxisZ.DisplayMode=FreeCADGui.ActiveDocument.AxisBoxZ.DisplayMode
 
3550
    FreeCAD.ActiveDocument.recompute()
 
3551
    FreeCAD.ActiveDocument.addObject('Part::Feature','FusionAxisZ1').Shape=FreeCAD.ActiveDocument.FusionAxisZ.Shape
 
3552
    FreeCAD.ActiveDocument.ActiveObject.Label = "Z"
1190
3553
 
1191
 
    Gui.ActiveDocument.ActiveObject.ShapeColor=(0.0000,0.0000,1.0000)
1192
 
    obj=App.ActiveDocument.ActiveObject
1193
 
    App.ActiveDocument.getObject("axis").addObject(obj)
1194
 
    App.ActiveDocument.recompute()
1195
 
    App.ActiveDocument.removeObject("FusionAxisZ")
1196
 
    App.ActiveDocument.removeObject("AxisBoxZ")
1197
 
    App.ActiveDocument.removeObject("AxisConeZ")
1198
 
    App.ActiveDocument.recompute()
 
3554
    FreeCADGui.ActiveDocument.ActiveObject.ShapeColor=(0.0000,0.0000,1.0000)
 
3555
    obj=FreeCAD.ActiveDocument.ActiveObject
 
3556
    FreeCAD.ActiveDocument.getObject("axis").addObject(obj)
 
3557
    FreeCAD.ActiveDocument.recompute()
 
3558
    FreeCAD.ActiveDocument.removeObject("FusionAxisZ")
 
3559
    FreeCAD.ActiveDocument.removeObject("AxisBoxZ")
 
3560
    FreeCAD.ActiveDocument.removeObject("AxisConeZ")
 
3561
    FreeCAD.ActiveDocument.recompute()
1199
3562
 
1200
3563
    #Y axis
1201
 
    App.ActiveDocument.addObject("Part::Box","AxisBoxY")
1202
 
    App.ActiveDocument.ActiveObject.Label = "CubeY"
1203
 
    App.ActiveDocument.addObject("Part::Cone","AxisConeY")
1204
 
    App.ActiveDocument.ActiveObject.Label = "ConeY"
1205
 
    App.ActiveDocument.getObject("AxisBoxY").Width = '0 mm'
1206
 
    App.ActiveDocument.getObject("AxisBoxY").Width = '0.1 mm'
1207
 
    App.ActiveDocument.getObject("AxisBoxY").Length = '0 mm'
1208
 
    App.ActiveDocument.getObject("AxisBoxY").Length = '0.2 mm'
1209
 
    App.ActiveDocument.getObject("AxisConeY").Radius1 = '0 mm'
1210
 
    App.ActiveDocument.getObject("AxisConeY").Radius1 = '0.4 mm'
1211
 
    App.ActiveDocument.getObject("AxisConeY").Radius2 = '0 mm'
1212
 
    App.ActiveDocument.getObject("AxisConeY").Radius2 = '0.1 mm'
1213
 
    App.ActiveDocument.getObject("AxisConeY").Placement = App.Placement(App.Vector(0,0,9),App.Rotation(App.Vector(0,0,1),0))
1214
 
    App.ActiveDocument.getObject("AxisConeY").Height = '5 mm'
1215
 
    App.ActiveDocument.getObject("AxisBoxY").Placement = App.Placement(App.Vector(-0.1,-0.05,0),App.Rotation(App.Vector(0,0,1),0))
1216
 
    Gui.ActiveDocument.getObject("AxisConeY").ShapeColor = (0.0000,1.0000,0.0000)
1217
 
    Gui.ActiveDocument.getObject("AxisBoxY").ShapeColor = (0.0000,1.0000,0.0000)
1218
 
    App.activeDocument().addObject("Part::MultiFuse","FusionAxisY")
1219
 
    App.activeDocument().FusionAxisY.Shapes = [App.activeDocument().AxisBoxY,App.activeDocument().AxisConeY,]
1220
 
    Gui.activeDocument().AxisBoxY.Visibility=False
1221
 
    Gui.activeDocument().AxisConeY.Visibility=False
1222
 
    Gui.ActiveDocument.FusionAxisY.ShapeColor=Gui.ActiveDocument.AxisBoxY.ShapeColor
1223
 
    Gui.ActiveDocument.FusionAxisY.DisplayMode=Gui.ActiveDocument.AxisBoxY.DisplayMode
1224
 
    App.ActiveDocument.recompute()
1225
 
    App.ActiveDocument.addObject('Part::Feature','FusionAxisY1').Shape=App.ActiveDocument.FusionAxisY.Shape
1226
 
    App.ActiveDocument.ActiveObject.Label = "Y"
 
3564
    FreeCAD.ActiveDocument.addObject("Part::Box","AxisBoxY")
 
3565
    FreeCAD.ActiveDocument.ActiveObject.Label = "CubeY"
 
3566
    FreeCAD.ActiveDocument.addObject("Part::Cone","AxisConeY")
 
3567
    FreeCAD.ActiveDocument.ActiveObject.Label = "ConeY"
 
3568
    FreeCAD.ActiveDocument.getObject("AxisBoxY").Width = '0 mm'
 
3569
    FreeCAD.ActiveDocument.getObject("AxisBoxY").Width = '0.1 mm'
 
3570
    FreeCAD.ActiveDocument.getObject("AxisBoxY").Length = '0 mm'
 
3571
    FreeCAD.ActiveDocument.getObject("AxisBoxY").Length = '0.2 mm'
 
3572
    FreeCAD.ActiveDocument.getObject("AxisConeY").Radius1 = '0 mm'
 
3573
    FreeCAD.ActiveDocument.getObject("AxisConeY").Radius1 = '0.4 mm'
 
3574
    FreeCAD.ActiveDocument.getObject("AxisConeY").Radius2 = '0 mm'
 
3575
    FreeCAD.ActiveDocument.getObject("AxisConeY").Radius2 = '0.1 mm'
 
3576
    FreeCAD.ActiveDocument.getObject("AxisConeY").Placement = FreeCAD.Placement(FreeCAD.Vector(0,0,9),FreeCAD.Rotation(FreeCAD.Vector(0,0,1),0))
 
3577
    FreeCAD.ActiveDocument.getObject("AxisConeY").Height = '5 mm'
 
3578
    FreeCAD.ActiveDocument.getObject("AxisBoxY").Placement = FreeCAD.Placement(FreeCAD.Vector(-0.1,-0.05,0),FreeCAD.Rotation(FreeCAD.Vector(0,0,1),0))
 
3579
    FreeCADGui.ActiveDocument.getObject("AxisConeY").ShapeColor = (0.0000,1.0000,0.0000)
 
3580
    FreeCADGui.ActiveDocument.getObject("AxisBoxY").ShapeColor = (0.0000,1.0000,0.0000)
 
3581
    FreeCAD.activeDocument().addObject("Part::MultiFuse","FusionAxisY")
 
3582
    FreeCAD.activeDocument().FusionAxisY.Shapes = [FreeCAD.activeDocument().AxisBoxY,FreeCAD.activeDocument().AxisConeY,]
 
3583
    FreeCADGui.activeDocument().AxisBoxY.Visibility=False
 
3584
    FreeCADGui.activeDocument().AxisConeY.Visibility=False
 
3585
    FreeCADGui.ActiveDocument.FusionAxisY.ShapeColor=FreeCADGui.ActiveDocument.AxisBoxY.ShapeColor
 
3586
    FreeCADGui.ActiveDocument.FusionAxisY.DisplayMode=FreeCADGui.ActiveDocument.AxisBoxY.DisplayMode
 
3587
    FreeCAD.ActiveDocument.recompute()
 
3588
    FreeCAD.ActiveDocument.addObject('Part::Feature','FusionAxisY1').Shape=FreeCAD.ActiveDocument.FusionAxisY.Shape
 
3589
    FreeCAD.ActiveDocument.ActiveObject.Label = "Y"
1227
3590
 
1228
 
    Gui.ActiveDocument.ActiveObject.ShapeColor=(0.0000,1.0000,0.000)
1229
 
    obj=App.ActiveDocument.ActiveObject
1230
 
    App.ActiveDocument.getObject("axis").addObject(obj)
1231
 
    App.ActiveDocument.recompute()
1232
 
    App.ActiveDocument.removeObject("FusionAxisY")
1233
 
    App.ActiveDocument.removeObject("AxisBoxY")
1234
 
    App.ActiveDocument.removeObject("AxisConeY")
1235
 
    App.ActiveDocument.recompute()
1236
 
    App.ActiveDocument.ActiveObject.Placement = App.Placement(App.Vector(0,0,0.05),App.Rotation(App.Vector(1,0,0),-90))
 
3591
    FreeCADGui.ActiveDocument.ActiveObject.ShapeColor=(0.0000,1.0000,0.000)
 
3592
    obj=FreeCAD.ActiveDocument.ActiveObject
 
3593
    FreeCAD.ActiveDocument.getObject("axis").addObject(obj)
 
3594
    FreeCAD.ActiveDocument.recompute()
 
3595
    FreeCAD.ActiveDocument.removeObject("FusionAxisY")
 
3596
    FreeCAD.ActiveDocument.removeObject("AxisBoxY")
 
3597
    FreeCAD.ActiveDocument.removeObject("AxisConeY")
 
3598
    FreeCAD.ActiveDocument.recompute()
 
3599
    FreeCAD.ActiveDocument.ActiveObject.Placement = FreeCAD.Placement(FreeCAD.Vector(0,0,0.05),FreeCAD.Rotation(FreeCAD.Vector(1,0,0),-90))
1237
3600
 
1238
3601
    #X axis
1239
 
    App.ActiveDocument.addObject("Part::Box","AxisBoxX")
1240
 
    App.ActiveDocument.ActiveObject.Label = "CubeX"
1241
 
    App.ActiveDocument.addObject("Part::Cone","AxisConeX")
1242
 
    App.ActiveDocument.ActiveObject.Label = "ConeX"
1243
 
    App.ActiveDocument.getObject("AxisBoxX").Width = '0 mm'
1244
 
    App.ActiveDocument.getObject("AxisBoxX").Width = '0.2 mm'
1245
 
    App.ActiveDocument.getObject("AxisBoxX").Length = '0 mm'
1246
 
    App.ActiveDocument.getObject("AxisBoxX").Length = '0.1 mm'
1247
 
    App.ActiveDocument.getObject("AxisConeX").Radius1 = '0 mm'
1248
 
    App.ActiveDocument.getObject("AxisConeX").Radius1 = '0.4 mm'
1249
 
    App.ActiveDocument.getObject("AxisConeX").Radius2 = '0 mm'
1250
 
    App.ActiveDocument.getObject("AxisConeX").Radius2 = '0.1 mm'
1251
 
    App.ActiveDocument.getObject("AxisConeX").Placement = App.Placement(App.Vector(0,0,9),App.Rotation(App.Vector(0,0,1),0))
1252
 
    App.ActiveDocument.getObject("AxisConeX").Height = '5 mm'
1253
 
    App.ActiveDocument.getObject("AxisBoxX").Placement = App.Placement(App.Vector(-0.1,-0.05,0),App.Rotation(App.Vector(0,0,1),0))
1254
 
    Gui.ActiveDocument.getObject("AxisConeX").ShapeColor = (1.0000,0.0000,0.0000)
1255
 
    Gui.ActiveDocument.getObject("AxisBoxX").ShapeColor = (1.0000,0.0000,0.0000)
1256
 
    App.activeDocument().addObject("Part::MultiFuse","FusionAxisX")
1257
 
    App.activeDocument().FusionAxisX.Shapes = [App.activeDocument().AxisBoxX,App.activeDocument().AxisConeX,]
1258
 
    Gui.activeDocument().AxisBoxX.Visibility=False
1259
 
    Gui.activeDocument().AxisConeX.Visibility=False
1260
 
    Gui.ActiveDocument.FusionAxisX.ShapeColor=Gui.ActiveDocument.AxisBoxX.ShapeColor
1261
 
    Gui.ActiveDocument.FusionAxisX.DisplayMode=Gui.ActiveDocument.AxisBoxX.DisplayMode
1262
 
    App.ActiveDocument.recompute()
1263
 
    App.ActiveDocument.addObject('Part::Feature','FusionAxisX1').Shape=App.ActiveDocument.FusionAxisX.Shape
1264
 
    App.ActiveDocument.ActiveObject.Label="X"
1265
 
 
1266
 
    Gui.ActiveDocument.ActiveObject.ShapeColor=(1.0000,0.0000,0.0000)
1267
 
    obj=App.ActiveDocument.ActiveObject
1268
 
    App.ActiveDocument.getObject("axis").addObject(obj)
1269
 
    App.ActiveDocument.recompute()
1270
 
    App.ActiveDocument.removeObject("FusionAxisX")
1271
 
    App.ActiveDocument.removeObject("AxisBoxX")
1272
 
    App.ActiveDocument.removeObject("AxisConeX")
1273
 
    App.ActiveDocument.getObject("FusionAxisX1").Placement = App.Placement(App.Vector(0,-0.05,0),App.Rotation(App.Vector(0,1,0),90))
1274
 
 
1275
 
    App.ActiveDocument.recompute()
 
3602
    FreeCAD.ActiveDocument.addObject("Part::Box","AxisBoxX")
 
3603
    FreeCAD.ActiveDocument.ActiveObject.Label = "CubeX"
 
3604
    FreeCAD.ActiveDocument.addObject("Part::Cone","AxisConeX")
 
3605
    FreeCAD.ActiveDocument.ActiveObject.Label = "ConeX"
 
3606
    FreeCAD.ActiveDocument.getObject("AxisBoxX").Width = '0 mm'
 
3607
    FreeCAD.ActiveDocument.getObject("AxisBoxX").Width = '0.2 mm'
 
3608
    FreeCAD.ActiveDocument.getObject("AxisBoxX").Length = '0 mm'
 
3609
    FreeCAD.ActiveDocument.getObject("AxisBoxX").Length = '0.1 mm'
 
3610
    FreeCAD.ActiveDocument.getObject("AxisConeX").Radius1 = '0 mm'
 
3611
    FreeCAD.ActiveDocument.getObject("AxisConeX").Radius1 = '0.4 mm'
 
3612
    FreeCAD.ActiveDocument.getObject("AxisConeX").Radius2 = '0 mm'
 
3613
    FreeCAD.ActiveDocument.getObject("AxisConeX").Radius2 = '0.1 mm'
 
3614
    FreeCAD.ActiveDocument.getObject("AxisConeX").Placement = FreeCAD.Placement(FreeCAD.Vector(0,0,9),FreeCAD.Rotation(FreeCAD.Vector(0,0,1),0))
 
3615
    FreeCAD.ActiveDocument.getObject("AxisConeX").Height = '5 mm'
 
3616
    FreeCAD.ActiveDocument.getObject("AxisBoxX").Placement = FreeCAD.Placement(FreeCAD.Vector(-0.1,-0.05,0),FreeCAD.Rotation(FreeCAD.Vector(0,0,1),0))
 
3617
    FreeCADGui.ActiveDocument.getObject("AxisConeX").ShapeColor = (1.0000,0.0000,0.0000)
 
3618
    FreeCADGui.ActiveDocument.getObject("AxisBoxX").ShapeColor = (1.0000,0.0000,0.0000)
 
3619
    FreeCAD.activeDocument().addObject("Part::MultiFuse","FusionAxisX")
 
3620
    FreeCAD.activeDocument().FusionAxisX.Shapes = [FreeCAD.activeDocument().AxisBoxX,FreeCAD.activeDocument().AxisConeX,]
 
3621
    FreeCADGui.activeDocument().AxisBoxX.Visibility=False
 
3622
    FreeCADGui.activeDocument().AxisConeX.Visibility=False
 
3623
    FreeCADGui.ActiveDocument.FusionAxisX.ShapeColor=FreeCADGui.ActiveDocument.AxisBoxX.ShapeColor
 
3624
    FreeCADGui.ActiveDocument.FusionAxisX.DisplayMode=FreeCADGui.ActiveDocument.AxisBoxX.DisplayMode
 
3625
    FreeCAD.ActiveDocument.recompute()
 
3626
    FreeCAD.ActiveDocument.addObject('Part::Feature','FusionAxisX1').Shape=FreeCAD.ActiveDocument.FusionAxisX.Shape
 
3627
    FreeCAD.ActiveDocument.ActiveObject.Label="X"
 
3628
 
 
3629
    FreeCADGui.ActiveDocument.ActiveObject.ShapeColor=(1.0000,0.0000,0.0000)
 
3630
    obj=FreeCAD.ActiveDocument.ActiveObject
 
3631
    FreeCAD.ActiveDocument.getObject("axis").addObject(obj)
 
3632
    FreeCAD.ActiveDocument.recompute()
 
3633
    FreeCAD.ActiveDocument.removeObject("FusionAxisX")
 
3634
    FreeCAD.ActiveDocument.removeObject("AxisBoxX")
 
3635
    FreeCAD.ActiveDocument.removeObject("AxisConeX")
 
3636
    FreeCAD.ActiveDocument.getObject("FusionAxisX1").Placement = FreeCAD.Placement(FreeCAD.Vector(0,-0.05,0),FreeCAD.Rotation(FreeCAD.Vector(0,1,0),90))
 
3637
 
 
3638
    FreeCAD.ActiveDocument.recompute()
1276
3639
###
1277
3640
#############################
1278
 
def createSolidBBox(model3D):
1279
 
    #Gui.Selection.removeSelection(App.activeDocument().ActiveObject)
 
3641
def createSolidBBox2(model3D):
 
3642
    #FreeCADGui.Selection.removeSelection(FreeCAD.activeDocument().ActiveObject)
1280
3643
    selEx=model3D
1281
3644
    selEx = FreeCADGui.Selection.getSelectionEx()
1282
3645
    objs = [selobj.Object for selobj in selEx]
1283
3646
    if len(objs) == 1:
1284
3647
        s = objs[0].Shape
1285
3648
        name=objs[0].Label
1286
 
        App.Console.PrintMessage(name+" name \r\n")
 
3649
        #say(name+" name \r\n")
1287
3650
        # boundBox
1288
3651
        delta=0.6
1289
3652
        boundBox_ = s.BoundBox
1302
3665
        #oripl_Z = float(c[2])+offZ
1303
3666
        oripl_Z = -boundBoxLZ+offZ
1304
3667
 
1305
 
        App.Console.PrintMessage(str(boundBox_)+"\r\n")
1306
 
        App.Console.PrintMessage("Rectangle : "+str(boundBox_.XLength)+" x "+str(boundBox_.YLength)+" x "+str(boundBox_.ZLength)+"\r\n")
1307
 
        App.Console.PrintMessage("_____________________"+"\r\n")
1308
 
        App.Console.PrintMessage("x: "+str(oripl_X)+" y: "+str(oripl_Y)+"z: "+str(oripl_Z)+"\r\n")
 
3668
        #say(str(boundBox_)+"\r\n")
 
3669
        #say("Rectangle : "+str(boundBox_.XLength)+" x "+str(boundBox_.YLength)+" x "+str(boundBox_.ZLength)+"\r\n")
 
3670
        #say("_____________________"+"\r\n")
 
3671
        #say("x: "+str(oripl_X)+" y: "+str(oripl_Y)+"z: "+str(oripl_Z)+"\r\n")
1309
3672
 
1310
 
        obj=App.ActiveDocument.addObject('Part::Feature',name)
1311
 
        #obj.Shape=Part.makeBox(boundBox_.XLength, boundBox_.YLength, boundBox_.ZLength, App.Vector(oripl_X,oripl_Y,oripl_Z), App.Vector(0,0,01))
1312
 
        #obj.Shape=Part.makeBox(boundBoxLX, boundBoxLY, boundBoxLZ, App.Vector(oripl_X,oripl_Y,oripl_Z), App.Vector(0,0,01))
1313
 
        obj.Shape=Part.makeBox(boundBoxLX, boundBoxLY, boundBoxLZ, App.Vector(oripl_X,oripl_Y,oripl_Z), App.Vector(0,0,01))
 
3673
        obj=FreeCAD.ActiveDocument.addObject('Part::Feature',name)
 
3674
        #obj.Shape=Part.makeBox(boundBox_.XLength, boundBox_.YLength, boundBox_.ZLength, FreeCAD.Vector(oripl_X,oripl_Y,oripl_Z), FreeCAD.Vector(0,0,01))
 
3675
        #obj.Shape=Part.makeBox(boundBoxLX, boundBoxLY, boundBoxLZ, FreeCAD.Vector(oripl_X,oripl_Y,oripl_Z), FreeCAD.Vector(0,0,01))
 
3676
        obj.Shape=Part.makeBox(boundBoxLX, boundBoxLY, boundBoxLZ, FreeCAD.Vector(oripl_X,oripl_Y,oripl_Z), FreeCAD.Vector(0,0,01))
1314
3677
 
1315
3678
        #obj.translate(offX,offY,0)
1316
3679
        # Part.show(cube)
1317
 
        App.Console.PrintMessage("cube name "+ obj.Name+'\r\n')
1318
 
        ### App.ActiveDocument.recompute()
 
3680
        #say("cube name "+ obj.Name+'\r\n')
 
3681
        ### FreeCAD.ActiveDocument.recompute()
1319
3682
    else:
1320
 
        App.Console.PrintMessage("Select a single part object !"+"\r\n")
 
3683
        say("Select a single part object !\n")
1321
3684
    #end bbox macro
1322
3685
 
1323
3686
    name=obj.Name
1324
 
    App.Console.PrintMessage("bbox name "+name+"\r\n")
 
3687
    #say("bbox name "+name+"\r\n")
1325
3688
    del objs
1326
3689
    return name
1327
3690
 
1328
 
 
1329
3691
###
1330
3692
def rotateObj(mainObj, rot):
1331
3693
    return mainObj.rotate(FreeCAD.Vector(rot[0], rot[1], 0), FreeCAD.Vector(0, 0, 1), rot[2])
1393
3755
    data = []
1394
3756
    source = ''.join(content)
1395
3757
    #
1396
 
    data1 = re.findall(r'\({1}\s+\(start\s+([0-9\.-]*?)\s+([0-9\.-]*?)\)\s+\(end\s+([0-9\.-]*?)\s+([0-9\.-]*?)\)(\s+\(angle\s+[0-9\.-]*?\)\s+|\s+)\(layer\s+{0}\)\s+\(width\s+([0-9\.]*?)\)\)'.format(layer, oType), source, re.MULTILINE|re.DOTALL)
1397
 
    #App.Console.PrintMessage(data1)
 
3758
    #data1 = re.findall(r'\({1}\s+\(start\s+([0-9\.-]*?)\s+([0-9\.-]*?)\)\s+\(end\s+([0-9\.-]*?)\s+([0-9\.-]*?)\)(\s+\(angle\s+[0-9\.-]*?\)\s+|\s+)\(layer\s+{0}\)\s+\(width\s+([0-9\.]*?)\)\)'.format(layer, oType), source, re.MULTILINE|re.DOTALL)
 
3759
    data1 = re.findall(r'\({1}\s+\(start\s+([0-9\.-]*?)\s+([0-9\.-]*?)\)\s+\(end\s+([0-9\.-]*?)\s+([0-9\.-]*?)\)(\s+\(angle\s+[0-9\.-]*?\)\s+|\s+)\(layer\s+{0}\)\s+\(width\s+([0-9\.]*?)\)'.format(layer, oType), source, re.MULTILINE|re.DOTALL)
 
3760
    #say(data1)
1398
3761
    for i in data1:
1399
3762
        x1 = float(i[0])
1400
3763
        y1 = float(i[1]) * (-1)
1410
3773
    data = []
1411
3774
    #
1412
3775
    source = ''.join(content)
1413
 
    data1 = re.findall(r'\({1}\s+\(center\s+([0-9\.-]*?)\s+([0-9\.-]*?)\)\s+\(end\s+([0-9\.-]*?)\s+([0-9\.-]*?)\)\s+\(layer\s+{0}\)(\s+\(width\s+([0-9\.]*?)\)|)\)'.format(layer, oType), source, re.MULTILINE|re.DOTALL)
1414
 
    #App.Console.PrintMessage(source)
1415
 
    #App.Console.PrintMessage(data1)
 
3776
    #data1 = re.findall(r'\({1}\s+\(center\s+([0-9\.-]*?)\s+([0-9\.-]*?)\)\s+\(end\s+([0-9\.-]*?)\s+([0-9\.-]*?)\)\s+\(layer\s+{0}\)(\s+\(width\s+([0-9\.]*?)\)|)\)'.format(layer, oType), source, re.MULTILINE|re.DOTALL)
 
3777
    data1 = re.findall(r'\({1}\s+\(center\s+([0-9\.-]*?)\s+([0-9\.-]*?)\)\s+\(end\s+([0-9\.-]*?)\s+([0-9\.-]*?)\)\s+\(layer\s+{0}\)(\s+\(width\s+([0-9\.]*?)\)|)'.format(layer, oType), source, re.MULTILINE|re.DOTALL)
 
3778
    #say(source)
 
3779
    #say(data1)
1416
3780
    for i in data1:
1417
3781
        xs = float(i[0])
1418
3782
        ys = float(i[1]) * (-1)
1428
3792
 
1429
3793
        data.append([xs, ys, radius, width])
1430
3794
    #
1431
 
    #App.Console.PrintMessage(data)
 
3795
    #say(data)
1432
3796
    return data
1433
3797
###
1434
3798
def rotPoint(point, ref, angle):
1451
3815
    data = []
1452
3816
    #
1453
3817
    source = ''.join(content)
1454
 
    data1 = re.findall(r'\({1}\s+\(start\s+([0-9\.-]*?)\s+([0-9\.-]*?)\)\s+\(end\s+([0-9\.-]*?)\s+([0-9\.-]*?)\)\s+\(angle\s+([0-9\.-]*?)\)\s+\(layer\s+{0}\)(\s+\(width\s+([0-9\.]*?)\)|)\)'.format(layer, oType), source, re.MULTILINE|re.DOTALL)
 
3818
    #data1 = re.findall(r'\({1}\s+\(start\s+([0-9\.-]*?)\s+([0-9\.-]*?)\)\s+\(end\s+([0-9\.-]*?)\s+([0-9\.-]*?)\)\s+\(angle\s+([0-9\.-]*?)\)\s+\(layer\s+{0}\)(\s+\(width\s+([0-9\.]*?)\)|)\)'.format(layer, oType), source, re.MULTILINE|re.DOTALL)
 
3819
    data1 = re.findall(r'\({1}\s+\(start\s+([0-9\.-]*?)\s+([0-9\.-]*?)\)\s+\(end\s+([0-9\.-]*?)\s+([0-9\.-]*?)\)\s+\(angle\s+([0-9\.-]*?)\)\s+\(layer\s+{0}\)(\s+\(width\s+([0-9\.]*?)|)\)'.format(layer, oType), source, re.MULTILINE|re.DOTALL)
1455
3820
    for i in data1:
1456
3821
        xs = float(i[0])
1457
3822
        ys = float(i[1])
1470
3835
    return data
1471
3836
 
1472
3837
def getModName(source):
1473
 
    #FreeCAD.Console.PrintMessage("here test0")
 
3838
    #say("here test0")
1474
3839
    #for x in source:
1475
3840
    #    x.encode('utf-8')
1476
 
    #    FreeCAD.Console.PrintMessage(x+"\r\n")
 
3841
    #    say(x+"\r\n")
1477
3842
 
1478
 
    #FreeCAD.Console.PrintMessage("here test1")
 
3843
    #say("here test1")
1479
3844
    #model = ''.join(u)
1480
3845
    model = ''.join(source)
1481
 
    #FreeCAD.Console.PrintMessage("here test2")
 
3846
    #say("here test2")
1482
3847
    model_name = re.search(r'\(module\s+(.+?)\(layer', model, re.MULTILINE|re.DOTALL).groups(0)[0]
1483
3848
 
1484
3849
    return model_name
1485
3850
###
 
3851
def getwrlData(source):
 
3852
    model = ''.join(source)
 
3853
    wrl_pos=['0', '0', '0']
 
3854
    if re.search(r'\(at\s+\(xyz+\s(.+?)\)', model, re.MULTILINE|re.DOTALL) is not None:
 
3855
        pos_vrml = re.search(r'\(at\s+\(xyz+\s(.+?)\)', model, re.MULTILINE|re.DOTALL).groups(0)[0]
 
3856
        #pos_vrml=pos_vrml[5:]
 
3857
        wrl_pos=pos_vrml.split(" ")
 
3858
        xp_vrml=wrl_pos[0]
 
3859
        #say('alive')
 
3860
        yp_vrml=wrl_pos[1]
 
3861
        zp_vrml=wrl_pos[2]
 
3862
        #say(wrl_pos);say('\n')
 
3863
        #wrl_pos=(xp_vrml,yp_vrml,zp_vrml)
 
3864
    #say(wrl_pos);say('\n')
 
3865
    #    
 
3866
    scale_vrml=['1', '1', '1']
 
3867
    if re.search(r'\(scale\s+(.+?)\)', model, re.MULTILINE|re.DOTALL) is not None:
 
3868
        sc_vrml = re.search(r'\(scale\s+(.+?)\)', model, re.MULTILINE|re.DOTALL).groups(0)[0]
 
3869
        sc_vrml=sc_vrml[5:]
 
3870
        scale_vrml=sc_vrml.split(" ")
 
3871
        xsc_vrml=scale_vrml[0]
 
3872
        ysc_vrml=scale_vrml[1]
 
3873
        zsc_vrml=scale_vrml[2]        
 
3874
        #say(scale_vrml);say('\n')
 
3875
    #say(scale_vrml);say('\n')
 
3876
    #
 
3877
    rot_wrl=['0', '0', '0']
 
3878
    zrot_vrml=''
 
3879
    if re.search(r'\(rotate\s+(.+?)\)', model, re.MULTILINE|re.DOTALL) is not None:
 
3880
        rot_vrml = re.search(r'\(rotate\s+(.+?)\)', model, re.MULTILINE|re.DOTALL).groups(0)[0]
 
3881
        rot_vrml=rot_vrml[5:]
 
3882
        rot_wrl=rot_vrml.split(" ")
 
3883
        xrot_vrml=rot_wrl[0]
 
3884
        yrot_vrml=rot_wrl[1]
 
3885
        zrot_vrml=rot_wrl[2]
 
3886
        #say(rot_wrl);say('\n')
 
3887
    else:
 
3888
        rotz_vrml=False
 
3889
    #say("hereA")
 
3890
    #if rotz_vrml:
 
3891
    #    zrot_vrml=zrot_vrml
 
3892
    #    #say("rotz:"+rotz+"\r\n")
 
3893
    #    ##rotz=rotz[5:]
 
3894
    #    #say("rotz:"+rotz+"\r\n")
 
3895
    #    ##temp=rotz.split(" ")
 
3896
    #    #say("rotz temp:"+temp[2]+"\r\n")
 
3897
    #    ##rotz=temp[2]
 
3898
    #    #say("rotate vrml: "+rotz+"\r\n")
 
3899
    if zrot_vrml=='':
 
3900
        zrot_vrml=0.0
 
3901
    else:
 
3902
        zrot_vrml=float(zrot_vrml)
 
3903
    rot=zrot_vrml  #adding vrml module z-rotation
 
3904
    #say(rot_wrl);say('\n')
 
3905
    return wrl_pos, scale_vrml, rot_wrl
 
3906
 
1486
3907
def getwrlRot(source):
1487
3908
    model = ''.join(source)
1488
3909
    if re.search(r'\(rotate\s+(.+?)\)', model, re.MULTILINE|re.DOTALL) is not None:
1489
3910
        rotz_vrml = re.search(r'\(rotate\s+(.+?)\)', model, re.MULTILINE|re.DOTALL).groups(0)[0]
1490
3911
    else:
1491
3912
        rotz_vrml=False
1492
 
    FreeCAD.Console.PrintMessage("hereA")
 
3913
    #say("hereA")
1493
3914
    rotz=''
1494
3915
    if rotz_vrml:
1495
3916
        rotz=rotz_vrml
1496
 
        #FreeCAD.Console.PrintMessage("rotz:"+rotz+"\r\n")
 
3917
        #say("rotz:"+rotz+"\r\n")
1497
3918
        rotz=rotz[5:]
1498
 
        #FreeCAD.Console.PrintMessage("rotz:"+rotz+"\r\n")
 
3919
        #say("rotz:"+rotz+"\r\n")
1499
3920
        temp=rotz.split(" ")
1500
 
        #FreeCAD.Console.PrintMessage("rotz temp:"+temp[2]+"\r\n")
 
3921
        #say("rotz temp:"+temp[2]+"\r\n")
1501
3922
        rotz=temp[2]
1502
 
        #FreeCAD.Console.PrintMessage("rotate vrml: "+rotz+"\r\n")
 
3923
        #say("rotate vrml: "+rotz+"\r\n")
1503
3924
    if rotz=='':
1504
3925
        rotz=0.0
1505
3926
    else:
1513
3934
    #
1514
3935
    model = ''.join(content)
1515
3936
    #model_name = re.search(r'\(module\s+(.+?)\(layer', model, re.MULTILINE|re.DOTALL).groups(0)[0]
1516
 
    #App.Console.PrintMessage(model_name+'\r\n')
 
3937
    #say(model_name+'\r\n')
1517
3938
 
1518
3939
    found = re.findall(r'\(pad .* ', model, re.MULTILINE|re.DOTALL)
1519
3940
    if len(found):
1577
3998
                    else:
1578
3999
                        yOF = float(data[5])
1579
4000
                ##
1580
 
                #App.Console.PrintMessage(data)
 
4001
                #say(data)
1581
4002
                pads.append({'x': x, 'y': y, 'rot': rot, 'padType': pType, 'padShape': pShape, 'rx': drill_x, 'ry': drill_y, 'dx': dx, 'dy': dy, 'holeType': hType, 'xOF': xOF, 'yOF': yOF, 'layers': layers})
1582
4003
 
1583
 
    #App.Console.PrintMessage(pads)
 
4004
    #say(pads)
1584
4005
    #
1585
4006
    return pads
1586
4007
###
1747
4168
    return createCircle(x, y, r, w)
1748
4169
###
1749
4170
def createLine(x1, y1, x2, y2, width=0.01):
1750
 
    #App.Console.PrintMessage("create line routine \r\n")
 
4171
    #say("create line routine \r\n")
1751
4172
    z_silk_offset=0.01
1752
4173
    if width <= 0:
1753
4174
        width = 0.01
1911
4332
        z_off=0
1912
4333
 
1913
4334
        hole = addPadLong(holep[0], holep[1], holed[0], holed[1], 100, 0, z_off)
1914
 
        #hole = Part.Face(hole)
1915
 
        App.Console.PrintMessage("herex1\r\n")
1916
 
 
1917
 
        #hole = Part.Wire(hole)
1918
 
        #hole = Part.Face(hole)
1919
 
        #myhole=hole.copy()
1920
 
        #App.ActiveDocument.addObject('Part::Feature','mynewhole').Shape=App.ActiveDocument.hole.Shape.removeSplitter()
1921
 
        ##App.Console.PrintMessage(str(holep[0])+"-"+str(holep[1])+" px,py\r\n")
1922
 
        ##App.Console.PrintMessage(str(holed[0])+"-"+str(holed[1])+" drx,dry\r\n")
1923
 
        #Part.show(mainObj)
1924
 
        #App.ActiveDocument.ActiveObject.Label="test_main"
1925
 
        #App.Console.PrintMessage(mainObj.Label)
1926
 
        #Part.show(hole)
1927
 
        #list=[]
1928
 
        #list.append(hole)
1929
 
        #hole1=Part.makeCompound(list)
1930
 
        #Part.makeCompound(mainObj)
1931
 
        #App.ActiveDocument.ActiveObject.Label="test_hole"
1932
 
 
1933
 
        #sleep
1934
4335
        mainObj = mainObj.cut(hole)
1935
4336
        Part.show(mainObj)
1936
 
 
1937
4337
    return mainObj
1938
4338
###
1939
4339
###
1953
4353
    else:
1954
4354
        thick=0.01
1955
4355
        z_offset=-1.6
1956
 
    App.Console.PrintMessage(str(x)+"x "+str(y)+"y "+str(sx)+"sx "+str(sy)+"sy "+"\r\n")
1957
 
    App.Console.PrintMessage(str(dcx)+"dcx "+str(dcy)+"dcy "+str(dx)+"dx "+str(dy)+"dy "+"\r\n")
 
4356
    #say(str(x)+"x "+str(y)+"y "+str(sx)+"sx "+str(sy)+"sy "+"\r\n")
 
4357
    #say(str(dcx)+"dcx "+str(dcy)+"dcy "+str(dx)+"dx "+str(dy)+"dy "+"\r\n")
1958
4358
    mypad=addPadLong2(x, y, sx, sy, perc, tp, z_offset)
1959
4359
    Part.show(mypad)
1960
 
    App.ActiveDocument.ActiveObject.Label="mypad"
1961
 
    pad_name=App.ActiveDocument.ActiveObject.Name
1962
 
    #FreeCAD.ActiveDocument.addObject("Part::Extrusion","Extrude_pad")
1963
 
    #extrude_name=App.ActiveDocument.ActiveObject.Name
1964
 
    #FreeCAD.ActiveDocument.Extrude_pad.Base = FreeCAD.ActiveDocument.getObject(pad_name)
1965
 
    #FreeCAD.ActiveDocument.Extrude_pad.Dir = (0,0,thick)
1966
 
    #FreeCAD.ActiveDocument.Extrude_pad.Solid = (True)
1967
 
    #FreeCAD.ActiveDocument.Extrude_pad.TaperAngle = (0)
1968
 
    #Gui.ActiveDocument.getObject(pad_name).Visibility = False
1969
 
    #FreeCAD.ActiveDocument.Extrude_pad.Label = 'mypad_solid'
1970
 
    #extrude_pad_name=App.ActiveDocument.ActiveObject.Name
1971
 
    #App.ActiveDocument.recompute()
 
4360
    FreeCAD.ActiveDocument.ActiveObject.Label="mypad"
 
4361
    pad_name=FreeCAD.ActiveDocument.ActiveObject.Name
1972
4362
    if dx!=0:
1973
4363
        perc=100 #drill always oval
1974
4364
        tp=0
1975
4365
        mydrill=addPadLong2(dcx, dcy, dx, dy, perc, tp, 0)
1976
4366
        Part.show(mydrill)
1977
 
        App.ActiveDocument.ActiveObject.Label="mydrill"
1978
 
        drill_name=App.ActiveDocument.ActiveObject.Name
 
4367
        FreeCAD.ActiveDocument.ActiveObject.Label="mydrill"
 
4368
        drill_name=FreeCAD.ActiveDocument.ActiveObject.Name
1979
4369
        myannular=addPadLong2(dcx, dcy, dx+0.01, dy+0.01, perc, tp, 0)
1980
4370
        Part.show(myannular)
1981
 
        App.ActiveDocument.ActiveObject.Label="myannular"
1982
 
        ann_name=App.ActiveDocument.ActiveObject.Name
 
4371
        FreeCAD.ActiveDocument.ActiveObject.Label="myannular"
 
4372
        ann_name=FreeCAD.ActiveDocument.ActiveObject.Name
1983
4373
        #myhole=addPadLong2(dcx, dcy, dx, dy, perc, tp, z_offset)
1984
4374
        #Part.show(myhole)
1985
 
        #App.ActiveDocument.ActiveObject.Label="myhole"
 
4375
        #FreeCAD.ActiveDocument.ActiveObject.Label="myhole"
1986
4376
        wire = [mypad,mydrill]
1987
4377
        wire2 = [myannular,mydrill]
1988
4378
        face = Part.Face(wire)
1990
4380
        face3 = Part.Face(wire2)
1991
4381
        extr = face.extrude(FreeCAD.Vector(0,0,-.01))
1992
4382
        Part.show(extr)
1993
 
        App.ActiveDocument.ActiveObject.Label="drilled_pad"
 
4383
        FreeCAD.ActiveDocument.ActiveObject.Label="drilled_pad"
1994
4384
        extr2 = face2.extrude(FreeCAD.Vector(0,0,-1.58))
1995
4385
        Part.show(extr2)
1996
 
        App.ActiveDocument.ActiveObject.Label="hole"
 
4386
        FreeCAD.ActiveDocument.ActiveObject.Label="hole"
1997
4387
        extr3 = face3.extrude(FreeCAD.Vector(0,0,-1.58))
1998
4388
        Part.show(extr3)
1999
 
        App.ActiveDocument.ActiveObject.Label="annular"
2000
 
        App.ActiveDocument.removeObject(pad_name)
2001
 
        App.ActiveDocument.removeObject(drill_name)
2002
 
        App.ActiveDocument.removeObject(ann_name)
2003
 
 
2004
 
        #Part.show(obj)
2005
 
        #drill_name=App.ActiveDocument.ActiveObject.Name
2006
 
 
2007
 
        #FreeCAD.ActiveDocument.addObject("Part::Extrusion","Extrude_d")
2008
 
        #extrude_d_name=App.ActiveDocument.ActiveObject.Name
2009
 
        #FreeCAD.ActiveDocument.Extrude_d.Base = FreeCAD.ActiveDocument.getObject(drill_name)
2010
 
        #FreeCAD.ActiveDocument.Extrude_d.Dir = (0,0,thick)
2011
 
        #FreeCAD.ActiveDocument.Extrude_d.Solid = (True)
2012
 
        #FreeCAD.ActiveDocument.Extrude_d.TaperAngle = (0)
2013
 
        #Gui.ActiveDocument.getObject(drill_name).Visibility = False
2014
 
        #FreeCAD.ActiveDocument.Extrude_d.Label = 'mydrill_solid'
2015
 
        #extrude_drill_name=App.ActiveDocument.ActiveObject.Name
2016
 
        #App.ActiveDocument.recompute()
2017
 
 
2018
 
        #App.activeDocument().addObject("Part::Cut","myCut")
2019
 
        #cut_name=App.ActiveDocument.ActiveObject.Name
2020
 
        #App.activeDocument().getObject(cut_name).Base = App.activeDocument().Extrude_pad
2021
 
        #App.activeDocument().getObject(cut_name).Tool = App.activeDocument().Extrude_d
2022
 
        #Gui.activeDocument().Extrude_pad.Visibility=False
2023
 
        #Gui.activeDocument().Extrude_d.Visibility=False
2024
 
        ##Gui.ActiveDocument.getObject(cut_name).ShapeColor=Gui.ActiveDocument.Extrude.ShapeColor
2025
 
        #FreeCADGui.ActiveDocument.ActiveObject.ShapeColor =  (0.81,0.71,0.23) #(0.85,0.53,0.10)
2026
 
        #Gui.ActiveDocument.ActiveObject.DisplayMode=Gui.ActiveDocument.Extrude_pad.DisplayMode
2027
 
        #App.ActiveDocument.recompute()
2028
 
        #pad_d_name="TH_Pad"
2029
 
        #App.ActiveDocument.addObject('Part::Feature',pad_d_name).Shape=App.ActiveDocument.ActiveObject.Shape
2030
 
        #FreeCADGui.ActiveDocument.ActiveObject.ShapeColor =  (0.81,0.71,0.23) #(0.85,0.53,0.10)
2031
 
        #myObj=FreeCAD.ActiveDocument.getObject(pad_d_name)
2032
 
        #if remove==1:
2033
 
        #    App.ActiveDocument.removeObject(cut_name)
2034
 
        #    App.ActiveDocument.removeObject(extrude_pad_name)
2035
 
        #    App.ActiveDocument.removeObject(pad_name)
2036
 
        #    App.ActiveDocument.removeObject(drill_name)
2037
 
        #    App.ActiveDocument.removeObject(extrude_drill_name)
2038
 
        App.ActiveDocument.recompute()
 
4389
        FreeCAD.ActiveDocument.ActiveObject.Label="annular"
 
4390
        FreeCAD.ActiveDocument.removeObject(pad_name)
 
4391
        FreeCAD.ActiveDocument.removeObject(drill_name)
 
4392
        FreeCAD.ActiveDocument.removeObject(ann_name)
 
4393
        FreeCAD.ActiveDocument.recompute()
2039
4394
    else:
2040
4395
        face = Part.Face(mypad)
2041
4396
        extr = face.extrude(FreeCAD.Vector(0,0,-.01))
2042
4397
        Part.show(extr)
2043
 
        App.ActiveDocument.ActiveObject.Label="smd_pad"
2044
 
        App.ActiveDocument.removeObject(pad_name)
2045
 
        #App.ActiveDocument.addObject('Part::Feature',pad_d_name).Shape=App.ActiveDocument.ActiveObject.Shape
2046
 
        #myObj=FreeCAD.ActiveDocument.getObject(pad_d_name)
2047
 
        #FreeCADGui.ActiveDocument.ActiveObject.ShapeColor =  (0.81,0.71,0.23) #(0.85,0.53,0.10)
2048
 
        ##App.ActiveDocument.removeObject(extrude_pad_name)
2049
 
        ##App.ActiveDocument.removeObject(pad_name)
2050
 
        App.ActiveDocument.recompute()
 
4398
        FreeCAD.ActiveDocument.ActiveObject.Label="smd_pad"
 
4399
        FreeCAD.ActiveDocument.removeObject(pad_name)
 
4400
        FreeCAD.ActiveDocument.recompute()
2051
4401
    return extr
2052
4402
###
2053
4403
def createPad3(x,y,sx,sy,dcx,dcy,dx,dy,type,layer):
2066
4416
    else:
2067
4417
        thick=0.01
2068
4418
        z_offset=-1.6
2069
 
    App.Console.PrintMessage(str(x)+"x "+str(y)+"y "+str(sx)+"sx "+str(sy)+"sy "+"\r\n")
2070
 
    App.Console.PrintMessage(str(dcx)+"dcx "+str(dcy)+"dcy "+str(dx)+"dx "+str(dy)+"dy "+"\r\n")
 
4419
    #say(str(x)+"x "+str(y)+"y "+str(sx)+"sx "+str(sy)+"sy "+"\r\n")
 
4420
    #say(str(dcx)+"dcx "+str(dcy)+"dcy "+str(dx)+"dx "+str(dy)+"dy "+"\r\n")
2071
4421
    mypad=addPadLong2(x, y, sx, sy, perc, tp, z_offset)
2072
4422
    Part.show(mypad)
2073
 
    App.ActiveDocument.ActiveObject.Label="mypad"
2074
 
    pad_name=App.ActiveDocument.ActiveObject.Name
 
4423
    FreeCAD.ActiveDocument.ActiveObject.Label="mypad"
 
4424
    pad_name=FreeCAD.ActiveDocument.ActiveObject.Name
2075
4425
    if dx!=0:
2076
4426
        perc=100 #drill always oval
2077
4427
        tp=0
2078
4428
        mydrill=addPadLong2(dcx, dcy, dx, dy, perc, tp, z_offset)
2079
 
        if test_flag==True:
 
4429
        if test_flag_pads==True:
2080
4430
            Part.show(mydrill)
2081
 
            App.ActiveDocument.ActiveObject.Label="mydrill"
2082
 
            drill_name=App.ActiveDocument.ActiveObject.Name
 
4431
            FreeCAD.ActiveDocument.ActiveObject.Label="mydrill"
 
4432
            drill_name=FreeCAD.ActiveDocument.ActiveObject.Name
2083
4433
        myannular=addPadLong2(dcx, dcy, dx+0.01, dy+0.01, perc, tp, z_offset)
2084
 
        if test_flag==True:
 
4434
        if test_flag_pads==True:
2085
4435
            Part.show(myannular)
2086
 
            App.ActiveDocument.ActiveObject.Label="myannular"
2087
 
            ann_name=App.ActiveDocument.ActiveObject.Name
 
4436
            FreeCAD.ActiveDocument.ActiveObject.Label="myannular"
 
4437
            ann_name=FreeCAD.ActiveDocument.ActiveObject.Name
2088
4438
        myhole=addPadLong2(dcx, dcy, dx, dy, perc, tp, z_offset)
2089
 
        if test_flag==True:
 
4439
        if test_flag_pads==True:
2090
4440
            Part.show(myhole)
2091
 
            App.ActiveDocument.ActiveObject.Label="myhole"
 
4441
            FreeCAD.ActiveDocument.ActiveObject.Label="myhole"
2092
4442
        wire = [mypad,mydrill]
2093
4443
        face = Part.Face(wire)
2094
4444
        extr = face.extrude(FreeCAD.Vector(0,0,thick))
2095
 
        if test_flag==True:
 
4445
        if test_flag_pads==True:
2096
4446
            Part.show(extr)
2097
 
            App.ActiveDocument.ActiveObject.Label="drilled_pad"
2098
 
        App.ActiveDocument.removeObject(pad_name)
2099
 
        App.ActiveDocument.recompute()
 
4447
            FreeCAD.ActiveDocument.ActiveObject.Label="drilled_pad"
 
4448
        FreeCAD.ActiveDocument.removeObject(pad_name)
 
4449
        FreeCAD.ActiveDocument.recompute()
2100
4450
    else:
2101
4451
        face = Part.Face(mypad)
2102
4452
        extr = face.extrude(FreeCAD.Vector(0,0,thick))
2103
4453
        #Part.show(extr)
2104
 
        #App.ActiveDocument.ActiveObject.Label="smd_pad"
2105
 
        App.ActiveDocument.removeObject(pad_name)
2106
 
        App.ActiveDocument.recompute()
 
4454
        #FreeCAD.ActiveDocument.ActiveObject.Label="smd_pad"
 
4455
        FreeCAD.ActiveDocument.removeObject(pad_name)
 
4456
        FreeCAD.ActiveDocument.recompute()
2107
4457
    return extr
2108
4458
###
2109
4459
def createPad(x,y,sx,sy,dcx,dcy,dx,dy,type,layer):
2122
4472
    else:
2123
4473
        thick=0.01
2124
4474
        z_offset=-1.6
2125
 
    App.Console.PrintMessage(str(x)+"x "+str(y)+"y "+str(sx)+"sx "+str(sy)+"sy "+"\r\n")
2126
 
    App.Console.PrintMessage(str(dcx)+"dcx "+str(dcy)+"dcy "+str(dx)+"dx "+str(dy)+"dy "+"\r\n")
 
4475
    #say(str(x)+"x "+str(y)+"y "+str(sx)+"sx "+str(sy)+"sy "+"\r\n")
 
4476
    #say(str(dcx)+"dcx "+str(dcy)+"dcy "+str(dx)+"dx "+str(dy)+"dy "+"\r\n")
2127
4477
    mypad=addPadLong(x, y, sx, sy, perc, tp, z_offset)
2128
4478
    Part.show(mypad)
2129
 
    App.ActiveDocument.ActiveObject.Label="mypad"
2130
 
    pad_name=App.ActiveDocument.ActiveObject.Name
 
4479
    FreeCAD.ActiveDocument.ActiveObject.Label="mypad"
 
4480
    pad_name=FreeCAD.ActiveDocument.ActiveObject.Name
2131
4481
    FreeCAD.ActiveDocument.addObject("Part::Extrusion","Extrude_pad")
2132
 
    extrude_name=App.ActiveDocument.ActiveObject.Name
 
4482
    extrude_name=FreeCAD.ActiveDocument.ActiveObject.Name
2133
4483
    FreeCAD.ActiveDocument.Extrude_pad.Base = FreeCAD.ActiveDocument.getObject(pad_name)
2134
4484
    FreeCAD.ActiveDocument.Extrude_pad.Dir = (0,0,thick)
2135
4485
    FreeCAD.ActiveDocument.Extrude_pad.Solid = (True)
2136
4486
    FreeCAD.ActiveDocument.Extrude_pad.TaperAngle = (0)
2137
 
    Gui.ActiveDocument.getObject(pad_name).Visibility = False
 
4487
    FreeCADGui.ActiveDocument.getObject(pad_name).Visibility = False
2138
4488
    FreeCAD.ActiveDocument.Extrude_pad.Label = 'mypad_solid'
2139
 
    extrude_pad_name=App.ActiveDocument.ActiveObject.Name
2140
 
    #App.ActiveDocument.recompute()
 
4489
    extrude_pad_name=FreeCAD.ActiveDocument.ActiveObject.Name
 
4490
    #FreeCAD.ActiveDocument.recompute()
2141
4491
    if dx!=0:
2142
4492
        perc=100 #drill always oval
2143
4493
        mydrill=addPadLong(dcx, dcy, dx, dy, perc, tp, z_offset)
2144
4494
        Part.show(mydrill)
2145
 
        App.ActiveDocument.ActiveObject.Label="mydrill"
2146
 
        drill_name=App.ActiveDocument.ActiveObject.Name
 
4495
        FreeCAD.ActiveDocument.ActiveObject.Label="mydrill"
 
4496
        drill_name=FreeCAD.ActiveDocument.ActiveObject.Name
2147
4497
        FreeCAD.ActiveDocument.addObject("Part::Extrusion","Extrude_d")
2148
 
        extrude_d_name=App.ActiveDocument.ActiveObject.Name
 
4498
        extrude_d_name=FreeCAD.ActiveDocument.ActiveObject.Name
2149
4499
        FreeCAD.ActiveDocument.Extrude_d.Base = FreeCAD.ActiveDocument.getObject(drill_name)
2150
4500
        FreeCAD.ActiveDocument.Extrude_d.Dir = (0,0,thick)
2151
4501
        FreeCAD.ActiveDocument.Extrude_d.Solid = (True)
2152
4502
        FreeCAD.ActiveDocument.Extrude_d.TaperAngle = (0)
2153
 
        Gui.ActiveDocument.getObject(drill_name).Visibility = False
 
4503
        FreeCADGui.ActiveDocument.getObject(drill_name).Visibility = False
2154
4504
        FreeCAD.ActiveDocument.Extrude_d.Label = 'mydrill_solid'
2155
 
        extrude_drill_name=App.ActiveDocument.ActiveObject.Name
2156
 
        #App.ActiveDocument.recompute()
 
4505
        extrude_drill_name=FreeCAD.ActiveDocument.ActiveObject.Name
 
4506
        #FreeCAD.ActiveDocument.recompute()
2157
4507
 
2158
 
        App.activeDocument().addObject("Part::Cut","myCut")
2159
 
        cut_name=App.ActiveDocument.ActiveObject.Name
2160
 
        App.activeDocument().getObject(cut_name).Base = App.activeDocument().Extrude_pad
2161
 
        App.activeDocument().getObject(cut_name).Tool = App.activeDocument().Extrude_d
2162
 
        Gui.activeDocument().Extrude_pad.Visibility=False
2163
 
        Gui.activeDocument().Extrude_d.Visibility=False
2164
 
        #Gui.ActiveDocument.getObject(cut_name).ShapeColor=Gui.ActiveDocument.Extrude.ShapeColor
 
4508
        FreeCAD.activeDocument().addObject("Part::Cut","myCut")
 
4509
        cut_name=FreeCAD.ActiveDocument.ActiveObject.Name
 
4510
        FreeCAD.activeDocument().getObject(cut_name).Base = FreeCAD.activeDocument().Extrude_pad
 
4511
        FreeCAD.activeDocument().getObject(cut_name).Tool = FreeCAD.activeDocument().Extrude_d
 
4512
        FreeCADGui.activeDocument().Extrude_pad.Visibility=False
 
4513
        FreeCADGui.activeDocument().Extrude_d.Visibility=False
 
4514
        #FreeCADGui.ActiveDocument.getObject(cut_name).ShapeColor=FreeCADGui.ActiveDocument.Extrude.ShapeColor
2165
4515
        FreeCADGui.ActiveDocument.ActiveObject.ShapeColor =  (0.81,0.71,0.23) #(0.85,0.53,0.10)
2166
 
        Gui.ActiveDocument.ActiveObject.DisplayMode=Gui.ActiveDocument.Extrude_pad.DisplayMode
2167
 
        App.ActiveDocument.recompute()
 
4516
        FreeCADGui.ActiveDocument.ActiveObject.DisplayMode=FreeCADGui.ActiveDocument.Extrude_pad.DisplayMode
 
4517
        FreeCAD.ActiveDocument.recompute()
2168
4518
        pad_d_name="TH_Pad"
2169
 
        App.ActiveDocument.addObject('Part::Feature',pad_d_name).Shape=App.ActiveDocument.ActiveObject.Shape
 
4519
        FreeCAD.ActiveDocument.addObject('Part::Feature',pad_d_name).Shape=FreeCAD.ActiveDocument.ActiveObject.Shape
2170
4520
        FreeCADGui.ActiveDocument.ActiveObject.ShapeColor =  (0.81,0.71,0.23) #(0.85,0.53,0.10)
2171
4521
        myObj=FreeCAD.ActiveDocument.getObject(pad_d_name)
2172
4522
        if remove==1:
2173
 
            App.ActiveDocument.removeObject(cut_name)
2174
 
            App.ActiveDocument.removeObject(extrude_pad_name)
2175
 
            App.ActiveDocument.removeObject(pad_name)
2176
 
            App.ActiveDocument.removeObject(drill_name)
2177
 
            App.ActiveDocument.removeObject(extrude_drill_name)
2178
 
        App.ActiveDocument.recompute()
 
4523
            FreeCAD.ActiveDocument.removeObject(cut_name)
 
4524
            FreeCAD.ActiveDocument.removeObject(extrude_pad_name)
 
4525
            FreeCAD.ActiveDocument.removeObject(pad_name)
 
4526
            FreeCAD.ActiveDocument.removeObject(drill_name)
 
4527
            FreeCAD.ActiveDocument.removeObject(extrude_drill_name)
 
4528
        FreeCAD.ActiveDocument.recompute()
2179
4529
    else:
2180
 
        App.ActiveDocument.recompute()
 
4530
        FreeCAD.ActiveDocument.recompute()
2181
4531
        pad_d_name="smdPad"
2182
 
        App.ActiveDocument.addObject('Part::Feature',pad_d_name).Shape=App.ActiveDocument.ActiveObject.Shape
 
4532
        FreeCAD.ActiveDocument.addObject('Part::Feature',pad_d_name).Shape=FreeCAD.ActiveDocument.ActiveObject.Shape
2183
4533
        myObj=FreeCAD.ActiveDocument.getObject(pad_d_name)
2184
4534
        FreeCADGui.ActiveDocument.ActiveObject.ShapeColor =  (0.81,0.71,0.23) #(0.85,0.53,0.10)
2185
 
        App.ActiveDocument.removeObject(extrude_pad_name)
2186
 
        App.ActiveDocument.removeObject(pad_name)
2187
 
        App.ActiveDocument.recompute()
 
4535
        FreeCAD.ActiveDocument.removeObject(extrude_pad_name)
 
4536
        FreeCAD.ActiveDocument.removeObject(pad_name)
 
4537
        FreeCAD.ActiveDocument.recompute()
2188
4538
    return myObj
2189
4539
###
2190
4540
 
2197
4547
        tp=0
2198
4548
    mydrill=addPadLong(x, y, dx, dy, perc, tp, 0)
2199
4549
    Part.show(mydrill)
2200
 
    App.ActiveDocument.ActiveObject.Label="mydrill"
2201
 
    drill_name=App.ActiveDocument.ActiveObject.Name
 
4550
    FreeCAD.ActiveDocument.ActiveObject.Label="mydrill"
 
4551
    drill_name=FreeCAD.ActiveDocument.ActiveObject.Name
2202
4552
    FreeCAD.ActiveDocument.addObject("Part::Extrusion","Extrude_d")
2203
4553
    FreeCAD.ActiveDocument.Extrude_d.Base = FreeCAD.ActiveDocument.getObject(drill_name)
2204
4554
    FreeCAD.ActiveDocument.Extrude_d.Dir = (0,0,-1.6)
2205
4555
    FreeCAD.ActiveDocument.Extrude_d.Solid = (True)
2206
4556
    FreeCAD.ActiveDocument.Extrude_d.TaperAngle = (0)
2207
 
    Gui.ActiveDocument.getObject(drill_name).Visibility = False
 
4557
    FreeCADGui.ActiveDocument.getObject(drill_name).Visibility = False
2208
4558
    FreeCAD.ActiveDocument.Extrude_d.Label = 'mydrill_hole'
2209
 
    extrude_hole_name=App.ActiveDocument.ActiveObject.Name
2210
 
    App.ActiveDocument.recompute()
 
4559
    extrude_hole_name=FreeCAD.ActiveDocument.ActiveObject.Name
 
4560
    FreeCAD.ActiveDocument.recompute()
2211
4561
 
2212
4562
    hole_name="hole"
2213
 
    App.ActiveDocument.addObject('Part::Feature',hole_name).Shape=App.ActiveDocument.getObject(extrude_hole_name).Shape
 
4563
    FreeCAD.ActiveDocument.addObject('Part::Feature',hole_name).Shape=FreeCAD.ActiveDocument.getObject(extrude_hole_name).Shape
2214
4564
    FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (0.67,1.00,0.50)
2215
4565
    FreeCADGui.ActiveDocument.ActiveObject.Transparency = 70
2216
4566
    myObj=FreeCADGui.ActiveDocument.ActiveObject
2217
 
    App.ActiveDocument.removeObject(drill_name)
2218
 
    App.ActiveDocument.removeObject(extrude_hole_name)
2219
 
    App.ActiveDocument.recompute()
 
4567
    FreeCAD.ActiveDocument.removeObject(drill_name)
 
4568
    FreeCAD.ActiveDocument.removeObject(extrude_hole_name)
 
4569
    FreeCAD.ActiveDocument.recompute()
2220
4570
 
2221
4571
    return myObj
2222
4572
 
2236
4586
    holeModel=[]
2237
4587
    holeModel.append(hole)
2238
4588
    holeModel = Part.makeCompound(holeModel)
2239
 
    #App.Console.PrintMessage("hereHole")
2240
 
    #App.ActiveDocument.recompute()
2241
 
 
 
4589
    #say("hereHole")
 
4590
    #FreeCAD.ActiveDocument.recompute()
 
4591
    return holeModel
 
4592
 
 
4593
###
 
4594
def createHole3(x,y,dx,dy,type,height):
 
4595
    if type=="oval":
 
4596
        perc=100
 
4597
        tp=0
 
4598
    else:
 
4599
        perc=0
 
4600
        tp=0
 
4601
    #mydrill=addPadLong(x, y, dx, dy, perc, tp, -0.01)
 
4602
    mydrill=addPadLong(x, y, dx, dy, perc, tp, 0.1)
 
4603
    #Part.show(mydrill)
 
4604
    #hole = mydrill.extrude(FreeCAD.Base.Vector(0, 0, -1.58))
 
4605
    hole = mydrill.extrude(FreeCAD.Base.Vector(0, 0, -(height+0.2)))
 
4606
    holeModel=[]
 
4607
    holeModel.append(hole)
 
4608
    holeModel = Part.makeCompound(holeModel)
 
4609
    #say("hereHole")
 
4610
    #FreeCAD.ActiveDocument.recompute()
 
4611
 
 
4612
    return holeModel
 
4613
 
 
4614
###
 
4615
###
 
4616
def createHole4(x,y,dx,dy,type):
 
4617
    if type=="oval":
 
4618
        perc=100
 
4619
        tp=0
 
4620
    else:
 
4621
        perc=0
 
4622
        tp=0
 
4623
    #mydrill=addPadLong(x, y, dx, dy, perc, tp, -0.01)
 
4624
    #mydrill=addPadLong(x, y, dx, dy, perc, tp, .01)
 
4625
    mydrill=addPadLong2(x, y, dx, dy, perc, tp, 0)
 
4626
    holeModel=[]
 
4627
    #holeModel.append(hole)
 
4628
    holeModel.append(mydrill)
 
4629
    ##holeModel = Part.makeCompound(holeModel)
 
4630
    holeModel = Part.Face(holeModel)
 
4631
    #say("hereHole")
 
4632
    #FreeCAD.ActiveDocument.recompute()
2242
4633
    return holeModel
2243
4634
 
2244
4635
###
2256
4647
    face3 = Part.Face(wire2)
2257
4648
    THP = face3.extrude(FreeCAD.Vector(0,0,-1.58))
2258
4649
    #Part.show(extr3)
2259
 
    #App.ActiveDocument.ActiveObject.Label="annular"
 
4650
    #FreeCAD.ActiveDocument.ActiveObject.Label="annular"
2260
4651
    ##hole = mydrill.extrude(FreeCAD.Base.Vector(0, 0, -1.58))
2261
4652
    #THP = myannular.extrude(FreeCAD.Base.Vector(0, 0, -1.58))
2262
4653
    THPModel=[]
2263
4654
    THPModel.append(THP)
2264
4655
    THPModel = Part.makeCompound(THPModel)
2265
 
    #App.Console.PrintMessage("hereHole")
2266
 
    #App.ActiveDocument.recompute()
 
4656
    #say("hereHole")
 
4657
    #FreeCAD.ActiveDocument.recompute()
2267
4658
 
2268
4659
    return THPModel
2269
4660
 
2271
4662
def routineDrawFootPrint(content,name):
2272
4663
    global rot_wrl
2273
4664
    #for item in content:
2274
 
    #    App.Console.PrintMessage(item)
 
4665
    #    say(item)
2275
4666
 
2276
4667
    #                      x1, y1, x2, y2, width
2277
 
    App.Console.PrintMessage("FootPrint Loader "+name+"\r\n")
 
4668
    say("FootPrint Loader "+name+"\n")
2278
4669
    footprint_name=getModName(content)
2279
4670
    rot_wrl=getwrlRot(content)
2280
 
    App.Console.PrintMessage(footprint_name+" wrl rotation:"+str(rot_wrl)+"\r\n")
2281
 
    if App.activeDocument():
2282
 
        doc=App.activeDocument()
 
4671
    posiz, scale, rot = getwrlData(content)
 
4672
    #say(posiz);say(scale);say(rot);say('\n')
 
4673
    error_mod=False
 
4674
    if scale!=['1', '1', '1']:
 
4675
        sayw('wrong scale!!! set scale to (1 1 1)\n')
 
4676
        error_mod=True
 
4677
    if posiz!=['0', '0', '0']:
 
4678
        sayw('wrong xyx position!!! set xyz to (0 0 0)\n')
 
4679
        error_mod=True
 
4680
    if rot[0]!='0' or rot[1]!='0':
 
4681
        sayw('wrong rotation!!! set rotate x and y to (0 0 z)\n')
 
4682
        error_mod=True
 
4683
    if error_mod:
 
4684
        msg="""<b>Error in '.kicad_mod' footprint</b><br>"""
 
4685
        msg+="<br>reset values to:<br>"
 
4686
        msg+="<b>(at (xyz 0 0 0))<br>"
 
4687
        msg+="(scale (xyz 1 1 1))<br>"
 
4688
        msg+="(rotate (xyz 0 0 z))<br>"
 
4689
        msg+="</b><br>Only z rotation is allowed!"
 
4690
        reply = QtGui.QMessageBox.information(None,"info", msg)
 
4691
        #stop
 
4692
    #say(footprint_name+" wrl rotation:"+str(rot_wrl)+"\r\n")
 
4693
    if FreeCAD.activeDocument():
 
4694
        doc=FreeCAD.activeDocument()
2283
4695
    else:
2284
 
        doc=App.newDocument()
2285
 
    for obj in App.ActiveDocument.Objects:
2286
 
        Gui.Selection.removeSelection(obj)
 
4696
        doc=FreeCAD.newDocument()
 
4697
    for obj in FreeCAD.ActiveDocument.Objects:
 
4698
        FreeCADGui.Selection.removeSelection(obj)
2287
4699
 
2288
4700
    TopPadList=[]
2289
4701
    BotPadList=[]
2290
4702
    HoleList=[]
2291
4703
    THPList=[]
2292
4704
    for pad in getPadsList(content):
2293
 
        #App.Console.PrintMessage(pad)
2294
 
        #App.Console.PrintMessage("\r\n")
 
4705
        #say(pad)
 
4706
        #say("\r\n")
2295
4707
        #   pads.append({'x': x, 'y': y, 'rot': rot, 'padType': pType, 'padShape': pShape, 'rx': drill_x, 'ry': drill_y, 'dx': dx, 'dy': dy, 'holeType': hType, 'xOF': xOF, 'yOF': yOF, 'layers': layers})
2296
4708
        pType = pad['padType']
2297
4709
        pShape = pad['padShape']
2308
4720
        rx=drill_x
2309
4721
        ry=drill_y
2310
4722
        numberOfLayers = pad['layers'].split(' ')
2311
 
        #App.Console.PrintMessage(str(rx)+"\r\n")
2312
 
        App.Console.PrintMessage(numberOfLayers)
 
4723
        #say(str(rx)+"\r\n")
 
4724
        #say(numberOfLayers)
2313
4725
        #if pType=="thru_hole":
2314
4726
        #pad shape - circle/rec/oval/trapezoid
2315
4727
        perc=0
2317
4729
            pShape="oval"
2318
4730
            perc=100
2319
4731
            # pad type - SMD/thru_hole/connect
2320
 
        #App.Console.PrintMessage(pType+"here\r\n")
 
4732
        #say(pType+"here\r\n")
2321
4733
        if dx>rx and dy>ry:
2322
 
            App.Console.PrintMessage(pType+"\r\n")
2323
 
            App.Console.PrintMessage(str(dx)+"+"+str(rx)+" dx,rx\r\n")
2324
 
            App.Console.PrintMessage(str(dy)+"+"+str(ry)+" dy,ry\r\n")
2325
 
            App.Console.PrintMessage(str(xOF)+"+"+str(yOF)+" xOF,yOF\r\n")
 
4734
            #say(pType+"\r\n")
 
4735
            #say(str(dx)+"+"+str(rx)+" dx,rx\r\n")
 
4736
            #say(str(dy)+"+"+str(ry)+" dy,ry\r\n")
 
4737
            #say(str(xOF)+"+"+str(yOF)+" xOF,yOF\r\n")
2326
4738
            #def addPadLong(x, y, dx, dy, perc, typ, z_off):
2327
4739
            x1=xs+xOF
2328
4740
            y1=ys-yOF #yoffset opposite
2329
 
            App.Console.PrintMessage(str(x1)+"+"+str(y1)+" x1,y1\r\n")
 
4741
            #say(str(x1)+"+"+str(y1)+" x1,y1\r\n")
2330
4742
            top=False
2331
4743
            bot=False
2332
4744
            if 'F.Cu' in numberOfLayers:
2354
4766
                BotPadList.append(obj)
2355
4767
        if rx!=0:
2356
4768
            obj=createHole2(xs,ys,rx,ry,"oval") #need to be separated instructions
2357
 
            #App.Console.PrintMessage(HoleList)
 
4769
            #say(HoleList)
2358
4770
            if rot!=0:
2359
4771
                rotateObj(obj, [xs, ys, rot])
2360
4772
            HoleList.append(obj)
2369
4781
    # line
2370
4782
    #getLine('F.SilkS', content, 'fp_line')
2371
4783
    for i in getLine('F.SilkS', content, 'fp_line'):
2372
 
        #App.Console.PrintMessage("here3\r\n")
 
4784
        #say("here3\r\n")
2373
4785
        x1 = i[0] #+ X1
2374
4786
        y1 = i[1] #+ Y1
2375
4787
        x2 = i[2] #+ X1
2382
4794
 
2383
4795
    # circle
2384
4796
    for i in getCircle('F.SilkS', content, 'fp_circle'):
2385
 
        #App.Console.PrintMessage(i)
 
4797
        #say(i)
2386
4798
        xs = i[0] #+ X1
2387
4799
        ys = i[1] #+ Y1
2388
4800
        FrontSilk.append(addCircle_2(xs, ys, i[2], i[3]))
2400
4812
        #FrontSilk.append(arc2)
2401
4813
        ##shape=arc1.copy()
2402
4814
        ##shape.Placement=arc1.Placement;
2403
 
        #App.Console.PrintMessage(i[4])
2404
 
        #App.Console.PrintMessage(arcMidPoint([x1, y1], [x2, y2],i[4]))
 
4815
        #say(i[4])
 
4816
        #say(arcMidPoint([x1, y1], [x2, y2],i[4]))
2405
4817
        #[xm,ym]=arcMidPoint([x1, y1], [x2, y2],i[4])
2406
4818
        xm=(x1+x2)/2
2407
4819
        ym=(y1+y2)/2
2418
4830
    if len(FrontSilk)>0:
2419
4831
        FSilk_lines = Part.makeCompound(FrontSilk)
2420
4832
        Part.show(FSilk_lines)
2421
 
        App.ActiveDocument.ActiveObject.Label="FrontSilk"
2422
 
        FSilk_name=App.ActiveDocument.ActiveObject.Name
 
4833
        FreeCAD.ActiveDocument.ActiveObject.Label="FrontSilk"
 
4834
        FSilk_name=FreeCAD.ActiveDocument.ActiveObject.Name
2423
4835
        FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (1.0000,1.0000,1.0000)
2424
4836
        FreeCADGui.ActiveDocument.ActiveObject.Transparency = 60
2425
4837
    #
2426
4838
    if len(TopPadList)>0:
2427
4839
        TopPads = Part.makeCompound(TopPadList)
2428
4840
        Part.show(TopPads)
2429
 
        App.ActiveDocument.ActiveObject.Label="TopPads"
2430
 
        TopPads_name=App.ActiveDocument.ActiveObject.Name
 
4841
        FreeCAD.ActiveDocument.ActiveObject.Label="TopPads"
 
4842
        TopPads_name=FreeCAD.ActiveDocument.ActiveObject.Name
2431
4843
        FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (0.81,0.71,0.23) #(0.85,0.53,0.10)
2432
4844
        FreeCADGui.ActiveDocument.ActiveObject.Transparency = 60
2433
4845
    if len(BotPadList)>0:
2434
4846
        BotPads = Part.makeCompound(BotPadList)
2435
4847
        Part.show(BotPads)
2436
 
        App.ActiveDocument.ActiveObject.Label="BotPads"
2437
 
        BotPads_name=App.ActiveDocument.ActiveObject.Name
 
4848
        FreeCAD.ActiveDocument.ActiveObject.Label="BotPads"
 
4849
        BotPads_name=FreeCAD.ActiveDocument.ActiveObject.Name
2438
4850
        FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (0.81,0.71,0.23) #(0.85,0.53,0.10)
2439
4851
        FreeCADGui.ActiveDocument.ActiveObject.Transparency = 60
2440
4852
 
2443
4855
        Holes = Part.makeCompound(HoleList)
2444
4856
        Holes = Part.makeSolid(Holes)
2445
4857
        Part.show(Holes)
2446
 
        #App.Console.PrintMessage(App.ActiveDocument.ActiveObject.Name)
2447
 
        App.ActiveDocument.ActiveObject.Label="Holes"
2448
 
        Holes_name=App.ActiveDocument.ActiveObject.Name
2449
 
        #App.Console.PrintMessage(Holes_name)
 
4858
        #say(FreeCAD.ActiveDocument.ActiveObject.Name)
 
4859
        FreeCAD.ActiveDocument.ActiveObject.Label="Holes"
 
4860
        Holes_name=FreeCAD.ActiveDocument.ActiveObject.Name
 
4861
        #say(Holes_name)
2450
4862
        FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (0.67,1.00,0.50)
2451
4863
        FreeCADGui.ActiveDocument.ActiveObject.Transparency = 70
2452
4864
        THPs = Part.makeCompound(THPList)
2453
4865
        THPs = Part.makeSolid(THPs)
2454
4866
        Part.show(THPs)
2455
 
        #App.Console.PrintMessage(App.ActiveDocument.ActiveObject.Name)
2456
 
        App.ActiveDocument.ActiveObject.Label="PTHs"
2457
 
        THPs_name=App.ActiveDocument.ActiveObject.Name
2458
 
        #App.Console.PrintMessage(Holes_name)
 
4867
        #say(FreeCAD.ActiveDocument.ActiveObject.Name)
 
4868
        FreeCAD.ActiveDocument.ActiveObject.Label="PTHs"
 
4869
        THPs_name=FreeCAD.ActiveDocument.ActiveObject.Name
 
4870
        #say(Holes_name)
2459
4871
        FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (0.67,1.00,0.50)
2460
4872
        FreeCADGui.ActiveDocument.ActiveObject.Transparency = 70
2461
4873
 
2462
4874
    fp_group=FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup", footprint_name+'fp')
2463
 
    App.Console.PrintMessage(fp_group.Name)
 
4875
    say(fp_group.Label+'\n')
2464
4876
    list=[]
2465
4877
    if len(FrontSilk)>0:
2466
 
        obj2 = App.ActiveDocument.getObject(FSilk_name)
 
4878
        obj2 = FreeCAD.ActiveDocument.getObject(FSilk_name)
2467
4879
        list.append(FSilk_name)
2468
4880
        fp_group.addObject(obj2)
2469
4881
 
2470
4882
 
2471
4883
    if len(TopPadList)>0:
2472
 
        obj3 = App.ActiveDocument.getObject(TopPads_name)
 
4884
        obj3 = FreeCAD.ActiveDocument.getObject(TopPads_name)
2473
4885
        fp_group.addObject(obj3)
2474
4886
        list.append(TopPads_name)
2475
4887
    if len(BotPadList)>0:
2476
 
        obj4 = App.ActiveDocument.getObject(BotPads_name)
 
4888
        obj4 = FreeCAD.ActiveDocument.getObject(BotPads_name)
2477
4889
        fp_group.addObject(obj4)
2478
4890
        list.append(BotPads_name)
2479
4891
 
2480
4892
    if len(HoleList)>0:
2481
 
        obj5 = App.ActiveDocument.getObject(Holes_name)
 
4893
        obj5 = FreeCAD.ActiveDocument.getObject(Holes_name)
2482
4894
        fp_group.addObject(obj5)
2483
4895
        list.append(Holes_name)
2484
 
        obj6 = App.ActiveDocument.getObject(THPs_name)
 
4896
        obj6 = FreeCAD.ActiveDocument.getObject(THPs_name)
2485
4897
        fp_group.addObject(obj6)
2486
4898
        list.append(THPs_name)
2487
4899
 
2488
 
 
2489
4900
    #objFp=Part.makeCompound(list)
2490
4901
    #Part.show(objFp)
2491
 
    #App.Console.PrintMessage(list)
 
4902
    #say(list)
2492
4903
    doc=FreeCAD.ActiveDocument
2493
4904
    fp_objs=[]
2494
4905
    list1=[]
2495
4906
    for obj in fp_group.Group:
2496
 
        # do what you want to automate
2497
4907
        #if (obj.Label==fp_group.Label):
2498
 
        #Gui.Selection.addSelection(obj)
 
4908
        #FreeCADGui.Selection.addSelection(obj)
2499
4909
        shape=obj.Shape.copy()
2500
 
        #shape_name=App.ActiveDocument.ActiveObject.Name
 
4910
        #shape_name=FreeCAD.ActiveDocument.ActiveObject.Name
2501
4911
        list1.append(shape)
2502
4912
        #Part.show(shape)
2503
4913
        fp_objs.append(obj)
2504
 
        #App.Console.PrintMessage("added")
2505
 
 
 
4914
        #say("added")
2506
4915
        #
2507
4916
    #fp_objs.copy
2508
4917
    #objFp=Part.makeCompound(shape)
2509
4918
    objFp=Part.makeCompound(list1)
2510
4919
    Part.show(objFp)
2511
4920
 
2512
 
    obj = App.ActiveDocument.ActiveObject
2513
 
    #App.Console.PrintMessage("h")
2514
 
    Gui.Selection.addSelection(obj)            # select the object
2515
 
 
2516
 
    #obj = App.ActiveDocument.getObject(objFp.Name)
2517
 
    #Gui.Selection.addSelection(Gui.ActiveDocument.ActiveObject)
2518
 
    #Gui.ActiveDocument.getObject(objFp.Name).BoundingBox = True
2519
 
 
2520
 
    createSolidBBox(obj)
2521
 
    bbox=App.ActiveDocument.ActiveObject
2522
 
    App.ActiveDocument.ActiveObject.Label ="Pcb_solid"
2523
 
    pcb_solid_name=App.ActiveDocument.ActiveObject.Name
2524
 
    App.ActiveDocument.removeObject(obj.Name)
2525
 
 
2526
 
    #Gui.ActiveDocument.getObject(bbox.Name).BoundingBox = True
 
4921
    obj = FreeCAD.ActiveDocument.ActiveObject
 
4922
    #say("h")
 
4923
    FreeCADGui.Selection.addSelection(obj)            # select the object
 
4924
    createSolidBBox2(obj)
 
4925
    bbox=FreeCAD.ActiveDocument.ActiveObject
 
4926
    FreeCAD.ActiveDocument.ActiveObject.Label ="Pcb_solid"
 
4927
    pcb_solid_name=FreeCAD.ActiveDocument.ActiveObject.Name
 
4928
    FreeCAD.ActiveDocument.removeObject(obj.Name)
 
4929
 
 
4930
    #FreeCADGui.ActiveDocument.getObject(bbox.Name).BoundingBox = True
2527
4931
    FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (0.664,0.664,0.496)
2528
4932
    FreeCADGui.ActiveDocument.ActiveObject.Transparency = 80
2529
 
    #obj6 = App.ActiveDocument.getObject(bbox.Name)
 
4933
    #obj6 = FreeCAD.ActiveDocument.getObject(bbox.Name)
2530
4934
    fp_group.addObject(bbox)
2531
4935
 
2532
 
 
2533
4936
    if len(HoleList)>0:
2534
 
        #App.Console.PrintMessage("cutting base")
2535
 
        #Gui.ActiveDocument.getObject(bbox.Name).BoundingBox = True
2536
 
        #Gui.ActiveDocument.getObject(pcb_solid_name).BoundingBox = True
2537
 
        #Gui.ActiveDocument.getObject(Holes_name).BoundingBox = True
2538
 
        cut_base = App.ActiveDocument.getObject(pcb_solid_name).Shape
2539
 
        #App.Console.PrintMessage("cutting")
2540
 
        cutter = App.ActiveDocument.getObject(Holes_name).Shape
2541
 
        #App.Console.PrintMessage("cutting2")
2542
 
        cut_base=cut_base.cut(cutter)
2543
 
        Part.show(cut_base)
2544
 
        pcb_name=App.ActiveDocument.ActiveObject.Name
2545
 
        App.ActiveDocument.ActiveObject.Label ="Pcb"
 
4937
        cut_base = FreeCAD.ActiveDocument.getObject(pcb_solid_name).Shape
 
4938
        for drill in HoleList:
 
4939
            #Holes = Part.makeCompound(HoleList)
 
4940
            hole = Part.makeSolid(drill)
 
4941
            #Part.show(hole)
 
4942
            #hole_name=FreeCAD.ActiveDocument.ActiveObject.Name
 
4943
            #cutter = FreeCAD.ActiveDocument.getObject(hole_name).Shape
 
4944
            cut_base=cut_base.cut(hole)
 
4945
        Part.show(cut_base) 
 
4946
        pcb_name=FreeCAD.ActiveDocument.ActiveObject.Name
 
4947
        FreeCAD.ActiveDocument.ActiveObject.Label ="Pcb"
2546
4948
        FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (0.664,0.664,0.496)
2547
4949
        FreeCADGui.ActiveDocument.ActiveObject.Transparency = 80
2548
 
        #App.Console.PrintMessage("cutted")
2549
 
        pcb=App.ActiveDocument.ActiveObject
 
4950
        #say("cutted")
 
4951
        pcb=FreeCAD.ActiveDocument.ActiveObject
2550
4952
        fp_group.addObject(pcb)
2551
 
        #App.Console.PrintMessage("added")
2552
 
        #App.activeDocument().recompute()
2553
 
        App.ActiveDocument.removeObject(pcb_solid_name)
2554
 
        App.ActiveDocument.removeObject(Holes_name)
2555
 
 
 
4953
        #say("added")
 
4954
        #FreeCAD.activeDocument().recompute()
 
4955
        FreeCAD.ActiveDocument.removeObject(pcb_solid_name)
 
4956
        FreeCAD.ActiveDocument.removeObject(Holes_name)
 
4957
       
2556
4958
    list2=[]
2557
4959
    list2_objs=[]
2558
4960
    for obj in fp_group.Group:
2559
4961
        # do what you want to automate
2560
4962
        #if (obj.Label==fp_group.Label):
2561
 
        #Gui.Selection.addSelection(obj)
 
4963
        #FreeCADGui.Selection.addSelection(obj)
2562
4964
        shape=obj.Shape.copy()
2563
 
        #shape_name=App.ActiveDocument.ActiveObject.Name
 
4965
        #shape_name=FreeCAD.ActiveDocument.ActiveObject.Name
2564
4966
        list2.append(shape)
2565
4967
        #Part.show(shape)
2566
4968
        list2_objs.append(obj)
2567
 
        #App.Console.PrintMessage("added")
2568
 
    #App.Console.PrintMessage(list2)
2569
 
    #App.Console.PrintMessage('here1')
 
4969
        #say("added")
 
4970
    #say(list2)
 
4971
    #say('here1')
2570
4972
 
2571
4973
    #Draft.rotate(list2_objs,90.0,FreeCAD.Vector(0.0,0.0,0.0),axis=FreeCAD.Vector(-0.0,-0.0,1.0),copy=False)
2572
 
    #App.Console.PrintMessage('here1')
 
4974
    #say('here1')
2573
4975
 
2574
4976
    rot=[0,0,rot_wrl]
2575
4977
    rotateObjs(list2_objs, rot)
2576
4978
 
2577
4979
    for obj in fp_group.Group:
2578
 
        Gui.Selection.removeSelection(obj)
2579
 
    #App.Console.PrintMessage('here2')
2580
 
 
2581
 
    Gui.SendMsgToActiveView("ViewFit")
2582
 
    #pads_found=getPadsList(content)
2583
 
 
2584
 
###
2585
 
 
 
4980
        FreeCADGui.Selection.removeSelection(obj)
 
4981
    #say('here2')
 
4982
 
 
4983
    FreeCADGui.SendMsgToActiveView("ViewFit")
 
4984
    #pads_found=getPadsList(content)
 
4985
 
 
4986
###
 
4987
 
 
4988
def routineDrawIDF(doc,filename):
 
4989
    """process_emn(document, filename)-> adds emn geometry from emn file"""
 
4990
    global start_time
 
4991
    msg='IDF_ImporterVersion='+IDF_ImporterVersion+'\n'
 
4992
    say(msg)
 
4993
    emnfile=pythonopen(filename, "r")
 
4994
    emn_unit=1.0 #presume milimeter like emn unit
 
4995
    emn_version=2 #presume emn_version 2
 
4996
    board_thickness=0 #presume 0 board height
 
4997
    board_outline=[] #no outline
 
4998
    drills=[] #no drills
 
4999
    placement=[] #no placement
 
5000
    place_item=[] #empty place item
 
5001
    emnlines=emnfile.readlines()
 
5002
    emnfile.close()   
 
5003
    passed_sections=[]
 
5004
    current_section=""
 
5005
    section_counter=0
 
5006
    ignore_hole_size=min_drill_size
 
5007
    #say((emnlines))
 
5008
    for emnline in emnlines:
 
5009
        emnrecords=split_records(emnline)
 
5010
        if len( emnrecords )==0 : continue
 
5011
        if len( emnrecords[0] )>4 and emnrecords[0][0:4]==".END":
 
5012
            passed_sections.append(current_section)
 
5013
            current_section=""
 
5014
        elif emnrecords[0][0]==".":
 
5015
            current_section=emnrecords[0]
 
5016
            section_counter=0
 
5017
        section_counter+=1
 
5018
        if current_section==".HEADER"  and section_counter==2:
 
5019
            emn_version=int(float(emnrecords[1]))
 
5020
            say("Emn version: "+emnrecords[1]+"\n")
 
5021
        if current_section==".HEADER"  and section_counter==3 and emnrecords[1]=="THOU":
 
5022
            emn_unit=0.0254
 
5023
            say("UNIT THOU\n" )
 
5024
        if current_section==".HEADER"  and section_counter==3 and emnrecords[1]=="TNM":
 
5025
            emn_unit=0.000010
 
5026
            say("TNM\n" )
 
5027
        if current_section==".BOARD_OUTLINE"  and section_counter==2:
 
5028
            board_thickness=emn_unit*float(emnrecords[0])
 
5029
            say("Found board thickness "+emnrecords[0]+"\n")
 
5030
        if current_section==".BOARD_OUTLINE"  and section_counter>2:
 
5031
            board_outline.append([int(emnrecords[0]),float(emnrecords[1])*emn_unit,float(emnrecords[2])*emn_unit,float(emnrecords[3])])
 
5032
        if current_section==".DRILLED_HOLES"  and section_counter>1 and float(emnrecords[0])*emn_unit>ignore_hole_size:
 
5033
            drills.append([float(emnrecords[0])*emn_unit,float(emnrecords[1])*emn_unit,float(emnrecords[2])*emn_unit])
 
5034
        if current_section==".PLACEMENT"  and section_counter>1 and fmod(section_counter,2)==0:
 
5035
            place_item=[]
 
5036
            place_item.append(emnrecords[2]) #Reference designator
 
5037
            place_item.append(emnrecords[1]) #Component part number
 
5038
            place_item.append(emnrecords[0]) #Package name
 
5039
        if current_section==".PLACEMENT"  and section_counter>1 and fmod(section_counter,2)==1:
 
5040
            place_item.append(float(emnrecords[0])*emn_unit) #X
 
5041
            place_item.append(float(emnrecords[1])*emn_unit) #Y
 
5042
            if emn_version==3:
 
5043
                place_item.append(float(emnrecords[2])*emn_unit) #Z  maui
 
5044
                #say("\nZ="+(str(float(emnrecords[2])))+"\n")   
 
5045
            place_item.append(float(emnrecords[emn_version])) #Rotation
 
5046
            place_item.append(emnrecords[emn_version+1]) #Side
 
5047
            place_item.append(emnrecords[emn_version+2]) #Place Status
 
5048
            say(str(place_item)+"\n")
 
5049
            placement.append(place_item)
 
5050
        
 
5051
    say("\n".join(passed_sections)+"\n")
 
5052
    #say(board_outline)
 
5053
    say("Proceed "+str(Process_board_outline(doc,board_outline,drills,board_thickness))+" outlines\n")
 
5054
    ## place_steps(doc,placement,board_thickness)
 
5055
    
 
5056
###
 
5057
def Process_board_outline(doc,board_outline,drills,board_thickness):
 
5058
    """Process_board_outline(doc,board_outline,drills,board_thickness)-> number proccesed loops
 
5059
        adds emn geometry from emn file"""
 
5060
    global start_time
 
5061
    vertex_index=-1; #presume no vertex
 
5062
    lines=-1 #presume no lines
 
5063
    out_shape=[]
 
5064
    out_face=[]
 
5065
    for point in board_outline:
 
5066
        vertex=Base.Vector(point[1],point[2],0) 
 
5067
        vertex_index+=1
 
5068
        if vertex_index==0:
 
5069
            lines=point[0] 
 
5070
        elif lines==point[0]:
 
5071
            if point[3]!=0 and point[3]!=360:
 
5072
                out_shape.append(Part.Arc(prev_vertex,mid_point(prev_vertex,vertex,point[3]),vertex))
 
5073
                #say("mid point "+str(mid_point)+"\n")
 
5074
            elif point[3]==360:
 
5075
                per_point=Per_point(prev_vertex,vertex)
 
5076
                out_shape.append(Part.Arc(per_point,mid_point(per_point,vertex,point[3]/2),vertex))
 
5077
                out_shape.append(Part.Arc(per_point,mid_point(per_point,vertex,-point[3]/2),vertex))
 
5078
            else:
 
5079
                out_shape.append(Part.Line(prev_vertex,vertex))
 
5080
        else:
 
5081
            out_shape=Part.Shape(out_shape)
 
5082
            out_shape=Part.Wire(out_shape.Edges)
 
5083
            out_face.append(Part.Face(out_shape))
 
5084
            out_shape=[]
 
5085
            vertex_index=0 
 
5086
            lines=point[0] 
 
5087
        prev_vertex=vertex
 
5088
    if lines!=-1:
 
5089
        out_shape=Part.Shape(out_shape)
 
5090
        out_shape=Part.Wire(out_shape.Edges)
 
5091
        out_face.append(Part.Face(out_shape))
 
5092
        outline=out_face[0]
 
5093
        say("Added outline\n")
 
5094
        if len(out_face)>1:
 
5095
            say("Cutting shape inside outline\n")
 
5096
            for otl_cut in out_face[1: ]:
 
5097
                outline=outline.cut(otl_cut)
 
5098
                #say("Cutting shape inside outline\n")
 
5099
        if len(drills)>0:
 
5100
            say("Cutting holes inside outline\n")
 
5101
        for drill in drills:
 
5102
            #say("Cutting hole inside outline\n")
 
5103
            out_shape=Part.makeCircle(drill[0]/2, Base.Vector(drill[1],drill[2],0))
 
5104
            out_shape=Part.Wire(out_shape.Edges)
 
5105
            outline=outline.cut(Part.Face(out_shape))
 
5106
        doc_outline=doc.addObject("Part::Feature","Pcb")
 
5107
        doc_outline.Shape=outline 
 
5108
        #FreeCADGui.Selection.addSelection(doc_outline)
 
5109
        #FreeCADGui.runCommand("Draft_Upgrade")
 
5110
        #outline=FreeCAD.ActiveDocument.getObject("Union").Shape
 
5111
        #FreeCAD.ActiveDocument.removeObject("Union")
 
5112
        #doc_outline=doc.addObject("Part::Feature","Board_outline")
 
5113
        doc_outline.Shape=outline.extrude(Base.Vector(0,0,-board_thickness))
 
5114
        grp=doc.addObject("App::DocumentObjectGroup", "Board_Geoms")
 
5115
        grp.addObject(doc_outline)
 
5116
        doc.Pcb.ViewObject.ShapeColor = (colr,colg,colb)
 
5117
        say_time()
 
5118
        #say(str(start_time));say('*'+str(end_milli_time)+'start-end')
 
5119
        FreeCADGui.activeDocument().activeView().viewAxometric()
 
5120
        FreeCADGui.SendMsgToActiveView("ViewFit")
 
5121
        #doc.Pcb.ViewObject.ShapeColor=(0.0, 0.5, 0.0, 0.0)
 
5122
    return lines+1
 
5123
 
 
5124
 
 
5125
###
 
5126
def split_records(line_record):
 
5127
    """split_records(line_record)-> list of strings(records)
 
5128
       
 
5129
       standard separator list separator is space, records containting encapsulated by " """
 
5130
    split_result=[]
 
5131
    quote_pos=line_record.find('"')
 
5132
    while quote_pos!=-1:
 
5133
        if quote_pos>0:
 
5134
            split_result.extend(line_record[ :quote_pos].split())
 
5135
            line_record=line_record[quote_pos: ]
 
5136
            quote_pos=line_record.find('"',1)
 
5137
        else: 
 
5138
            quote_pos=line_record.find('"',1)
 
5139
        if quote_pos!=-1:
 
5140
            split_result.append(line_record[ :quote_pos+1])
 
5141
            line_record=line_record[quote_pos+1: ]
 
5142
        else:
 
5143
            split_result.append(line_record) 
 
5144
            line_record=""
 
5145
        quote_pos=line_record.find('"')
 
5146
    split_result.extend(line_record.split())
 
5147
    return split_result
 
5148
###
 
5149
 
 
5150
#def routineDrawPCB(content,pcbThickness,board_elab):
 
5151
def routineDrawPCB(pcbThickness,board_elab):
 
5152
    global start_time
 
5153
    #for item in content:
 
5154
    #    say(item)
 
5155
    #                      x1, y1, x2, y2, width
 
5156
    say("PCB Loader \n")
 
5157
    doc=FreeCAD.activeDocument()
 
5158
    for obj in FreeCAD.ActiveDocument.Objects:
 
5159
        FreeCADGui.Selection.removeSelection(obj)
 
5160
    TopPadList=[]
 
5161
    BotPadList=[]
 
5162
    HoleList=[]
 
5163
    THPList=[]
 
5164
 
 
5165
    EdgeCuts = []
 
5166
    EdgeCuts_face = []
 
5167
    EdgeCuts_shape = []
 
5168
    PCB = []
 
5169
    
 
5170
    edges=[]
 
5171
    PCBs = []
 
5172
    totalHeight=pcbThickness
 
5173
    
 
5174
    # arc
 
5175
    #for i in getArc('Edge.Cuts', content, 'gr_arc'):
 
5176
    for i in getArc('Edge.Cuts', board_elab, 'gr_arc'):
 
5177
        #say('arcs')
 
5178
        x1 = i[0] #+ X1
 
5179
        y1 = i[1] #+ Y1
 
5180
        x2 = i[2] #+ X1
 
5181
        y2 = i[3] #+ Y1
 
5182
        arc1=Part.Edge(Part.Arc(Base.Vector(x2,y2,0),mid_point(Base.Vector(x2,y2,0),Base.Vector(x1,y1,0),i[4]),Base.Vector(x1,y1,0)))
 
5183
        #arc1=Part.Edge(getCurvedLine(x2, y2,x1, y1, i[4]))
 
5184
        #say(arc1.Curve.EndPoint) #to do maui
 
5185
        edges.append(arc1)
 
5186
        if show_border:
 
5187
            Part.show(arc1)
 
5188
        #FreeCAD.ActiveDocument.ActiveObject.supportedProperties()
 
5189
        #say(FreeCAD.ActiveDocument.ActiveObject.Shape.Name)
 
5190
        PCB.append(['Arc', i[0], i[1], i[2], i[3], i[4]])
 
5191
        
 
5192
    # circle
 
5193
    #for i in getCircle('Edge.Cuts', content, 'gr_circle'):
 
5194
    for i in getCircle('Edge.Cuts', board_elab, 'gr_circle'):
 
5195
        #say(i)
 
5196
        xs = i[0] #+ X1
 
5197
        ys = i[1] #+ Y1
 
5198
        r  = i[2]
 
5199
        circle1=Part.Edge(Part.Circle(Base.Vector(xs, ys,0), Base.Vector(0, 0, 1), r))
 
5200
        ##circle1=Part.makeCircle(Base.Vector(xs, ys,0), Base.Vector(0, 0, 1), r)
 
5201
        ##circle1=circle1.Edge
 
5202
        if show_border:
 
5203
            Part.show(circle1)
 
5204
        circle1=Part.Wire(circle1)
 
5205
        circle1=Part.Face(circle1)
 
5206
        if show_shapes:
 
5207
            Part.show(circle1)
 
5208
        #circle1.translate(Base.Vector(0,0,-totalHeight))
 
5209
        PCBs.append(circle1)
 
5210
        #say('circle\n')
 
5211
        PCB.append(['Circle', i[0], i[1], i[2]])
 
5212
    
 
5213
    # line
 
5214
    #getLine('F.SilkS', content, 'fp_line')
 
5215
    #for i in getLine('Edge.Cuts', content, 'gr_line'):
 
5216
    for i in getLine('Edge.Cuts', board_elab, 'gr_line'):
 
5217
        #say("here3\r\n")
 
5218
        x1 = i[0] #+ X1
 
5219
        y1 = i[1] #+ Y1
 
5220
        x2 = i[2] #+ X1
 
5221
        y2 = i[3] #+ Y1
 
5222
        line1=Part.makeLine((x1, y1,0), (x2,y2,0))
 
5223
        edges.append(line1);
 
5224
        if show_border:
 
5225
            Part.show(line1)
 
5226
        PCB.append(['Line', i[0], i[1], i[2], i[3]])
 
5227
    
 
5228
    #sort edges to form a single closed 2D shape
 
5229
    loopcounter = 0
 
5230
    if (not len(edges)>0):
 
5231
        say ("no PCBs found")
 
5232
    else:
 
5233
        newEdges = [];
 
5234
        newEdges.append(edges.pop(0))
 
5235
        #say(newEdges[0])
 
5236
        #print [newEdges[0].Vertexes[0].Point]
 
5237
        #print [newEdges[0].Vertexes[-1].Point]
 
5238
        #say(str(len(newEdges[0].Vertexes)))
 
5239
        nextCoordinate = newEdges[0].Vertexes[0].Point
 
5240
        firstCoordinate = newEdges[0].Vertexes[-1].Point
 
5241
        #nextCoordinate = newEdges[0].Curve.EndPoint
 
5242
        #firstCoordinate = newEdges[0].Curve.StartPoint
 
5243
        while(len(edges)>0 and loopcounter < 2):
 
5244
            loopcounter = loopcounter + 1
 
5245
            #print "nextCoordinate: ", nextCoordinate
 
5246
            #if len(newEdges[0].Vertexes) > 1: # not circle
 
5247
            for j, edge in enumerate(edges):
 
5248
                #print "compare to: ", edges[j].Curve.StartPoint, "/" , edges[j].Curve.EndPoint
 
5249
                #if edges[j].Curve.StartPoint == nextCoordinate:
 
5250
                if edges[j].Vertexes[-1].Point == nextCoordinate:
 
5251
                    nextCoordinate = edges[j].Vertexes[0].Point
 
5252
                    newEdges.append(edges.pop(j))
 
5253
                    loopcounter = 0
 
5254
                    break
 
5255
                elif edges[j].Vertexes[0].Point == nextCoordinate:
 
5256
                    nextCoordinate = edges[j].Vertexes[-1].Point
 
5257
                    newEdges.append(edges.pop(j))
 
5258
                    loopcounter = 0
 
5259
                    break
 
5260
            if nextCoordinate == firstCoordinate:
 
5261
                say('2d closed path\n')
 
5262
                try: # maui
 
5263
                    #say('\ntrying wire & face\n')
 
5264
                    #newEdges_old=newEdges
 
5265
                    ## newEdges = Part.Wire(newEdges)
 
5266
                    #say('trying face\n')
 
5267
                    ## newEdges = Part.Face(newEdges)
 
5268
                    newEdges = OpenSCAD2Dgeom.edgestofaces(newEdges)
 
5269
                    #say('done\n')
 
5270
                    #newEdges.translate(Base.Vector(0,0,-totalHeight))
 
5271
                    if show_shapes:
 
5272
                        Part.show(newEdges)
 
5273
                    #newEdges = newEdges.extrude(Base.Vector(0,0,totalHeight))
 
5274
                    PCBs.append(newEdges)
 
5275
                    if (len(edges)>0):
 
5276
                        newEdges = [];
 
5277
                        newEdges.append(edges.pop(0))
 
5278
                        nextCoordinate = newEdges[0].Vertexes[0].Point
 
5279
                        firstCoordinate = newEdges[0].Vertexes[-1].Point
 
5280
                except Part.OCCError: # Exception: #
 
5281
                    say("error in creating PCB")
 
5282
                    stop
 
5283
                    
 
5284
        if loopcounter == 2:
 
5285
            say("*** omitting PCBs because there was a not closed loop in your edge lines ***\n")
 
5286
            say("*** have a look at position x=" + str(nextCoordinate.x) + "mm, y=" + str(nextCoordinate.y) + "mm ***\n")
 
5287
            say('pcb edge not closed\n')
 
5288
            QtGui.qApp.restoreOverrideCursor()
 
5289
            diag = QtGui.QMessageBox(QtGui.QMessageBox.Icon.Critical,
 
5290
                                    'Error in creating Board Edge                                                                ."+"\r\n"',
 
5291
                                    'Try Loading IDF(.emn) instead of .kicad_pcb or \nreview your Board Edges in Kicad!\nposition x=' + str(nextCoordinate.x) + 'mm, y=' + str(nextCoordinate.y) + 'mm')
 
5292
            diag.setWindowModality(QtCore.Qt.ApplicationModal)
 
5293
            diag.exec_()
 
5294
            stop #maui
 
5295
        if disable_cutting:
 
5296
            FreeCADGui.activeDocument().activeView().viewTop()
 
5297
            FreeCADGui.SendMsgToActiveView("ViewFit")
 
5298
            stop #maui
 
5299
        maxLenght=0
 
5300
        idx=0
 
5301
        for extruded in PCBs:
 
5302
            #search for orientation of each pcb in 3d space, save it (no transformation yet!)
 
5303
            angle = 0;
 
5304
            axis = Base.Vector(0,0,1)
 
5305
            position = Base.Vector(0,0,0)
 
5306
            if show_shapes:
 
5307
                Part.show(extruded)
 
5308
            #extrude_XLenght=FreeCAD.ActiveDocument.ActiveObject.Shape.BoundBox.XLength
 
5309
            # extrude_XLenght=extruded.Length #perimeter
 
5310
            extrude_XLenght=extruded.BoundBox.XLength
 
5311
            #extrude_XLenght=FreeCAD.ActiveDocument.ActiveObject.Shape.Edges.Length
 
5312
            if maxLenght < extrude_XLenght:
 
5313
                maxLenght = extrude_XLenght
 
5314
                external_idx=idx
 
5315
            #say('XLenght='+str(extrude_XLenght)+'\n')
 
5316
            idx=idx+1
 
5317
        say('max Length='+str(maxLenght)+' index='+str(external_idx)+'\n')
 
5318
        cut_base=PCBs[external_idx]
 
5319
        i=0
 
5320
        for i in range (len(PCBs)):
 
5321
            if i!=external_idx:
 
5322
                cutter=PCBs[i]
 
5323
                cut_base=cut_base.cut(cutter)
 
5324
        if test_extrude:
 
5325
            cut_base = cut_base.extrude(Base.Vector(0,0,totalHeight))
 
5326
        if show_shapes:
 
5327
            Part.show(cut_base)
 
5328
        #cut_base_name=FreeCAD.ActiveDocument.ActiveObject.Name
 
5329
        #say('Alive1')
 
5330
    if len(PCBs)==1:
 
5331
        cut_base = PCBs[0]
 
5332
        if test_extrude:
 
5333
            cut_base = cut_base.extrude(Base.Vector(0,0,totalHeight))
 
5334
        if show_shapes:
 
5335
            Part.show(cut_base)
 
5336
        if show_shapes:
 
5337
            FreeCAD.activeDocument().removeObject("Shape")
 
5338
        ###FreeCAD.ActiveDocument.recompute()
 
5339
    
 
5340
    if len(PCBs)==0:
 
5341
        say('pcb edge not found\n')
 
5342
        QtGui.qApp.restoreOverrideCursor()
 
5343
        diag = QtGui.QMessageBox(QtGui.QMessageBox.Icon.Critical,
 
5344
                                'Error in creating Board Edge                                                                ."+"\r\n"',
 
5345
                                'Try Loading IDF(.emn) instead of .kicad_pcb or \nreview your Board Edges in Kicad!\n')
 
5346
        diag.setWindowModality(QtCore.Qt.ApplicationModal)
 
5347
        diag.exec_()
 
5348
        stop #maui
 
5349
    FreeCADGui.activeDocument().activeView().viewTop()
 
5350
    FreeCADGui.SendMsgToActiveView("ViewFit")
 
5351
    say_time()
 
5352
    # stop #maui       
 
5353
    
 
5354
    say("start cutting\n")    
 
5355
    if holes_solid:
 
5356
        HoleList = getPads(board_elab,pcbThickness)
 
5357
    else:
 
5358
        HoleList = getPads_flat(board_elab)
 
5359
    #say('alive-getting holes\n')
 
5360
    ## stop
 
5361
    if len(HoleList)>0:
 
5362
        #cut_base = FreeCAD.ActiveDocument.getObject(cut_base_name).Shape
 
5363
        #cut_base_name=FreeCAD.ActiveDocument.ActiveObject
 
5364
        #cut_base_name=FreeCAD.ActiveDocument.ActiveObject.Name
 
5365
        #say(cut_base)
 
5366
        for drill in HoleList:
 
5367
            #say("Cutting hole inside outline\n")
 
5368
            #say(drill)
 
5369
            if holes_solid:
 
5370
                drill = Part.makeSolid(drill)
 
5371
            if show_shapes:
 
5372
                Part.show(drill)
 
5373
            cut_base=cut_base.cut(drill)
 
5374
    doc_outline=doc.addObject("Part::Feature","Pcb")
 
5375
    doc_outline.Shape=cut_base 
 
5376
    doc_outline.Shape=cut_base.extrude(Base.Vector(0,0,-pcbThickness))
 
5377
    #cut_base=cut_base.extrude(Base.Vector(0,0,-pcbThickness))
 
5378
    #Part.show(cut_base)
 
5379
    pcb_name=FreeCAD.ActiveDocument.ActiveObject.Name
 
5380
    pcb_board=FreeCAD.ActiveDocument.ActiveObject
 
5381
    #FreeCAD.ActiveDocument.ActiveObject.Label ="Pcb"
 
5382
    FreeCADGui.ActiveDocument.ActiveObject.ShapeColor = (colr,colg,colb)
 
5383
    #FreeCADGui.ActiveDocument.ActiveObject.Transparency = 20
 
5384
    
 
5385
    #if remove_pcbPad==True:
 
5386
    #    FreeCAD.activeDocument().removeObject(cut_base_name)
 
5387
        #FreeCAD.activeDocument().removeObject(Holes_name)
 
5388
    grp=doc.addObject("App::DocumentObjectGroup", "Board_Geoms")
 
5389
    grp.addObject(pcb_board)
 
5390
    #grp.addObject(doc_outline)      
 
5391
        
 
5392
    say_time()
 
5393
    FreeCADGui.activeDocument().activeView().viewAxometric()
 
5394
    FreeCADGui.SendMsgToActiveView("ViewFit")
 
5395
    #FreeCADGui.SendMsgToActiveView("ViewFit")
 
5396
    #pads_found=getPadsList(content)
 
5397
    
 
5398
###
 
5399
 
 
5400
###
 
5401
#cmd open option
 
5402
args=sys.argv
 
5403
#say(args)
 
5404
if len(args) == 3:
 
5405
#    #filename="./psu-fc-1.wrl"
 
5406
    #path, fname = os.path.split(args[2])
 
5407
    #export_board_2step=True
 
5408
    sys.argv=""
 
5409
    ext = os.path.splitext(os.path.basename(args[2]))[1]
 
5410
    fullfname=args[2]
 
5411
    fname=os.path.splitext(os.path.basename(args[2]))[0]
 
5412
    #say(filePath+' ');say(fname+' ');say(ext);say('\n')
 
5413
    fullFileName=fullfname+".kicad_pcb"
 
5414
    fileName=fname+".kicad_pcb"
 
5415
    #filePath = os.path.dirname(os.path.abspath(__file__))
 
5416
    filePath = os.path.dirname(os.path.abspath(fullFileName))
 
5417
    #filePath = os.path.split(os.path.realpath(__file__))[0]
 
5418
    say ('arg file path '+filePath+'\n')
 
5419
    if filePath == "":
 
5420
        filePath = "."
 
5421
    last_pcb_path = filePath
 
5422
    #say(fullFileName+'\n')
 
5423
    if os.path.exists(fullFileName):
 
5424
        #say("opening "+ fullFileName+'\n')
 
5425
        cfgParsWrite(configFilePath)
 
5426
        onLoadBoard(fullFileName)
 
5427
    else:
 
5428
        fullfilePath=filePath+os.sep+fname+".kicad_pcb"
 
5429
        #say(fullfilePath+'\n')
 
5430
        if os.path.exists(fullfilePath):
 
5431
            #say("opening "+ fullfilePath+'\n')
 
5432
            cfgParsWrite(configFilePath)
 
5433
            onLoadBoard(fullfilePath)
 
5434
        else:
 
5435
            sayw("missing "+ fullfilePath+'\n')
 
5436
            sayw("missing "+ fullFileName+'\n')
 
5437
            #say("error missing "+ fullfilePath+'\r\n')
 
5438
            QtGui.qApp.restoreOverrideCursor()
 
5439
            reply = QtGui.QMessageBox.information(None,"Error ...","... missing \r\n"+ fullfilePath+"\r\n... missing \r\n"+ fullFileName)
 
5440
        #
 
5441
 
 
5442
###
2586
5443
 
2587
5444
QtGui.QDesktopServices.openUrl(QtCore.QUrl("t"))
2588
5445
 
2589
 
# Constant definitions
2590
 
global userCancelled, userOK, show_mouse_pos, min_val, last_file_path, resetP
2591
 
last_file_path=''
2592
 
resetP=True
2593
 
global rot_wrl, test_flag
2594
 
 
2595
 
#test_flag=True
2596
 
test_flag=False
2597
 
 
2598
 
rot_wrl=0.0
2599
 
#global module_3D_dir
2600
 
userCancelled        = "Cancelled"
2601
 
userOK            = "OK"
2602
 
show_mouse_pos = True
2603
 
#module_3D_dir="C:/Cad/Progetti_K/a_mod"
2604
 
___ver___ = "1.3.2.8"
2605
 
min_val=0.001
2606
 
conflict_tolerance=1e-6  #volume tolerance
2607
 
font_size=8
2608
5446
 
2609
5447
# code ***********************************************************************************
2610
5448
 
2611
5449
form = RotateXYZGuiClass()
 
5450
 
2612
5451
#
2613
5452
#Word size: 64-bit
2614
5453
#Version: 0.15.4671 (Git)
2618
5457
#Coin version: 3.1.3
2619
5458
#SoQt version: 1.5.0
2620
5459
#OCC version: 6.7.0
2621
 
#
 
 
b'\\ No newline at end of file'
 
5460
#