From ad73247e9eab41e15595970e3e269462edba33c6 Mon Sep 17 00:00:00 2001 From: howetuft Date: Thu, 15 Aug 2019 15:42:08 +0200 Subject: [PATCH 01/19] [Robot] svd_eigen_Macie.hpp: Fix compiler warnings "Warning: comparison between signed and unsigned integer expressions [-Wsign-compare]" Changed 'unsigned int' into 'Eigen::Index' type for several loop indexes... --- .../Robot/App/kdl_cp/utilities/svd_eigen_Macie.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Mod/Robot/App/kdl_cp/utilities/svd_eigen_Macie.hpp b/src/Mod/Robot/App/kdl_cp/utilities/svd_eigen_Macie.hpp index ef2dbd4d99..4e3e00c235 100644 --- a/src/Mod/Robot/App/kdl_cp/utilities/svd_eigen_Macie.hpp +++ b/src/Mod/Robot/App/kdl_cp/utilities/svd_eigen_Macie.hpp @@ -70,8 +70,8 @@ namespace KDL rotate=false; rotations=0; //Perform rotations between columns of B - for(unsigned int i=0;i Date: Thu, 15 Aug 2019 16:07:54 +0200 Subject: [PATCH 02/19] [Robot] chainiksolverpos_lma.cpp: Fix compil warng "Warning: Comparison between signed and unsigned integer expressions [-Wsign-compare]" Fixed by declaring loop index as library-provided type 'Eigen::Index' instead of raw 'unsigned int'. --- src/Mod/Robot/App/kdl_cp/chainiksolverpos_lma.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mod/Robot/App/kdl_cp/chainiksolverpos_lma.cpp b/src/Mod/Robot/App/kdl_cp/chainiksolverpos_lma.cpp index c74ea8d52c..091b553741 100644 --- a/src/Mod/Robot/App/kdl_cp/chainiksolverpos_lma.cpp +++ b/src/Mod/Robot/App/kdl_cp/chainiksolverpos_lma.cpp @@ -195,7 +195,7 @@ int ChainIkSolverPos_LMA::CartToJnt(const KDL::JntArray& q_init, const KDL::Fram svd.compute(jac); original_Aii = svd.singularValues(); - for (unsigned int j=0;j Date: Thu, 15 Aug 2019 16:56:46 +0200 Subject: [PATCH 03/19] [Robot] jacobian.cpp: Fix compiler warnings "Warning: comparison between signed and unsigned integer expressions [-Wsign-compare]" Changed 'unsigned int' into 'Eigen::Index' type for several loop indexes... --- src/Mod/Robot/App/kdl_cp/jacobian.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Mod/Robot/App/kdl_cp/jacobian.cpp b/src/Mod/Robot/App/kdl_cp/jacobian.cpp index 7c49c18c07..dffd7d7bf6 100644 --- a/src/Mod/Robot/App/kdl_cp/jacobian.cpp +++ b/src/Mod/Robot/App/kdl_cp/jacobian.cpp @@ -83,7 +83,7 @@ namespace KDL } void Jacobian::changeRefPoint(const Vector& base_AB){ - for(unsigned int i=0;isetColumn(i,this->getColumn(i).RefPoint(base_AB)); } @@ -97,7 +97,7 @@ namespace KDL } void Jacobian::changeBase(const Rotation& rot){ - for(unsigned int i=0;isetColumn(i,rot*this->getColumn(i));; } @@ -111,7 +111,7 @@ namespace KDL } void Jacobian::changeRefFrame(const Frame& frame){ - for(unsigned int i=0;isetColumn(i,frame*this->getColumn(i)); } From 945e76d915cb640853db406f8d79a50ab49e18fc Mon Sep 17 00:00:00 2001 From: howetuft Date: Thu, 15 Aug 2019 17:10:23 +0200 Subject: [PATCH 04/19] [Robot] treeiksolvervel_wdls.cpp: Fix compil warns "Warning: comparison between signed and unsigned integer expressions [-Wsign-compare]" Changed 'unsigned int' into 'Eigen::Index' type for several loop indexes... --- src/Mod/Robot/App/kdl_cp/treeiksolvervel_wdls.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Mod/Robot/App/kdl_cp/treeiksolvervel_wdls.cpp b/src/Mod/Robot/App/kdl_cp/treeiksolvervel_wdls.cpp index 924566ab86..52639edecd 100644 --- a/src/Mod/Robot/App/kdl_cp/treeiksolvervel_wdls.cpp +++ b/src/Mod/Robot/App/kdl_cp/treeiksolvervel_wdls.cpp @@ -89,9 +89,9 @@ namespace KDL { Wq_V.noalias() = Wq * V; // tmp = (Si*Wy*U'*y), - for (unsigned int i = 0; i < J.cols(); i++) { + for (Eigen::Index i = 0; i < J.cols(); i++) { double sum = 0.0; - for (unsigned int j = 0; j < J.rows(); j++) { + for (Eigen::Index j = 0; j < J.rows(); j++) { if (i < Wy_t.rows()) sum += U(j, i) * Wy_t(j); else From 4d12917b5fa40b8b573d689cd22b4a6fd952710c Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 22 Aug 2019 21:09:11 +1000 Subject: [PATCH 05/19] Refactor preferences into injected object instead of global. The following unrequired preferences are removed: - FORCE_BREP - STORE_UID - SERIALIZE - EXPORT_2D - FULL_PARAMETRIC - ADD-DEFAULT_SITE - ADD_DEFAULT_STOREY - ADD_DEFAULT_BUILDING --- src/Mod/Arch/importIFC.py | 238 +++++++++++++++++++------------------- 1 file changed, 116 insertions(+), 122 deletions(-) diff --git a/src/Mod/Arch/importIFC.py b/src/Mod/Arch/importIFC.py index 1bcb4abf2d..eea34da79f 100644 --- a/src/Mod/Arch/importIFC.py +++ b/src/Mod/Arch/importIFC.py @@ -144,42 +144,35 @@ def getPreferences(): """retrieves IFC preferences""" - global DEBUG, PREFIX_NUMBERS, SKIP, SEPARATE_OPENINGS - global ROOT_ELEMENT, GET_EXTRUSIONS, MERGE_MATERIALS - global MERGE_MODE_ARCH, MERGE_MODE_STRUCT, CREATE_CLONES - global FORCE_BREP, IMPORT_PROPERTIES, STORE_UID, SERIALIZE - global SPLIT_LAYERS, EXPORT_2D, FULL_PARAMETRIC, FITVIEW_ONIMPORT - global ADD_DEFAULT_SITE, ADD_DEFAULT_STOREY, ADD_DEFAULT_BUILDING p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch") + if FreeCAD.GuiUp and p.GetBool("ifcShowDialog",False): import FreeCADGui FreeCADGui.showPreferences("Import-Export",0) - DEBUG = p.GetBool("ifcDebug",False) - PREFIX_NUMBERS = p.GetBool("ifcPrefixNumbers",False) - SKIP = p.GetString("ifcSkip","").split(",") - SEPARATE_OPENINGS = p.GetBool("ifcSeparateOpenings",False) - ROOT_ELEMENT = p.GetString("ifcRootElement","IfcProduct") - GET_EXTRUSIONS = p.GetBool("ifcGetExtrusions",False) - MERGE_MATERIALS = p.GetBool("ifcMergeMaterials",False) - MERGE_MODE_ARCH = p.GetInt("ifcImportModeArch",0) - MERGE_MODE_STRUCT = p.GetInt("ifcImportModeStruct",1) - if MERGE_MODE_ARCH > 0: - SEPARATE_OPENINGS = False - GET_EXTRUSIONS = False - if not SEPARATE_OPENINGS: - SKIP.append("IfcOpeningElement") - CREATE_CLONES = p.GetBool("ifcCreateClones",True) - FORCE_BREP = p.GetBool("ifcExportAsBrep",False) - IMPORT_PROPERTIES = p.GetBool("ifcImportProperties",False) - STORE_UID = p.GetBool("ifcStoreUid",True) - SERIALIZE = p.GetBool("ifcSerialize",False) - SPLIT_LAYERS = p.GetBool("ifcSplitLayers",False) - EXPORT_2D = p.GetBool("ifcExport2D",True) - FULL_PARAMETRIC = p.GetBool("IfcExportFreeCADProperties",False) - FITVIEW_ONIMPORT = p.GetBool("ifcFitViewOnImport",False) - ADD_DEFAULT_SITE = p.GetBool("IfcAddDefaultSite",False) - ADD_DEFAULT_STOREY = p.GetBool("IfcAddDefaultStorey",False) - ADD_DEFAULT_BUILDING = p.GetBool("IfcAddDefaultBuilding",True) + + preferences = { + 'DEBUG': p.GetBool("ifcDebug",False), + 'PREFIX_NUMBERS': p.GetBool("ifcPrefixNumbers",False), + 'SKIP': p.GetString("ifcSkip","").split(","), + 'SEPARATE_OPENINGS': p.GetBool("ifcSeparateOpenings",False), + 'ROOT_ELEMENT': p.GetString("ifcRootElement","IfcProduct"), + 'GET_EXTRUSIONS': p.GetBool("ifcGetExtrusions",False), + 'MERGE_MATERIALS': p.GetBool("ifcMergeMaterials",False), + 'MERGE_MODE_ARCH': p.GetInt("ifcImportModeArch",0), + 'MERGE_MODE_STRUCT': p.GetInt("ifcImportModeStruct",1), + 'CREATE_CLONES': p.GetBool("ifcCreateClones",True), + 'IMPORT_PROPERTIES': p.GetBool("ifcImportProperties",False), + 'SPLIT_LAYERS': p.GetBool("ifcSplitLayers",False), + 'FITVIEW_ONIMPORT': p.GetBool("ifcFitViewOnImport",False) + } + + if preferences['MERGE_MODE_ARCH'] > 0: + preferences['SEPARATE_OPENINGS'] = False + preferences['GET_EXTRUSIONS'] = False + if not preferences['SEPARATE_OPENINGS']: + preferences['SKIP'].append("IfcOpeningElement") + + return preferences # ************************************************************************************************ @@ -197,7 +190,7 @@ def open(filename,skip=[],only=[],root=None): return doc -def insert(filename,docname,skip=[],only=[],root=None): +def insert(filename,docname,skip=[],only=[],root=None,preferences=None): """insert(filename,docname,skip=[],only=[],root=None): imports the contents of an IFC file. skip can contain a list of ids of objects to be skipped, only can restrict the import to @@ -205,7 +198,8 @@ def insert(filename,docname,skip=[],only=[],root=None): import only the derivates of a certain element type (default = ifcProduct).""" # read preference settings - getPreferences() + if preferences is None: + preferences = getPreferences() try: import ifcopenshell @@ -213,19 +207,19 @@ def insert(filename,docname,skip=[],only=[],root=None): FreeCAD.Console.PrintError("IfcOpenShell was not found on this system. IFC support is disabled\n") return - if DEBUG: print("Opening ",filename,"...",end="") + if preferences['DEBUG']: print("Opening ",filename,"...",end="") try: doc = FreeCAD.getDocument(docname) except: doc = FreeCAD.newDocument(docname) FreeCAD.ActiveDocument = doc - if DEBUG: print("done.") + if preferences['DEBUG']: print("done.") - global ROOT_ELEMENT, parametrics + global parametrics # allow to override the root element if root: - ROOT_ELEMENT = root + preferences['ROOT_ELEMENT'] = root # keeping global variable for debugging purposes # global ifcfile @@ -249,20 +243,20 @@ def insert(filename,docname,skip=[],only=[],root=None): settings.set(settings.USE_BREP_DATA,True) settings.set(settings.SEW_SHELLS,True) settings.set(settings.USE_WORLD_COORDS,True) - if SEPARATE_OPENINGS: + if preferences['SEPARATE_OPENINGS']: settings.set(settings.DISABLE_OPENING_SUBTRACTIONS,True) - if SPLIT_LAYERS and hasattr(settings,"APPLY_LAYERSETS"): + if preferences['SPLIT_LAYERS'] and hasattr(settings,"APPLY_LAYERSETS"): settings.set(settings.APPLY_LAYERSETS,True) # build all needed tables - if DEBUG: print("Building types and relationships table...",end="") + if preferences['DEBUG']: print("Building types and relationships table...",end="") # type tables sites = ifcfile.by_type("IfcSite") buildings = ifcfile.by_type("IfcBuilding") floors = ifcfile.by_type("IfcBuildingStorey") openings = ifcfile.by_type("IfcOpeningElement") materials = ifcfile.by_type("IfcMaterial") - products, annotations = importIFCHelper.buildRelProductsAnnotations(ifcfile, ROOT_ELEMENT) + products, annotations = importIFCHelper.buildRelProductsAnnotations(ifcfile, preferences['ROOT_ELEMENT']) # empty relation tables objects = {} # { id:object, ... } shapes = {} # { id:shaoe } only used for merge mode @@ -279,7 +273,7 @@ def insert(filename,docname,skip=[],only=[],root=None): subtractions = importIFCHelper.buildRelSubtractions(ifcfile) mattable = importIFCHelper.buildRelMattable(ifcfile) colors, style_material_id = importIFCHelper.buildRelColors(ifcfile, prodrepr) - if DEBUG: print("done.") + if preferences['DEBUG']: print("done.") # only import a list of IDs and their children, if defined if only: @@ -296,10 +290,10 @@ def insert(filename,docname,skip=[],only=[],root=None): from FreeCAD import Base progressbar = Base.ProgressIndicator() progressbar.start("Importing IFC objects...",len(products)) - if DEBUG: print("Parsing",len(products),"BIM objects...") + if preferences['DEBUG']: print("Parsing",len(products),"BIM objects...") # Prepare the 3D view if applicable - if FITVIEW_ONIMPORT and FreeCAD.GuiUp: + if preferences['FITVIEW_ONIMPORT'] and FreeCAD.GuiUp: overallboundbox = None import FreeCADGui FreeCADGui.ActiveDocument.activeView().viewAxonometric() @@ -317,7 +311,7 @@ def insert(filename,docname,skip=[],only=[],root=None): pid = product.id() guid = product.GlobalId ptype = product.is_a() - if DEBUG: print(count,"/",len(products),"object #"+str(pid),":",ptype,end="") + if preferences['DEBUG']: print(count,"/",len(products),"object #"+str(pid),":",ptype,end="") # build list of related property sets psets = importIFCHelper.getIfcPropertySets(ifcfile, pid) @@ -325,14 +319,14 @@ def insert(filename,docname,skip=[],only=[],root=None): # checking for full FreeCAD parametric definition, overriding everything else if psets and FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch").GetBool("IfcImportFreeCADProperties",False): if "FreeCADPropertySet" in [ifcfile[pset].Name for pset in psets.keys()]: - if DEBUG: print(" restoring from parametric definition...",end="") + if preferences['DEBUG']: print(" restoring from parametric definition...",end="") obj = createFromProperties(psets,ifcfile) if obj: objects[pid] = obj - if DEBUG: print("done") + if preferences['DEBUG']: print("done") continue else: - if DEBUG: print("failed") + if preferences['DEBUG']: print("failed") # no parametric data, we go the good old way name = str(ptype[3:]) @@ -340,7 +334,7 @@ def insert(filename,docname,skip=[],only=[],root=None): name = product.Name if six.PY2: name = name.encode("utf8") - if PREFIX_NUMBERS: + if preferences['PREFIX_NUMBERS']: name = "ID" + str(pid) + " " + name obj = None baseobj = None @@ -353,20 +347,20 @@ def insert(filename,docname,skip=[],only=[],root=None): if ptype in structuralifcobjects: archobj = False structobj = True - if DEBUG: print(" (struct)",end="") + if preferences['DEBUG']: print(" (struct)",end="") else: - if DEBUG: print(" (arch)",end="") - if MERGE_MODE_ARCH == 4 and archobj: - if DEBUG: print(" skipped.") + if preferences['DEBUG']: print(" (arch)",end="") + if preferences['MERGE_MODE_ARCH'] == 4 and archobj: + if preferences['DEBUG']: print(" skipped.") continue - if MERGE_MODE_STRUCT == 3 and not archobj: - if DEBUG: print(" skipped.") + if preferences['MERGE_MODE_STRUCT'] == 3 and not archobj: + if preferences['DEBUG']: print(" skipped.") continue if pid in skip: # user given id skip list - if DEBUG: print(" skipped.") + if preferences['DEBUG']: print(" skipped.") continue - if ptype in SKIP: # preferences-set type skip list - if DEBUG: print(" skipped.") + if ptype in preferences['SKIP']: # preferences-set type skip list + if preferences['DEBUG']: print(" skipped.") continue # check if this object is sharing its shape (mapped representation) @@ -376,8 +370,8 @@ def insert(filename,docname,skip=[],only=[],root=None): try: prepr = product.Representation except: - if DEBUG: print(" ERROR unable to get object representation",end="") - if prepr and (MERGE_MODE_ARCH == 0) and archobj and CREATE_CLONES: + if preferences['DEBUG']: print(" ERROR unable to get object representation",end="") + if prepr and (preferences['MERGE_MODE_ARCH'] == 0) and archobj and preferences['CREATE_CLONES']: for r in prepr.Representations: if r.RepresentationIdentifier.upper() == "BODY": if r.Items[0].is_a("IfcMappedItem"): @@ -402,7 +396,7 @@ def insert(filename,docname,skip=[],only=[],root=None): # from now on we have a brep string if brep: - if DEBUG: print(" "+str(int(len(brep)/1000))+"k ",end="") + if preferences['DEBUG']: print(" "+str(int(len(brep)/1000))+"k ",end="") # create a Part shape shape = Part.Shape() @@ -410,19 +404,19 @@ def insert(filename,docname,skip=[],only=[],root=None): shape.scale(1000.0) # IfcOpenShell always outputs in meters, we convert to mm, the freecad internal unit if shape.isNull(): - if DEBUG: print("null shape ",end="") + if preferences['DEBUG']: print("null shape ",end="") elif not shape.isValid(): - if DEBUG: print("invalid shape ",end="") + if preferences['DEBUG']: print("invalid shape ",end="") else: # add to the global boundbox if applicable - if FITVIEW_ONIMPORT and FreeCAD.GuiUp: + if preferences['FITVIEW_ONIMPORT'] and FreeCAD.GuiUp: try: bb = shape.BoundBox - # if DEBUG: print(' ' + str(bb),end="") + # if preferences['DEBUG']: print(' ' + str(bb),end="") except: bb = None - if DEBUG: print(' BB could not be computed',end="") + if preferences['DEBUG']: print(' BB could not be computed',end="") if bb and bb.isValid(): if not overallboundbox: overallboundbox = bb @@ -430,27 +424,27 @@ def insert(filename,docname,skip=[],only=[],root=None): FreeCADGui.SendMsgToActiveView("ViewFit") overallboundbox.add(bb) - if (MERGE_MODE_ARCH > 0 and archobj) or structobj: + if (preferences['MERGE_MODE_ARCH'] > 0 and archobj) or structobj: # we are not using Arch objects # additional tweaks to set when not using Arch objects if ptype == "IfcSpace": # do not add spaces to compounds - if DEBUG: print("skipping space ",pid,end="") + if preferences['DEBUG']: print("skipping space ",pid,end="") elif structobj: structshapes[pid] = shape - if DEBUG: print(len(shape.Solids),"solids ",end="") + if preferences['DEBUG']: print(len(shape.Solids),"solids ",end="") baseobj = shape else: shapes[pid] = shape - if DEBUG: print(len(shape.Solids),"solids ",end="") + if preferences['DEBUG']: print(len(shape.Solids),"solids ",end="") baseobj = shape else: # create base shape object if clone: - if DEBUG: print("clone ",end="") + if preferences['DEBUG']: print("clone ",end="") else: - if GET_EXTRUSIONS and (MERGE_MODE_ARCH != 1): + if preferences['GET_EXTRUSIONS'] and (preferences['MERGE_MODE_ARCH'] != 1): # recompose extrusions from a shape if ptype in ["IfcWall","IfcWallStandardCase","IfcSpace"]: @@ -528,11 +522,11 @@ def insert(filename,docname,skip=[],only=[],root=None): baseobj.Shape = shape else: # this object has no shape (storeys, etc...) - if DEBUG: print(" no brep ",end="") + if preferences['DEBUG']: print(" no brep ",end="") # we now have the shape, we create the final object - if MERGE_MODE_ARCH == 0 and archobj: + if preferences['MERGE_MODE_ARCH'] == 0 and archobj: # full Arch objects @@ -598,7 +592,7 @@ def insert(filename,docname,skip=[],only=[],root=None): # set additional properties obj.Label = name - if DEBUG: print(": "+obj.Label+" ",end="") + if preferences['DEBUG']: print(": "+obj.Label+" ",end="") if hasattr(obj,"Description") and hasattr(product,"Description"): if product.Description: obj.Description = product.Description @@ -638,7 +632,7 @@ def insert(filename,docname,skip=[],only=[],root=None): if obj: # print number of solids - if DEBUG: + if preferences['DEBUG']: s = "" if hasattr(obj,"Shape"): if obj.Shape.Solids: @@ -646,7 +640,7 @@ def insert(filename,docname,skip=[],only=[],root=None): print(s,end="") objects[pid] = obj - elif (MERGE_MODE_ARCH == 1 and archobj) or (MERGE_MODE_STRUCT == 0 and not archobj): + elif (preferences['MERGE_MODE_ARCH'] == 1 and archobj) or (preferences['MERGE_MODE_STRUCT'] == 0 and not archobj): # non-parametric Arch objects (just Arch components with a shape) @@ -660,7 +654,7 @@ def insert(filename,docname,skip=[],only=[],root=None): elif baseobj: obj = Arch.makeComponent(baseobj,name=name,delete=True) obj.Label = name - if DEBUG: print(": "+obj.Label+" ",end="") + if preferences['DEBUG']: print(": "+obj.Label+" ",end="") if hasattr(obj,"Description") and hasattr(product,"Description"): if product.Description: obj.Description = product.Description @@ -674,7 +668,7 @@ def insert(filename,docname,skip=[],only=[],root=None): a["IfcUID"] = str(guid) obj.IfcData = a - elif (MERGE_MODE_ARCH == 2 and archobj) or (MERGE_MODE_STRUCT == 1 and not archobj): + elif (preferences['MERGE_MODE_ARCH'] == 2 and archobj) or (preferences['MERGE_MODE_STRUCT'] == 1 and not archobj): # Part shapes @@ -689,7 +683,7 @@ def insert(filename,docname,skip=[],only=[],root=None): obj = FreeCAD.ActiveDocument.addObject("Part::Feature",name) obj.Shape = shape - if DEBUG: print("") # newline for debug prints, print for a new object should be on a new line + if preferences['DEBUG']: print("") # newline for debug prints, print for a new object should be on a new line if obj: @@ -700,7 +694,7 @@ def insert(filename,docname,skip=[],only=[],root=None): if psets: - if IMPORT_PROPERTIES and hasattr(obj,"IfcProperties"): + if preferences['IMPORT_PROPERTIES'] and hasattr(obj,"IfcProperties"): # treat as spreadsheet (pref option) @@ -715,13 +709,13 @@ def insert(filename,docname,skip=[],only=[],root=None): n = 2 for c in psets.keys(): o = ifcfile[c] - if DEBUG: print("propertyset Name",o.Name,type(o.Name)) + if preferences['DEBUG']: print("propertyset Name",o.Name,type(o.Name)) catname = o.Name for p in psets[c]: l = ifcfile[p] lname = l.Name if l.is_a("IfcPropertySingleValue"): - if DEBUG: + if preferences['DEBUG']: print("property name",l.Name,type(l.Name)) if six.PY2: catname = catname.encode("utf8") @@ -729,7 +723,7 @@ def insert(filename,docname,skip=[],only=[],root=None): ifc_spreadsheet.set(str('A'+str(n)), catname) ifc_spreadsheet.set(str('B'+str(n)), lname) if l.NominalValue: - if DEBUG: + if preferences['DEBUG']: print("property NominalValue",l.NominalValue.is_a(),type(l.NominalValue.is_a())) print("property NominalValue.wrappedValue",l.NominalValue.wrappedValue,type(l.NominalValue.wrappedValue)) #print("l.NominalValue.Unit",l.NominalValue.Unit,type(l.NominalValue.Unit)) @@ -768,11 +762,11 @@ def insert(filename,docname,skip=[],only=[],root=None): # color if FreeCAD.GuiUp and (pid in colors) and hasattr(obj.ViewObject,"ShapeColor"): - #if DEBUG: print(" setting color: ",int(colors[pid][0]*255),"/",int(colors[pid][1]*255),"/",int(colors[pid][2]*255)) + #if preferences['DEBUG']: print(" setting color: ",int(colors[pid][0]*255),"/",int(colors[pid][1]*255),"/",int(colors[pid][2]*255)) obj.ViewObject.ShapeColor = colors[pid] - # if DEBUG is on, recompute after each shape - if DEBUG: FreeCAD.ActiveDocument.recompute() + # if preferences['DEBUG'] is on, recompute after each shape + if preferences['DEBUG']: FreeCAD.ActiveDocument.recompute() # attached 2D elements @@ -820,9 +814,9 @@ def insert(filename,docname,skip=[],only=[],root=None): progressbar.stop() FreeCAD.ActiveDocument.recompute() - if MERGE_MODE_STRUCT == 2: + if preferences['MERGE_MODE_STRUCT'] == 2: - if DEBUG: print("Joining Structural shapes...",end="") + if preferences['DEBUG']: print("Joining Structural shapes...",end="") for host,children in groups.items(): # Structural if ifcfile[host].is_a("IfcStructuralAnalysisModel"): @@ -833,7 +827,7 @@ def insert(filename,docname,skip=[],only=[],root=None): del structshapes[c] if compound: name = ifcfile[host].Name or "AnalysisModel" - if PREFIX_NUMBERS: name = "ID" + str(host) + " " + name + if preferences['PREFIX_NUMBERS']: name = "ID" + str(host) + " " + name obj = FreeCAD.ActiveDocument.addObject("Part::Feature",name) obj.Label = name obj.Shape = Part.makeCompound(compound) @@ -841,11 +835,11 @@ def insert(filename,docname,skip=[],only=[],root=None): obj = FreeCAD.ActiveDocument.addObject("Part::Feature","UnclaimedStruct") obj.Shape = Part.makeCompound(structshapes.values()) - if DEBUG: print("done") + if preferences['DEBUG']: print("done") else: - if DEBUG: print("Processing Struct relationships...",end="") + if preferences['DEBUG']: print("Processing Struct relationships...",end="") # groups @@ -864,13 +858,13 @@ def insert(filename,docname,skip=[],only=[],root=None): for c in childs_to_delete: children.remove(c) # to not process the child again in remaining groups if cobs: - if DEBUG: print("adding ",len(cobs), " object(s) to ", objects[host].Label) + if preferences['DEBUG']: print("adding ",len(cobs), " object(s) to ", objects[host].Label) Arch.addComponents(cobs,objects[host]) - if DEBUG: FreeCAD.ActiveDocument.recompute() + if preferences['DEBUG']: FreeCAD.ActiveDocument.recompute() - if DEBUG: print("done") + if preferences['DEBUG']: print("done") - if MERGE_MODE_ARCH > 2: # if ArchObj is compound or ArchObj not imported + if preferences['MERGE_MODE_ARCH'] > 2: # if ArchObj is compound or ArchObj not imported FreeCAD.ActiveDocument.recompute() # cleaning bad shapes @@ -888,7 +882,7 @@ def insert(filename,docname,skip=[],only=[],root=None): if ifcfile[host].Name: grp_name = ifcfile[host].Name else: - if DEBUG: print("no group name specified for entity: #", ifcfile[host].id(), ", entity type is used!") + if preferences['DEBUG']: print("no group name specified for entity: #", ifcfile[host].id(), ", entity type is used!") grp_name = ifcfile[host].is_a() + "_" + str(ifcfile[host].id()) if six.PY2: grp_name = grp_name.encode("utf8") @@ -902,11 +896,11 @@ def insert(filename,docname,skip=[],only=[],root=None): else: remaining[child] = grp - if MERGE_MODE_ARCH == 3: + if preferences['MERGE_MODE_ARCH'] == 3: # One compound per storey - if DEBUG: print("Joining Arch shapes...",end="") + if preferences['DEBUG']: print("Joining Arch shapes...",end="") for host,children in additions.items(): # Arch if ifcfile[host].is_a("IfcBuildingStorey"): @@ -922,7 +916,7 @@ def insert(filename,docname,skip=[],only=[],root=None): del shapes[c2] if compound: name = ifcfile[host].Name or "Floor" - if PREFIX_NUMBERS: name = "ID" + str(host) + " " + name + if preferences['PREFIX_NUMBERS']: name = "ID" + str(host) + " " + name obj = FreeCAD.ActiveDocument.addObject("Part::Feature",name) obj.Label = name obj.Shape = Part.makeCompound(compound) @@ -930,24 +924,24 @@ def insert(filename,docname,skip=[],only=[],root=None): obj = FreeCAD.ActiveDocument.addObject("Part::Feature","UnclaimedArch") obj.Shape = Part.makeCompound(shapes.values()) - if DEBUG: print("done") + if preferences['DEBUG']: print("done") else: - if DEBUG: print("Processing Arch relationships...",end="") + if preferences['DEBUG']: print("Processing Arch relationships...",end="") first = True # subtractions - if SEPARATE_OPENINGS: + if preferences['SEPARATE_OPENINGS']: for subtraction in subtractions: if (subtraction[0] in objects.keys()) and (subtraction[1] in objects.keys()): - if DEBUG and first: + if preferences['DEBUG'] and first: print("") first = False - if DEBUG: print(" subtracting",objects[subtraction[0]].Label, "from", objects[subtraction[1]].Label) + if preferences['DEBUG']: print(" subtracting",objects[subtraction[0]].Label, "from", objects[subtraction[1]].Label) Arch.removeComponents(objects[subtraction[0]],objects[subtraction[1]]) - if DEBUG: FreeCAD.ActiveDocument.recompute() + if preferences['DEBUG']: FreeCAD.ActiveDocument.recompute() # additions @@ -961,18 +955,18 @@ def insert(filename,docname,skip=[],only=[],root=None): cobs.append(objects[child]) if not cobs: continue - if DEBUG and first: + if preferences['DEBUG'] and first: print("") first = False - if DEBUG and (len(cobs) > 10) and (not(Draft.getType(objects[host]) in ["Site","Building","Floor","BuildingPart","Project"])): + if preferences['DEBUG'] and (len(cobs) > 10) and (not(Draft.getType(objects[host]) in ["Site","Building","Floor","BuildingPart","Project"])): # avoid huge fusions print("more than 10 shapes to add: skipping.") else: - if DEBUG: print(" adding",len(cobs), "object(s) to", objects[host].Label) + if preferences['DEBUG']: print(" adding",len(cobs), "object(s) to", objects[host].Label) Arch.addComponents(cobs,objects[host]) - if DEBUG: FreeCAD.ActiveDocument.recompute() + if preferences['DEBUG']: FreeCAD.ActiveDocument.recompute() - if DEBUG and first: print("done.") + if preferences['DEBUG'] and first: print("done.") FreeCAD.ActiveDocument.recompute() @@ -987,7 +981,7 @@ def insert(filename,docname,skip=[],only=[],root=None): # 2D elements - if DEBUG and annotations: + if preferences['DEBUG'] and annotations: print("Processing",len(annotations),"2D objects...") prodcount = count count = 0 @@ -998,11 +992,11 @@ def insert(filename,docname,skip=[],only=[],root=None): aid = annotation.id() count += 1 - if DEBUG: print(count,"/",len(annotations),"object #"+str(aid),":",annotation.is_a(),end="") + if preferences['DEBUG']: print(count,"/",len(annotations),"object #"+str(aid),":",annotation.is_a(),end="") if aid in skip: continue # user given id skip list - if annotation.is_a() in SKIP: + if annotation.is_a() in preferences['SKIP']: continue # preferences-set type skip list if annotation.is_a("IfcGrid"): axes = [] @@ -1033,7 +1027,7 @@ def insert(filename,docname,skip=[],only=[],root=None): name = annotation.Name if six.PY2: name = name.encode("utf8") - if PREFIX_NUMBERS: + if preferences['PREFIX_NUMBERS']: name = "ID" + str(aid) + " " + name anno = Arch.makeAxisSystem(axes,name) print(" axis") @@ -1045,7 +1039,7 @@ def insert(filename,docname,skip=[],only=[],root=None): name = name.encode("utf8") if "annotation" not in name.lower(): name = "Annotation " + name - if PREFIX_NUMBERS: name = "ID" + str(aid) + " " + name + if preferences['PREFIX_NUMBERS']: name = "ID" + str(aid) + " " + name shapes2d = [] for rep in annotation.Representation.Representations: if rep.RepresentationIdentifier in ["Annotation","FootPrint","Axis"]: @@ -1057,14 +1051,14 @@ def insert(filename,docname,skip=[],only=[],root=None): shapes2d.extend(sh) if shapes2d: sh = Part.makeCompound(shapes2d) - if DEBUG: print(" shape") + if preferences['DEBUG']: print(" shape") anno = FreeCAD.ActiveDocument.addObject("Part::Feature",name) anno.Shape = sh p = importIFCHelper.getPlacement(annotation.ObjectPlacement,ifcscale) if p: # and annotation.is_a("IfcAnnotation"): anno.Placement = p else: - if DEBUG: print(" no shape") + if preferences['DEBUG']: print(" no shape") # placing in container if needed @@ -1080,7 +1074,7 @@ def insert(filename,docname,skip=[],only=[],root=None): # Materials - if DEBUG and materials: print("Creating materials...",end="") + if preferences['DEBUG'] and materials: print("Creating materials...",end="") #print("mattable:",mattable) #print("materials:",materials) fcmats = {} @@ -1102,7 +1096,7 @@ def insert(filename,docname,skip=[],only=[],root=None): mdict["DiffuseColor"] = str(colors[o]) # merge materials with same name and color if setting in prefs is True add_material = True - if MERGE_MATERIALS: + if preferences['MERGE_MATERIALS']: for key in list(fcmats.keys()): if key.startswith(name) \ and "DiffuseColor" in mdict and "DiffuseColor" in fcmats[key].Material \ @@ -1145,7 +1139,7 @@ def insert(filename,docname,skip=[],only=[],root=None): # print(" ", o, ": ", colors[o]) # print(" ", m, ": ", colors[m]) - if DEBUG and materials: print("done") + if preferences['DEBUG'] and materials: print("done") # restore links from full parametric definitions for p in parametrics: From 0f714e00f1eedbb2cfb2e8eea77ef9c053af4d2b Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Thu, 22 Aug 2019 16:44:00 -0300 Subject: [PATCH 06/19] AddonManager: Added function to check for updates for a specific addon --- src/Mod/AddonManager/AddonManager.py | 9 ++++++ src/Mod/AddonManager/addonmanager_workers.py | 33 ++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/Mod/AddonManager/AddonManager.py b/src/Mod/AddonManager/AddonManager.py index affd955280..31bde2ca53 100644 --- a/src/Mod/AddonManager/AddonManager.py +++ b/src/Mod/AddonManager/AddonManager.py @@ -587,4 +587,13 @@ class CommandAddonManager: pref.SetBool("AutoCheck",self.config.checkUpdates.isChecked()) pref.SetString("CustomRepositories",self.config.customRepositories.toPlainText()) +def check_updates(addon_name,callback): + + """Checks for updates for a given addon""" + + oname = "update_checker_"+addon_name + setattr(FreeCAD,oname,CheckSingleWorker(addon_name)) + getattr(FreeCAD,oname).updateAvailable.connect(callback) + getattr(FreeCAD,oname).start() + ## @} diff --git a/src/Mod/AddonManager/addonmanager_workers.py b/src/Mod/AddonManager/addonmanager_workers.py index 87e9b26c2d..ddf9f54a60 100644 --- a/src/Mod/AddonManager/addonmanager_workers.py +++ b/src/Mod/AddonManager/addonmanager_workers.py @@ -713,3 +713,36 @@ class InstallWorker(QtCore.QThread): if bakdir: shutil.rmtree(bakdir) return translate("AddonsInstaller", "Successfully installed") + " " + zipurl + + +class CheckSingleWorker(QtCore.QThread): + + """Worker to check for updates for a single addon""" + + updateAvailable = QtCore.Signal(bool) + + def __init__(self, name): + + QtCore.QThread.__init__(self) + self.name = name + + def run(self): + + try: + import git + except: + return + FreeCAD.Console.PrintLog("Checking for available updates of the "+name+" addon\n") + addondir = os.path.join(FreeCAD.getUserAppDataDir(),"Mod",name) + if os.path.exists(addondir): + if os.path.exists(addondir + os.sep + '.git'): + gitrepo = git.Git(addondir) + try: + gitrepo.fetch() + if "git pull" in gitrepo.status(): + self.updateAvailable.emit(True) + return + except: + # can fail for any number of reasons, ex. not being online + pass + self.updateAvailable.emit(False) From b5464ccf4d180c09da3d6754413899ccfaa1fcff Mon Sep 17 00:00:00 2001 From: wandererfan Date: Mon, 22 Jul 2019 11:48:40 -0400 Subject: [PATCH 07/19] [TD]Add uuid tags for cosmetics --- src/Mod/TechDraw/App/CenterLinePy.xml | 6 + src/Mod/TechDraw/App/CenterLinePyImp.cpp | 8 +- src/Mod/TechDraw/App/Cosmetic.cpp | 161 ++++++++++++++++++- src/Mod/TechDraw/App/Cosmetic.h | 35 +++- src/Mod/TechDraw/App/CosmeticEdgePy.xml | 6 + src/Mod/TechDraw/App/CosmeticEdgePyImp.cpp | 6 + src/Mod/TechDraw/App/CosmeticVertexPy.xml | 6 + src/Mod/TechDraw/App/CosmeticVertexPyImp.cpp | 7 + src/Mod/TechDraw/App/GeomFormatPy.xml | 6 + src/Mod/TechDraw/App/GeomFormatPyImp.cpp | 29 +--- src/Mod/TechDraw/App/PreCompiled.h | 1 + 11 files changed, 236 insertions(+), 35 deletions(-) diff --git a/src/Mod/TechDraw/App/CenterLinePy.xml b/src/Mod/TechDraw/App/CenterLinePy.xml index 8361d17f91..fe3f099244 100644 --- a/src/Mod/TechDraw/App/CenterLinePy.xml +++ b/src/Mod/TechDraw/App/CenterLinePy.xml @@ -36,5 +36,11 @@ returns the appearance attributes of this CenterLine. returns tuple(style, color, weight, visible). + + + Gives the tag of the CenterLine as string. + + + diff --git a/src/Mod/TechDraw/App/CenterLinePyImp.cpp b/src/Mod/TechDraw/App/CenterLinePyImp.cpp index 2558b23092..5b546d33b1 100644 --- a/src/Mod/TechDraw/App/CenterLinePyImp.cpp +++ b/src/Mod/TechDraw/App/CenterLinePyImp.cpp @@ -24,7 +24,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ -//# include +# include #endif #include "DrawUtil.h" @@ -167,6 +167,12 @@ PyObject* CenterLinePy::getFormat(PyObject *args) return result; } +Py::String CenterLinePy::getTag(void) const +{ + std::string tmp = boost::uuids::to_string(getCenterLinePtr()->getTag()); + return Py::String(tmp); +} + PyObject *CenterLinePy::getCustomAttributes(const char* /*attr*/) const { return 0; diff --git a/src/Mod/TechDraw/App/Cosmetic.cpp b/src/Mod/TechDraw/App/Cosmetic.cpp index c5fd2ee87a..0d89a8c14a 100644 --- a/src/Mod/TechDraw/App/Cosmetic.cpp +++ b/src/Mod/TechDraw/App/Cosmetic.cpp @@ -145,6 +145,8 @@ CosmeticVertex::CosmeticVertex() : TechDraw::Vertex() size = 3.0; style = 1; visible = true; + + createNewTag(); } CosmeticVertex::CosmeticVertex(const TechDraw::CosmeticVertex* cv) : TechDraw::Vertex(cv) @@ -154,6 +156,8 @@ CosmeticVertex::CosmeticVertex(const TechDraw::CosmeticVertex* cv) : TechDraw::V size = cv->size; style = cv->style; visible = cv->visible; + + createNewTag(); } CosmeticVertex::CosmeticVertex(Base::Vector3d loc) : TechDraw::Vertex(loc) @@ -169,6 +173,9 @@ CosmeticVertex::CosmeticVertex(Base::Vector3d loc) : TechDraw::Vertex(loc) size = 30.0; style = 1; //TODO: implement styled vertexes visible = true; + + createNewTag(); + } std::string CosmeticVertex::toString(void) const @@ -219,6 +226,40 @@ void CosmeticVertex::Restore(Base::XMLReader &reader) visible = (int)reader.getAttributeAsInteger("value")==0?false:true; } +boost::uuids::uuid CosmeticVertex::getTag() const +{ + return tag; +} + +std::string CosmeticVertex::getTagAsString(void) const +{ + std::string tmp = boost::uuids::to_string(getTag()); + return tmp; +} + +void CosmeticVertex::createNewTag() +{ + // Initialize a random number generator, to avoid Valgrind false positives. + static boost::mt19937 ran; + static bool seeded = false; + + if (!seeded) { + ran.seed(static_cast(std::time(0))); + seeded = true; + } + static boost::uuids::basic_random_generator gen(&ran); + + tag = gen(); +} + +void CosmeticVertex::assignTag(const TechDraw::CosmeticVertex * cv) +{ + if(cv->getTypeId() == this->getTypeId()) + this->tag = cv->tag; + else + throw Base::TypeError("CosmeticVertex tag can not be assigned as types do not match."); +} + CosmeticVertex* CosmeticVertex::copy(void) const { // Base::Console().Message("CV::copy()\n"); @@ -230,6 +271,7 @@ CosmeticVertex* CosmeticVertex::clone(void) const { // Base::Console().Message("CV::clone()\n"); CosmeticVertex* cpy = this->copy(); + cpy->tag = this->tag; return cpy; } @@ -304,6 +346,9 @@ void CosmeticEdge::initialize(void) m_geometry->classOfEdge = ecHARD; m_geometry->visible = true; m_geometry->cosmetic = true; + + createNewTag(); + } TechDraw::BaseGeom* CosmeticEdge::scaledGeometry(double scale) @@ -402,6 +447,34 @@ void CosmeticEdge::Restore(Base::XMLReader &reader) } } +boost::uuids::uuid CosmeticEdge::getTag() const +{ + return tag; +} + +void CosmeticEdge::createNewTag() +{ + // Initialize a random number generator, to avoid Valgrind false positives. + static boost::mt19937 ran; + static bool seeded = false; + + if (!seeded) { + ran.seed(static_cast(std::time(0))); + seeded = true; + } + static boost::uuids::basic_random_generator gen(&ran); + + tag = gen(); +} + +void CosmeticEdge::assignTag(const TechDraw::CosmeticEdge * ce) +{ + if(ce->getTypeId() == this->getTypeId()) + this->tag = ce->tag; + else + throw Base::TypeError("CosmeticEdge tag can not be assigned as types do not match."); +} + CosmeticEdge* CosmeticEdge::copy(void) const { // Base::Console().Message("CE::copy()\n"); @@ -416,6 +489,7 @@ CosmeticEdge* CosmeticEdge::clone(void) const { // Base::Console().Message("CE::clone()\n"); CosmeticEdge* cpy = this->copy(); + cpy->tag = this->tag; return cpy; } @@ -440,6 +514,7 @@ CenterLine::CenterLine(void) m_type = CLTYPE::FACE; m_flip2Line = false; + createNewTag(); } CenterLine::CenterLine(CenterLine* cl) @@ -457,6 +532,8 @@ CenterLine::CenterLine(CenterLine* cl) m_flip2Line = cl->m_flip2Line; m_edges = cl->m_edges; m_verts = cl->m_verts; + + createNewTag(); } CenterLine::CenterLine(Base::Vector3d p1, Base::Vector3d p2) @@ -470,6 +547,8 @@ CenterLine::CenterLine(Base::Vector3d p1, Base::Vector3d p2) m_extendBy = 0.0; m_type = CLTYPE::FACE; m_flip2Line = false; + + createNewTag(); } CenterLine::CenterLine(Base::Vector3d p1, Base::Vector3d p2, @@ -488,6 +567,8 @@ CenterLine::CenterLine(Base::Vector3d p1, Base::Vector3d p2, m_extendBy = x; m_type = CLTYPE::FACE; m_flip2Line = false; + + createNewTag(); } CenterLine::~CenterLine() @@ -1102,9 +1183,39 @@ CenterLine* CenterLine::copy(void) const return newCL; } -CenterLine* CenterLine::clone(void) const +boost::uuids::uuid CenterLine::getTag() const +{ + return tag; +} + +void CenterLine::createNewTag() +{ + // Initialize a random number generator, to avoid Valgrind false positives. + static boost::mt19937 ran; + static bool seeded = false; + + if (!seeded) { + ran.seed(static_cast(std::time(0))); + seeded = true; + } + static boost::uuids::basic_random_generator gen(&ran); + + tag = gen(); +} + +void CenterLine::assignTag(const TechDraw::CenterLine * ce) +{ + if(ce->getTypeId() == this->getTypeId()) + this->tag = ce->tag; + else + throw Base::TypeError("CenterLine tag can not be assigned as types do not match."); +} + +CenterLine *CenterLine::clone(void) const { CenterLine* cpy = this->copy(); + cpy->tag = this->tag; + return cpy; } @@ -1169,6 +1280,8 @@ GeomFormat::GeomFormat() : m_format.m_weight = LineFormat::getDefEdgeWidth(); m_format.m_color = LineFormat::getDefEdgeColor(); m_format.m_visible = true; + + createNewTag(); } GeomFormat::GeomFormat(GeomFormat* gf) @@ -1178,6 +1291,8 @@ GeomFormat::GeomFormat(GeomFormat* gf) m_format.m_weight = gf->m_format.m_weight; m_format.m_color = gf->m_format.m_color; m_format.m_visible = gf->m_format.m_visible; + + createNewTag(); } GeomFormat::GeomFormat(int idx, @@ -1189,6 +1304,7 @@ GeomFormat::GeomFormat(int idx, m_format.m_color = fmt.m_color; m_format.m_visible = fmt.m_visible; + createNewTag(); } GeomFormat::~GeomFormat() @@ -1243,6 +1359,42 @@ void GeomFormat::Restore(Base::XMLReader &reader) m_format.m_visible = (int)reader.getAttributeAsInteger("value")==0?false:true; } +boost::uuids::uuid GeomFormat::getTag() const +{ + return tag; +} + +void GeomFormat::createNewTag() +{ + // Initialize a random number generator, to avoid Valgrind false positives. + static boost::mt19937 ran; + static bool seeded = false; + + if (!seeded) { + ran.seed(static_cast(std::time(0))); + seeded = true; + } + static boost::uuids::basic_random_generator gen(&ran); + + tag = gen(); +} + +void GeomFormat::assignTag(const TechDraw::GeomFormat * ce) +{ + if(ce->getTypeId() == this->getTypeId()) + this->tag = ce->tag; + else + throw Base::TypeError("GeomFormat tag can not be assigned as types do not match."); +} + +GeomFormat *GeomFormat::clone(void) const +{ + GeomFormat* cpy = this->copy(); + cpy->tag = this->tag; + + return cpy; +} + GeomFormat* GeomFormat::copy(void) const { GeomFormat* newFmt = new GeomFormat(); @@ -1254,15 +1406,8 @@ GeomFormat* GeomFormat::copy(void) const return newFmt; } -GeomFormat* GeomFormat::clone(void) const -{ - GeomFormat* cpy = this->copy(); - return cpy; -} - PyObject* GeomFormat::getPyObject(void) { return new GeomFormatPy(new GeomFormat(this->copy())); } - diff --git a/src/Mod/TechDraw/App/Cosmetic.h b/src/Mod/TechDraw/App/Cosmetic.h index c9df65c008..8e1dc297ab 100644 --- a/src/Mod/TechDraw/App/Cosmetic.h +++ b/src/Mod/TechDraw/App/Cosmetic.h @@ -23,6 +23,11 @@ #ifndef TECHDRAW_COSMETIC_H #define TECHDRAW_COSMETIC_H +# include + +#include +#include + #include #include @@ -57,7 +62,6 @@ public: void dump(char* title); std::string toString() const; -/* bool fromCSV(std::string& lineSpec);*/ }; class TechDrawExport CosmeticVertex: public Base::Persistence, public TechDraw::Vertex @@ -89,7 +93,16 @@ public: int style; bool visible; + boost::uuids::uuid getTag() const; + std::string getTagAsString(void) const; + + protected: + //Uniqueness + void createNewTag(); + void assignTag(const TechDraw::CosmeticVertex* cv); + + boost::uuids::uuid tag; }; @@ -123,8 +136,14 @@ public: TechDraw::BaseGeom* m_geometry; LineFormat m_format; -protected: + boost::uuids::uuid getTag() const; +protected: + //Uniqueness + void createNewTag(); + void assignTag(const TechDraw::CosmeticEdge* ce); + + boost::uuids::uuid tag; }; class TechDrawExport CenterLine: public Base::Persistence @@ -216,7 +235,13 @@ public: LineFormat m_format; bool m_flip2Line; + //Uniqueness + boost::uuids::uuid getTag() const; protected: + void createNewTag(); + void assignTag(const TechDraw::CenterLine* cl); + + boost::uuids::uuid tag; }; @@ -241,14 +266,18 @@ public: GeomFormat* clone(void) const; std::string toString(void) const; -/* bool fromCSV(std::string& lineSpec);*/ void dump(char* title) const; int m_geomIndex; LineFormat m_format; + //Uniqueness + boost::uuids::uuid getTag() const; protected: + void createNewTag(); + void assignTag(const TechDraw::GeomFormat* gf); + boost::uuids::uuid tag; }; } //end namespace TechDraw diff --git a/src/Mod/TechDraw/App/CosmeticEdgePy.xml b/src/Mod/TechDraw/App/CosmeticEdgePy.xml index dad876be13..39a8119d8c 100644 --- a/src/Mod/TechDraw/App/CosmeticEdgePy.xml +++ b/src/Mod/TechDraw/App/CosmeticEdgePy.xml @@ -36,5 +36,11 @@ returns the appearance attributes of this CometicEdge. returns tuple(style, color, weight, visible). + + + Gives the tag of the CosmeticEdge as string. + + + diff --git a/src/Mod/TechDraw/App/CosmeticEdgePyImp.cpp b/src/Mod/TechDraw/App/CosmeticEdgePyImp.cpp index c5e61c12c7..4ae3061bd3 100644 --- a/src/Mod/TechDraw/App/CosmeticEdgePyImp.cpp +++ b/src/Mod/TechDraw/App/CosmeticEdgePyImp.cpp @@ -24,6 +24,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ +# include #endif #include @@ -169,6 +170,11 @@ PyObject* CosmeticEdgePy::getFormat(PyObject *args) return result; } +Py::String CosmeticEdgePy::getTag(void) const +{ + std::string tmp = boost::uuids::to_string(getCosmeticEdgePtr()->getTag()); + return Py::String(tmp); +} PyObject *CosmeticEdgePy::getCustomAttributes(const char* /*attr*/) const { diff --git a/src/Mod/TechDraw/App/CosmeticVertexPy.xml b/src/Mod/TechDraw/App/CosmeticVertexPy.xml index e2033e5f2b..fb512c3db0 100644 --- a/src/Mod/TechDraw/App/CosmeticVertexPy.xml +++ b/src/Mod/TechDraw/App/CosmeticVertexPy.xml @@ -25,5 +25,11 @@ Create a copy of this CosmeticVertex + + + Gives the tag of the CosmeticVertex as string. + + + diff --git a/src/Mod/TechDraw/App/CosmeticVertexPyImp.cpp b/src/Mod/TechDraw/App/CosmeticVertexPyImp.cpp index 3e1fb94ece..7bab6e50de 100644 --- a/src/Mod/TechDraw/App/CosmeticVertexPyImp.cpp +++ b/src/Mod/TechDraw/App/CosmeticVertexPyImp.cpp @@ -24,6 +24,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ +# include #endif #include "Cosmetic.h" @@ -108,6 +109,12 @@ PyObject* CosmeticVertexPy::copy(PyObject *args) return cpy; } +Py::String CosmeticVertexPy::getTag(void) const +{ + std::string tmp = boost::uuids::to_string(getCosmeticVertexPtr()->getTag()); + return Py::String(tmp); +} + PyObject *CosmeticVertexPy::getCustomAttributes(const char* /*attr*/) const { return 0; diff --git a/src/Mod/TechDraw/App/GeomFormatPy.xml b/src/Mod/TechDraw/App/GeomFormatPy.xml index f0b971f2ae..2f399d425e 100644 --- a/src/Mod/TechDraw/App/GeomFormatPy.xml +++ b/src/Mod/TechDraw/App/GeomFormatPy.xml @@ -25,5 +25,11 @@ Create a copy of this geomformat + + + Gives the tag of the GeomFormat as string. + + + diff --git a/src/Mod/TechDraw/App/GeomFormatPyImp.cpp b/src/Mod/TechDraw/App/GeomFormatPyImp.cpp index c884d4f9ee..4a0d8f167b 100644 --- a/src/Mod/TechDraw/App/GeomFormatPyImp.cpp +++ b/src/Mod/TechDraw/App/GeomFormatPyImp.cpp @@ -23,37 +23,14 @@ #include "PreCompiled.h" #ifndef _PreComp_ -//# include -//# include -//# include -//# include -//# include -//# include -//# include -//# include -//# include -//# include # include #endif -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include - -//#include "OCCError.h" #include "Cosmetic.h" #include "GeomFormatPy.h" #include "GeomFormatPy.cpp" -//#include "TopoShape.h" -//#include "TopoShapePy.h" - using namespace TechDraw; // returns a string which represents the object e.g. when printed in python @@ -130,6 +107,12 @@ PyObject* GeomFormatPy::copy(PyObject *args) return cpy; } +Py::String GeomFormatPy::getTag(void) const +{ + std::string tmp = boost::uuids::to_string(getGeomFormatPtr()->getTag()); + return Py::String(tmp); +} + PyObject *GeomFormatPy::getCustomAttributes(const char* /*attr*/) const { return 0; diff --git a/src/Mod/TechDraw/App/PreCompiled.h b/src/Mod/TechDraw/App/PreCompiled.h index c6bd3b8a20..9b8799a1b2 100644 --- a/src/Mod/TechDraw/App/PreCompiled.h +++ b/src/Mod/TechDraw/App/PreCompiled.h @@ -58,6 +58,7 @@ #include #include +#include // OpenCasCade ===================================================================================== #include From f046a0e6579f66f53ea705d604b1efa8a5801fd4 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Mon, 22 Jul 2019 20:57:45 -0400 Subject: [PATCH 08/19] [TD]Fix CosmeticEraser multiple item delete --- src/Mod/TechDraw/Gui/CommandAnnotate.cpp | 43 +++++++++++++++++++++--- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/src/Mod/TechDraw/Gui/CommandAnnotate.cpp b/src/Mod/TechDraw/Gui/CommandAnnotate.cpp index 1892742195..f3801c7a1f 100644 --- a/src/Mod/TechDraw/Gui/CommandAnnotate.cpp +++ b/src/Mod/TechDraw/Gui/CommandAnnotate.cpp @@ -1073,6 +1073,9 @@ void CmdTechDrawCosmeticEraser::activated(int iMsg) objFeat = static_cast ((*itSel).getObject()); SubNames = (*itSel).getSubNames(); } + std::vector cv2Delete; + std::vector ce2Delete; + std::vector cl2Delete; for (auto& s: SubNames) { int idx = TechDraw::DrawUtil::getIndexFromName(s); std::string geomType = TechDraw::DrawUtil::getGeomTypeFromName(s); @@ -1083,24 +1086,54 @@ void CmdTechDrawCosmeticEraser::activated(int iMsg) int source = bg->source(); int sourceIndex = bg->sourceIndex(); if (source == 1) { //this is a "CosmeticEdge" - objFeat->removeCosmeticEdge(sourceIndex); + ce2Delete.push_back(sourceIndex); } else if (source == 2) { //this is a "CenterLine" - objFeat->removeCenterLine(sourceIndex); + cl2Delete.push_back(sourceIndex); } else { Base::Console().Message( "CMD::CosmeticEraserP - edge: %d is confused - source: %d\n",idx,source); } } } else if (geomType == "Vertex") { - TechDraw::CosmeticVertex* cv = objFeat->getCosmeticVertexByGeom(idx); - if (cv != nullptr) { - objFeat->removeCosmeticVertex(cv); + TechDraw::Vertex* tdv = objFeat->getProjVertexByIndex(idx); + if (tdv != nullptr) { + int delIndex = tdv->cosmeticLink; + if (!(delIndex < 0)) { + cv2Delete.push_back(delIndex); + } else { + Base::Console().Message("CMD::eraser - geom: %d has no cv\n", idx); + } + } else { + Base::Console().Message("CMD::eraser - geom: %d not found!\n", idx); } } else { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Unknown object type in selection")); return; } + + } + // delete items in reverse order so as not to invalidate indices + if (!cv2Delete.empty()) { + std::sort(cv2Delete.begin(), cv2Delete.end()); + auto it = cv2Delete.rbegin(); + for ( ; it != cv2Delete.rend(); it++) { + objFeat->removeCosmeticVertex((*it)); + } + } + if (!ce2Delete.empty()) { + std::sort(ce2Delete.begin(), ce2Delete.end()); + auto itce = ce2Delete.rbegin(); + for ( ; itce != ce2Delete.rend(); itce++) { + objFeat->removeCosmeticEdge((*itce)); + } + } + if (!cl2Delete.empty()) { + std::sort(cl2Delete.begin(), cl2Delete.end()); + auto itcl = cl2Delete.rbegin(); + for ( ; itcl != cl2Delete.rend(); itcl++) { + objFeat->removeCenterLine((*itcl)); + } } } } From 992ef1b07e4c7ed9078e11beaf1dff78ca9bff05 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Tue, 23 Jul 2019 21:24:14 -0400 Subject: [PATCH 09/19] [TD]Welding Symbol creation --- src/Mod/TechDraw/App/AppTechDraw.cpp | 9 + src/Mod/TechDraw/App/CMakeLists.txt | 22 + src/Mod/TechDraw/App/DrawLeaderLine.cpp | 46 ++ src/Mod/TechDraw/App/DrawLeaderLine.h | 4 + src/Mod/TechDraw/App/DrawTile.cpp | 118 ++++ src/Mod/TechDraw/App/DrawTile.h | 65 +++ src/Mod/TechDraw/App/DrawTilePy.xml | 18 + src/Mod/TechDraw/App/DrawTilePyImp.cpp | 54 ++ src/Mod/TechDraw/App/DrawTileWeld.cpp | 103 ++++ src/Mod/TechDraw/App/DrawTileWeld.h | 68 +++ src/Mod/TechDraw/App/DrawTileWeldPy.xml | 18 + src/Mod/TechDraw/App/DrawTileWeldPyImp.cpp | 54 ++ src/Mod/TechDraw/App/DrawWeldSymbol.cpp | 136 +++++ src/Mod/TechDraw/App/DrawWeldSymbol.h | 72 +++ src/Mod/TechDraw/App/DrawWeldSymbolPy.xml | 18 + src/Mod/TechDraw/App/DrawWeldSymbolPyImp.cpp | 67 +++ src/Mod/TechDraw/CMakeLists.txt | 11 +- src/Mod/TechDraw/Gui/AppTechDrawGui.cpp | 4 + src/Mod/TechDraw/Gui/CMakeLists.txt | 15 + src/Mod/TechDraw/Gui/CommandAnnotate.cpp | 59 ++ src/Mod/TechDraw/Gui/MDIViewPage.cpp | 4 + src/Mod/TechDraw/Gui/QGCustomText.cpp | 81 ++- src/Mod/TechDraw/Gui/QGCustomText.h | 16 +- src/Mod/TechDraw/Gui/QGIArrow.cpp | 5 +- src/Mod/TechDraw/Gui/QGIDecoration.cpp | 35 ++ src/Mod/TechDraw/Gui/QGIDecoration.h | 9 + src/Mod/TechDraw/Gui/QGIEdge.cpp | 1 + src/Mod/TechDraw/Gui/QGILeaderLine.cpp | 7 + src/Mod/TechDraw/Gui/QGILeaderLine.h | 2 + src/Mod/TechDraw/Gui/QGIPrimPath.cpp | 17 +- src/Mod/TechDraw/Gui/QGIPrimPath.h | 5 + src/Mod/TechDraw/Gui/QGITile.cpp | 351 ++++++++++++ src/Mod/TechDraw/Gui/QGITile.h | 114 ++++ src/Mod/TechDraw/Gui/QGIUserTypes.h | 2 + src/Mod/TechDraw/Gui/QGIVertex.cpp | 14 +- src/Mod/TechDraw/Gui/QGIVertex.h | 8 +- src/Mod/TechDraw/Gui/QGIView.cpp | 10 +- src/Mod/TechDraw/Gui/QGIView.h | 11 +- src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp | 441 +++++++++++++++ src/Mod/TechDraw/Gui/QGIWeldSymbol.h | 120 ++++ src/Mod/TechDraw/Gui/QGVPage.cpp | 30 + src/Mod/TechDraw/Gui/QGVPage.h | 2 + src/Mod/TechDraw/Gui/Resources/TechDraw.qrc | 2 + .../Resources/icons/actions/techdraw-tile.svg | 158 ++++++ .../icons/actions/techdraw-weldsymbol.svg | 171 ++++++ src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp | 533 ++++++++++++++++++ src/Mod/TechDraw/Gui/TaskWeldingSymbol.h | 178 ++++++ src/Mod/TechDraw/Gui/TaskWeldingSymbol.ui | 398 +++++++++++++ .../TechDraw/Gui/ViewProviderDrawingView.cpp | 13 +- src/Mod/TechDraw/Gui/ViewProviderLeader.cpp | 4 + src/Mod/TechDraw/Gui/ViewProviderPage.cpp | 7 +- src/Mod/TechDraw/Gui/ViewProviderTile.cpp | 90 +++ src/Mod/TechDraw/Gui/ViewProviderTile.h | 59 ++ src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp | 1 + src/Mod/TechDraw/Gui/ViewProviderWeld.cpp | 110 ++++ src/Mod/TechDraw/Gui/ViewProviderWeld.h | 63 +++ src/Mod/TechDraw/Gui/Workbench.cpp | 5 +- .../Symbols/Welding/AWS/SquareDown.svg | 175 ++++++ .../TechDraw/Symbols/Welding/AWS/SquareUp.svg | 171 ++++++ .../TechDraw/Symbols/Welding/AWS/VDown.svg | 166 ++++++ src/Mod/TechDraw/Symbols/Welding/AWS/VUp.svg | 170 ++++++ .../TechDraw/Symbols/Welding/AWS/beadDown.svg | 152 +++++ .../TechDraw/Symbols/Welding/AWS/beadUp.svg | 152 +++++ .../Symbols/Welding/AWS/filletDown.svg | 151 +++++ .../TechDraw/Symbols/Welding/AWS/filletUp.svg | 151 +++++ .../Symbols/Welding/AWS/filletUpPlain.svg | 30 + src/Mod/TechDraw/Symbols/Welding/AWS/plug.svg | 151 +++++ 67 files changed, 5457 insertions(+), 50 deletions(-) create mode 100644 src/Mod/TechDraw/App/DrawTile.cpp create mode 100644 src/Mod/TechDraw/App/DrawTile.h create mode 100644 src/Mod/TechDraw/App/DrawTilePy.xml create mode 100644 src/Mod/TechDraw/App/DrawTilePyImp.cpp create mode 100644 src/Mod/TechDraw/App/DrawTileWeld.cpp create mode 100644 src/Mod/TechDraw/App/DrawTileWeld.h create mode 100644 src/Mod/TechDraw/App/DrawTileWeldPy.xml create mode 100644 src/Mod/TechDraw/App/DrawTileWeldPyImp.cpp create mode 100644 src/Mod/TechDraw/App/DrawWeldSymbol.cpp create mode 100644 src/Mod/TechDraw/App/DrawWeldSymbol.h create mode 100644 src/Mod/TechDraw/App/DrawWeldSymbolPy.xml create mode 100644 src/Mod/TechDraw/App/DrawWeldSymbolPyImp.cpp create mode 100644 src/Mod/TechDraw/Gui/QGITile.cpp create mode 100644 src/Mod/TechDraw/Gui/QGITile.h create mode 100644 src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp create mode 100644 src/Mod/TechDraw/Gui/QGIWeldSymbol.h create mode 100644 src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-tile.svg create mode 100644 src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-weldsymbol.svg create mode 100644 src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp create mode 100644 src/Mod/TechDraw/Gui/TaskWeldingSymbol.h create mode 100644 src/Mod/TechDraw/Gui/TaskWeldingSymbol.ui create mode 100644 src/Mod/TechDraw/Gui/ViewProviderTile.cpp create mode 100644 src/Mod/TechDraw/Gui/ViewProviderTile.h create mode 100644 src/Mod/TechDraw/Gui/ViewProviderWeld.cpp create mode 100644 src/Mod/TechDraw/Gui/ViewProviderWeld.h create mode 100644 src/Mod/TechDraw/Symbols/Welding/AWS/SquareDown.svg create mode 100644 src/Mod/TechDraw/Symbols/Welding/AWS/SquareUp.svg create mode 100644 src/Mod/TechDraw/Symbols/Welding/AWS/VDown.svg create mode 100644 src/Mod/TechDraw/Symbols/Welding/AWS/VUp.svg create mode 100644 src/Mod/TechDraw/Symbols/Welding/AWS/beadDown.svg create mode 100644 src/Mod/TechDraw/Symbols/Welding/AWS/beadUp.svg create mode 100644 src/Mod/TechDraw/Symbols/Welding/AWS/filletDown.svg create mode 100644 src/Mod/TechDraw/Symbols/Welding/AWS/filletUp.svg create mode 100644 src/Mod/TechDraw/Symbols/Welding/AWS/filletUpPlain.svg create mode 100644 src/Mod/TechDraw/Symbols/Welding/AWS/plug.svg diff --git a/src/Mod/TechDraw/App/AppTechDraw.cpp b/src/Mod/TechDraw/App/AppTechDraw.cpp index 0ff8b8b3b2..d1b33c8e4f 100644 --- a/src/Mod/TechDraw/App/AppTechDraw.cpp +++ b/src/Mod/TechDraw/App/AppTechDraw.cpp @@ -42,6 +42,9 @@ #include "DrawViewBalloon.h" #include "DrawLeaderLine.h" #include "DrawRichAnno.h" +#include "DrawTile.h" +#include "DrawTileWeld.h" +#include "DrawWeldSymbol.h" #include "Cosmetic.h" #include "PropertyGeomFormatList.h" #include "PropertyCenterLineList.h" @@ -100,6 +103,9 @@ PyMOD_INIT_FUNC(TechDraw) TechDraw::DrawViewDraft ::init(); TechDraw::DrawViewArch ::init(); TechDraw::DrawViewImage ::init(); + TechDraw::DrawTile ::init(); + TechDraw::DrawTileWeld ::init(); + TechDraw::DrawWeldSymbol ::init(); TechDraw::PropertyGeomFormatList::init(); TechDraw::GeomFormat ::init(); @@ -119,5 +125,8 @@ PyMOD_INIT_FUNC(TechDraw) TechDraw::DrawViewSymbolPython::init(); TechDraw::DrawLeaderLinePython::init(); TechDraw::DrawRichAnnoPython ::init(); + TechDraw::DrawTilePython ::init(); + TechDraw::DrawTileWeldPython ::init(); + TechDraw::DrawWeldSymbolPython::init(); PyMOD_Return(mod); } diff --git a/src/Mod/TechDraw/App/CMakeLists.txt b/src/Mod/TechDraw/App/CMakeLists.txt index a6611d0e17..aa8fe00e31 100644 --- a/src/Mod/TechDraw/App/CMakeLists.txt +++ b/src/Mod/TechDraw/App/CMakeLists.txt @@ -63,6 +63,9 @@ generate_from_xml(GeomFormatPy) generate_from_xml(CenterLinePy) generate_from_xml(CosmeticEdgePy) generate_from_xml(CosmeticVertexPy) +generate_from_xml(DrawTilePy) +generate_from_xml(DrawTileWeldPy) +generate_from_xml(DrawWeldSymbolPy) SET(Draw_SRCS DrawPage.cpp @@ -117,6 +120,12 @@ SET(Draw_SRCS DrawRichAnno.h QDomNodeModel.cpp QDomNodeModel.h + DrawTile.cpp + DrawTile.h + DrawTileWeld.cpp + DrawTileWeld.h + DrawWeldSymbol.cpp + DrawWeldSymbol.h ) SET(TechDraw_SRCS @@ -196,6 +205,12 @@ SET(Python_SRCS CosmeticEdgePyImp.cpp CosmeticVertexPy.xml CosmeticVertexPyImp.cpp + DrawTilePy.xml + DrawTilePyImp.cpp + DrawTileWeldPy.xml + DrawTileWeldPyImp.cpp + DrawWeldSymbolPy.xml + DrawWeldSymbolPyImp.cpp ) SOURCE_GROUP("Mod" FILES ${TechDraw_SRCS}) @@ -225,6 +240,13 @@ ADD_CUSTOM_COMMAND(TARGET TechDraw COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/src/Mod/TechDraw/Templates ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/Mod/TechDraw/Templates +) + +ADD_CUSTOM_COMMAND(TARGET TechDraw + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${CMAKE_SOURCE_DIR}/src/Mod/TechDraw/Symbols + ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/Mod/TechDraw/Symbols ) SET_BIN_DIR(TechDraw TechDraw /Mod/TechDraw) diff --git a/src/Mod/TechDraw/App/DrawLeaderLine.cpp b/src/Mod/TechDraw/App/DrawLeaderLine.cpp index 81f4b3628f..b24dd49c61 100644 --- a/src/Mod/TechDraw/App/DrawLeaderLine.cpp +++ b/src/Mod/TechDraw/App/DrawLeaderLine.cpp @@ -187,6 +187,52 @@ void DrawLeaderLine::adjustLastSegment(void) WayPoints.setValues(wp); } +//middle of last line segment +Base::Vector3d DrawLeaderLine::getTileOrigin(void) const +{ + Base::Vector3d result; + std::vector wp = WayPoints.getValues(); + if (wp.size() > 1) { + Base::Vector3d last = wp.rbegin()[0]; + Base::Vector3d second = wp.rbegin()[1]; + result = (last + second) / 2.0; + } else { + Base::Console().Warning("DLL::getTileOrigin - no waypoints\n"); + } + return result; +} + +//start of last line segment +Base::Vector3d DrawLeaderLine::getKinkPoint(void) const +{ + Base::Vector3d result; + std::vector wp = WayPoints.getValues(); + if (wp.size() > 1) { + Base::Vector3d second = wp.rbegin()[1]; + result = second; + } else { + Base::Console().Warning("DLL::getKinkPoint - no waypoints\n"); + } + + return result; +} + +//end of last line segment +Base::Vector3d DrawLeaderLine::getTailPoint(void) const +{ + Base::Vector3d result; + std::vector wp = WayPoints.getValues(); + if (!wp.empty()) { + Base::Vector3d last = wp.rbegin()[0]; + result = last; + } else { + Base::Console().Warning("DLL::getTailPoint - no waypoints\n"); + } + + return result; +} + + bool DrawLeaderLine::getDefAuto(void) const { Base::Reference hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")-> diff --git a/src/Mod/TechDraw/App/DrawLeaderLine.h b/src/Mod/TechDraw/App/DrawLeaderLine.h index 7f73fd0991..634b4f24d0 100644 --- a/src/Mod/TechDraw/App/DrawLeaderLine.h +++ b/src/Mod/TechDraw/App/DrawLeaderLine.h @@ -66,6 +66,10 @@ public: void adjustLastSegment(void); bool getDefAuto(void) const; + Base::Vector3d getTileOrigin(void) const; + Base::Vector3d getKinkPoint(void) const; + Base::Vector3d getTailPoint(void) const; + protected: virtual void onChanged(const App::Property* prop) override; diff --git a/src/Mod/TechDraw/App/DrawTile.cpp b/src/Mod/TechDraw/App/DrawTile.cpp new file mode 100644 index 0000000000..65bb6e45b8 --- /dev/null +++ b/src/Mod/TechDraw/App/DrawTile.cpp @@ -0,0 +1,118 @@ +/*************************************************************************** + * Copyright (c) 2019 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" + +#ifndef _PreComp_ +#endif + +#include +#include +#include +#include + +#include "DrawUtil.h" + +#include // generated from DrawTilePy.xml +#include "DrawTile.h" + +using namespace TechDraw; + +//=========================================================================== +// DrawTile - attachable tile +//=========================================================================== + +PROPERTY_SOURCE(TechDraw::DrawTile, App::DocumentObject) + +DrawTile::DrawTile(void) +{ + static const char *group = "Tile"; + + Base::Vector3d defOrg(0.0, 0.0, 0.0); + ADD_PROPERTY_TYPE(TileParent,(0),group,(App::PropertyType)(App::Prop_None), + "Object to which this tile is attached"); + ADD_PROPERTY_TYPE(TileRow, (0), group, App::Prop_None, "Row in parent"); + ADD_PROPERTY_TYPE(TileColumn, (0), group, App::Prop_None, "Column in parent"); + ADD_PROPERTY_TYPE(TileOrigin, (defOrg), group, App::Prop_None, "Width limit before auto wrap"); +} + +DrawTile::~DrawTile() +{ +} + +void DrawTile::onChanged(const App::Property* prop) +{ + if (!isRestoring()) { + //nothing in particular + } + DocumentObject::onChanged(prop); + +} + +short DrawTile::mustExecute() const +{ + return DocumentObject::mustExecute(); +} + +App::DocumentObjectExecReturn *DrawTile::execute(void) +{ +// Base::Console().Message("DT::execute()\n"); + return DocumentObject::execute(); +} + +DrawView* DrawTile::getParent(void) const +{ + Base::Console().Message("DT::getParent() - %s\n", getNameInDocument()); + DrawView* result = nullptr; + App::DocumentObject* baseObj = TileParent.getValue(); + if (baseObj != nullptr) { + DrawView* cast = dynamic_cast(baseObj); + if (cast != nullptr) { + result = cast; + } + } + return result; +} + +PyObject *DrawTile::getPyObject(void) +{ + if (PythonObject.is(Py::_None())) { + // ref counter is set to 1 + PythonObject = Py::Object(new DrawTilePy(this),true); + } + return Py::new_reference_to(PythonObject); +} + +// Python Drawing feature --------------------------------------------------------- + +namespace App { +/// @cond DOXERR +PROPERTY_SOURCE_TEMPLATE(TechDraw::DrawTilePython, TechDraw::DrawTile) +template<> const char* TechDraw::DrawTilePython::getViewProviderName(void) const { + return "TechDrawGui::ViewProviderTile"; +} +/// @endcond + +// explicit template instantiation +template class TechDrawExport FeaturePythonT; +} + diff --git a/src/Mod/TechDraw/App/DrawTile.h b/src/Mod/TechDraw/App/DrawTile.h new file mode 100644 index 0000000000..6b80bd6e75 --- /dev/null +++ b/src/Mod/TechDraw/App/DrawTile.h @@ -0,0 +1,65 @@ +/*************************************************************************** + * Copyright (c) 2019 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef _TechDraw_DrawTile_h_ +#define _TechDraw_DrawTile_h_ + +# include +# include + +#include "DrawView.h" + +namespace TechDraw +{ + +class TechDrawExport DrawTile : public App::DocumentObject +{ + PROPERTY_HEADER(TechDraw::DrawTile); + +public: + DrawTile(); + virtual ~DrawTile(); + + App::PropertyLink TileParent; //eg DrawWeldSymbol + App::PropertyInteger TileRow; + App::PropertyInteger TileColumn; + App::PropertyVector TileOrigin; //sb call to TileParent - WeldingSymbol + + virtual short mustExecute() const; + virtual App::DocumentObjectExecReturn *execute(void); + + virtual const char* getViewProviderName(void) const { + return "TechDrawGui::ViewProviderTile"; + } + virtual PyObject *getPyObject(void); + virtual DrawView* getParent(void) const; + +protected: + virtual void onChanged(const App::Property* prop); + +private: +}; + +typedef App::FeaturePythonT DrawTilePython; + +} //namespace TechDraw +#endif diff --git a/src/Mod/TechDraw/App/DrawTilePy.xml b/src/Mod/TechDraw/App/DrawTilePy.xml new file mode 100644 index 0000000000..c0a466bd90 --- /dev/null +++ b/src/Mod/TechDraw/App/DrawTilePy.xml @@ -0,0 +1,18 @@ + + + + + + Feature for adding tiles to leader lines + + + + diff --git a/src/Mod/TechDraw/App/DrawTilePyImp.cpp b/src/Mod/TechDraw/App/DrawTilePyImp.cpp new file mode 100644 index 0000000000..ae48cfe9fd --- /dev/null +++ b/src/Mod/TechDraw/App/DrawTilePyImp.cpp @@ -0,0 +1,54 @@ +/*************************************************************************** + * Copyright (c) 2019 WandererFan (wandererfan@gmail.com) * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ +#endif + +#include +#include +#include + +#include "DrawTile.h" + +// inclusion of the generated files (generated out of DrawTilePy.xml) +#include +#include +#include + +using namespace TechDraw; + +// returns a string which represents the object e.g. when printed in python +std::string DrawTilePy::representation(void) const +{ + return std::string(""); +} + +PyObject *DrawTilePy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int DrawTilePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} diff --git a/src/Mod/TechDraw/App/DrawTileWeld.cpp b/src/Mod/TechDraw/App/DrawTileWeld.cpp new file mode 100644 index 0000000000..851d356743 --- /dev/null +++ b/src/Mod/TechDraw/App/DrawTileWeld.cpp @@ -0,0 +1,103 @@ +/*************************************************************************** + * Copyright (c) 2019 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" + +#ifndef _PreComp_ +#endif + +#include +#include +#include +#include + +#include "DrawUtil.h" + +#include // generated from DrawTileWeldPy.xml +#include "DrawTileWeld.h" + +using namespace TechDraw; + +//=========================================================================== +// DrawTileWeld - attachable tile +//=========================================================================== + +PROPERTY_SOURCE(TechDraw::DrawTileWeld, TechDraw::DrawTile) + +DrawTileWeld::DrawTileWeld(void) +{ + static const char *group = "TileWeld"; + + ADD_PROPERTY_TYPE(LeftText,(""),group,(App::PropertyType)(App::Prop_None), + "Text LHS"); + ADD_PROPERTY_TYPE(RightText, (0), group, App::Prop_None, "Text RHS"); + ADD_PROPERTY_TYPE(CenterText, (0), group, App::Prop_None, "Text above Symbol"); + ADD_PROPERTY_TYPE(SymbolFile, (""), group, App::Prop_None, "Svg Symbol File"); +} + +DrawTileWeld::~DrawTileWeld() +{ +} + +void DrawTileWeld::onChanged(const App::Property* prop) +{ + if (!isRestoring()) { + //nothing in particular + } + DrawTile::onChanged(prop); + +} + +short DrawTileWeld::mustExecute() const +{ + return DrawTile::mustExecute(); +} + +App::DocumentObjectExecReturn *DrawTileWeld::execute(void) +{ +// Base::Console().Message("DT::execute()\n"); + return DrawTile::execute(); +} + +PyObject *DrawTileWeld::getPyObject(void) +{ + if (PythonObject.is(Py::_None())) { + // ref counter is set to 1 + PythonObject = Py::Object(new DrawTileWeldPy(this),true); + } + return Py::new_reference_to(PythonObject); +} + +// Python Drawing feature --------------------------------------------------------- + +namespace App { +/// @cond DOXERR +PROPERTY_SOURCE_TEMPLATE(TechDraw::DrawTileWeldPython, TechDraw::DrawTileWeld) +template<> const char* TechDraw::DrawTileWeldPython::getViewProviderName(void) const { + return "TechDrawGui::ViewProviderTile"; +} +/// @endcond + +// explicit template instantiation +template class TechDrawExport FeaturePythonT; +} + diff --git a/src/Mod/TechDraw/App/DrawTileWeld.h b/src/Mod/TechDraw/App/DrawTileWeld.h new file mode 100644 index 0000000000..a8070e5c8b --- /dev/null +++ b/src/Mod/TechDraw/App/DrawTileWeld.h @@ -0,0 +1,68 @@ +/*************************************************************************** + * Copyright (c) 2019 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef _TechDraw_DrawTileWeld_h_ +#define _TechDraw_DrawTileWeld_h_ + +#include +#include +#include +#include + +#include "DrawTile.h" + + +namespace TechDraw +{ + +class TechDrawExport DrawTileWeld : public TechDraw::DrawTile +{ + PROPERTY_HEADER(TechDraw::DrawTileWeld); + +public: + DrawTileWeld(); + virtual ~DrawTileWeld(); + + App::PropertyString LeftText; + App::PropertyString RightText; + App::PropertyString CenterText; + App::PropertyFileIncluded SymbolFile; + + virtual short mustExecute() const; + virtual App::DocumentObjectExecReturn *execute(void); + + virtual const char* getViewProviderName(void) const { + return "TechDrawGui::ViewProviderTile"; + } + virtual PyObject *getPyObject(void); + virtual QRectF getRect() const { return QRectF(0,0,1,1);} + +protected: + virtual void onChanged(const App::Property* prop); + +private: +}; + +typedef App::FeaturePythonT DrawTileWeldPython; + +} //namespace TechDraw +#endif diff --git a/src/Mod/TechDraw/App/DrawTileWeldPy.xml b/src/Mod/TechDraw/App/DrawTileWeldPy.xml new file mode 100644 index 0000000000..a93e13ef0a --- /dev/null +++ b/src/Mod/TechDraw/App/DrawTileWeldPy.xml @@ -0,0 +1,18 @@ + + + + + + Feature for adding welding tiles to leader lines + + + + diff --git a/src/Mod/TechDraw/App/DrawTileWeldPyImp.cpp b/src/Mod/TechDraw/App/DrawTileWeldPyImp.cpp new file mode 100644 index 0000000000..5fb4342a2d --- /dev/null +++ b/src/Mod/TechDraw/App/DrawTileWeldPyImp.cpp @@ -0,0 +1,54 @@ +/*************************************************************************** + * Copyright (c) 2019 WandererFan (wandererfan@gmail.com) * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ +#endif + +#include +#include +#include + +#include "DrawTileWeld.h" + +// inclusion of the generated files (generated out of DrawTileWeldPy.xml) +#include +#include +#include + +using namespace TechDraw; + +// returns a string which represents the object e.g. when printed in python +std::string DrawTileWeldPy::representation(void) const +{ + return std::string(""); +} + +PyObject *DrawTileWeldPy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int DrawTileWeldPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} diff --git a/src/Mod/TechDraw/App/DrawWeldSymbol.cpp b/src/Mod/TechDraw/App/DrawWeldSymbol.cpp new file mode 100644 index 0000000000..7dd0fbfaa8 --- /dev/null +++ b/src/Mod/TechDraw/App/DrawWeldSymbol.cpp @@ -0,0 +1,136 @@ +/*************************************************************************** + * Copyright (c) 2019 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" + +#ifndef _PreComp_ +#endif + +#include +#include +#include +#include +#include +#include + +#include "DrawUtil.h" + +#include // generated from DrawWeldSymbolPy.xml + +#include "DrawTile.h" +#include "DrawTileWeld.h" +#include "DrawWeldSymbol.h" + +using namespace TechDraw; + +//=========================================================================== +// DrawWeldSymbol - welding symbol +//=========================================================================== + +PROPERTY_SOURCE(TechDraw::DrawWeldSymbol, TechDraw::DrawView) + +DrawWeldSymbol::DrawWeldSymbol(void) +{ + static const char *group = "Weld Symbol"; + + ADD_PROPERTY_TYPE(Leader,(0),group,(App::PropertyType)(App::Prop_None), "Parent Leader"); + ADD_PROPERTY_TYPE(AllAround, (false), group, App::Prop_None, "All Around Symbol on/off"); + ADD_PROPERTY_TYPE(FieldWeld, (false), group, App::Prop_None, "Field Weld Symbol on/off"); + ADD_PROPERTY_TYPE(TailText, (""), group, App::Prop_None, "Text at tail of symbol"); + + Caption.setStatus(App::Property::Hidden,true); + Scale.setStatus(App::Property::Hidden,true); + ScaleType.setStatus(App::Property::Hidden,true); + +} + +DrawWeldSymbol::~DrawWeldSymbol() +{ +} + +void DrawWeldSymbol::onChanged(const App::Property* prop) +{ + if (!isRestoring()) { + //nothing in particular + } + DrawView::onChanged(prop); +} + +short DrawWeldSymbol::mustExecute() const +{ + return DrawView::mustExecute(); +} + +App::DocumentObjectExecReturn *DrawWeldSymbol::execute(void) +{ +// Base::Console().Message("DWS::execute()\n"); + if (!keepUpdated()) { + return App::DocumentObject::StdReturn; + } + + + return DrawView::execute(); +} + +std::vector DrawWeldSymbol::getTiles(void) const +{ +// Base::Console().Message("DWS::getTiles()\n"); + std::vector temp; + std::vector result; + + std::vector tiles = getInList(); + if (!tiles.empty()) { + for(std::vector::iterator it = tiles.begin(); it != tiles.end(); it++) { + if ((*it)->getTypeId().isDerivedFrom(TechDraw::DrawTileWeld::getClassTypeId())) { + App::DocumentObject* doTemp = (*it); + DrawTileWeld* temp = static_cast(doTemp); + result.push_back(temp); + } + } + } +// Base::Console().Message("DWS::getTiles - returns: %d tiles\n",result.size()); + return result; +} + +PyObject *DrawWeldSymbol::getPyObject(void) +{ + if (PythonObject.is(Py::_None())) { + // ref counter is set to 1 + PythonObject = Py::Object(new DrawWeldSymbolPy(this),true); + } + return Py::new_reference_to(PythonObject); +} + +// Python Drawing feature --------------------------------------------------------- + +namespace App { +/// @cond DOXERR +PROPERTY_SOURCE_TEMPLATE(TechDraw::DrawWeldSymbolPython, TechDraw::DrawWeldSymbol) +template<> const char* TechDraw::DrawWeldSymbolPython::getViewProviderName(void) const { + return "TechDrawGui::ViewProviderWeld"; +} +/// @endcond + +// explicit template instantiation +template class TechDrawExport FeaturePythonT; +} + diff --git a/src/Mod/TechDraw/App/DrawWeldSymbol.h b/src/Mod/TechDraw/App/DrawWeldSymbol.h new file mode 100644 index 0000000000..0ab74871ea --- /dev/null +++ b/src/Mod/TechDraw/App/DrawWeldSymbol.h @@ -0,0 +1,72 @@ +/*************************************************************************** + * Copyright (c) 2019 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef _TechDraw_DrawWeldSymbol_h_ +#define _TechDraw_DrawWeldSymbol_h_ + +# include +# include + +#include "DrawView.h" + + +namespace TechDraw +{ +class DrawTile; +class DrawTileWeld; + +class TechDrawExport DrawWeldSymbol : public TechDraw::DrawView +{ + PROPERTY_HEADER(TechDraw::DrawWeldSymbol); + +public: + DrawWeldSymbol(); + virtual ~DrawWeldSymbol(); + + App::PropertyLink Leader; +// App::PropertyLinkList Tiles; + App::PropertyBool AllAround; + App::PropertyBool FieldWeld; + App::PropertyString TailText; + + virtual short mustExecute() const; + virtual App::DocumentObjectExecReturn *execute(void); + + virtual const char* getViewProviderName(void) const { + return "TechDrawGui::ViewProviderWeld"; + } + virtual PyObject *getPyObject(void); + virtual QRectF getRect() const { return QRectF(0,0,1,1);} + + std::vector getTiles(void) const; +// void addTile(App::DocumentObject* d); + +protected: + virtual void onChanged(const App::Property* prop); + +private: +}; + +typedef App::FeaturePythonT DrawWeldSymbolPython; + +} //namespace TechDraw +#endif diff --git a/src/Mod/TechDraw/App/DrawWeldSymbolPy.xml b/src/Mod/TechDraw/App/DrawWeldSymbolPy.xml new file mode 100644 index 0000000000..165fac160c --- /dev/null +++ b/src/Mod/TechDraw/App/DrawWeldSymbolPy.xml @@ -0,0 +1,18 @@ + + + + + + Feature for adding welding tiles to leader lines + + + + diff --git a/src/Mod/TechDraw/App/DrawWeldSymbolPyImp.cpp b/src/Mod/TechDraw/App/DrawWeldSymbolPyImp.cpp new file mode 100644 index 0000000000..578ad3f703 --- /dev/null +++ b/src/Mod/TechDraw/App/DrawWeldSymbolPyImp.cpp @@ -0,0 +1,67 @@ +/*************************************************************************** + * Copyright (c) 2019 WandererFan (wandererfan@gmail.com) * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ +#endif + +#include +#include +#include + +#include "DrawWeldSymbol.h" + +// inclusion of the generated files (generated out of DrawWeldSymbolPy.xml) +#include +#include +#include + +using namespace TechDraw; + +// returns a string which represents the object e.g. when printed in python +std::string DrawWeldSymbolPy::representation(void) const +{ + return std::string(""); +} + +//PyObject* DrawWeldSymbolPy::getTiles(PyObject *args) +//{ +// const char* fileSpec; +// PyObject* pTile +// if (!PyArg_ParseTuple(args, "O", &pTile)) { +// throw Py::TypeError("getTiles expected DrawTile"); +// } +// auto dws = getDrawWeldSymbolPtr(); +//// auto dt = pTile->getDrawTilePtr(); +////TODO: finish this! +// Py_Return; +//} + +PyObject *DrawWeldSymbolPy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int DrawWeldSymbolPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} diff --git a/src/Mod/TechDraw/CMakeLists.txt b/src/Mod/TechDraw/CMakeLists.txt index 1d28eda752..2a4c8c3a86 100644 --- a/src/Mod/TechDraw/CMakeLists.txt +++ b/src/Mod/TechDraw/CMakeLists.txt @@ -24,7 +24,7 @@ SET(TechDraw_LineGroupFile ) add_custom_target(TechDraw_Data ALL - SOURCES ${TechDraw_Scripts} ${TechDraw_PATFile} ${TechDraw_LineGroupFile} +SOURCES ${TechDraw_Scripts} ${TechDraw_PATFile} ${TechDraw_LineGroupFile} ) fc_target_copy_resource(TechDraw_Data @@ -86,6 +86,15 @@ INSTALL( PATTERN "*.svg*" ) +INSTALL( + DIRECTORY + Symbols + DESTINATION + ${CMAKE_INSTALL_DATADIR}/Mod/TechDraw + FILES_MATCHING + PATTERN "*.svg*" +) + #unit test files SET(TDTest_SRCS diff --git a/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp b/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp index fba82bd380..d5511b046e 100644 --- a/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp +++ b/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp @@ -58,6 +58,8 @@ #include "ViewProviderImage.h" #include "ViewProviderRichAnno.h" #include "ViewProviderLeader.h" +#include "ViewProviderTile.h" +#include "ViewProviderWeld.h" // use a different name to CreateCommand() @@ -134,6 +136,8 @@ PyMOD_INIT_FUNC(TechDrawGui) TechDrawGui::ViewProviderImage::init(); TechDrawGui::ViewProviderLeader::init(); TechDrawGui::ViewProviderRichAnno::init(); + TechDrawGui::ViewProviderTile::init(); + TechDrawGui::ViewProviderWeld::init(); // register preferences pages new Gui::PrefPageProducer ("TechDraw"); diff --git a/src/Mod/TechDraw/Gui/CMakeLists.txt b/src/Mod/TechDraw/Gui/CMakeLists.txt index f39360856f..e31c45a3ec 100644 --- a/src/Mod/TechDraw/Gui/CMakeLists.txt +++ b/src/Mod/TechDraw/Gui/CMakeLists.txt @@ -55,6 +55,7 @@ set(TechDrawGui_MOC_HDRS TaskCosVertex.h TaskCenterLine.h TaskLineDecor.h + TaskWeldingSymbol.h QGEPath.h QGTracker.h QGILeaderLine.h @@ -63,6 +64,7 @@ set(TechDrawGui_MOC_HDRS mrichtextedit.h mtextedit.h TaskBalloon.h + QGIWeldSymbol.h ) fc_wrap_cpp(TechDrawGui_MOC_SRCS ${TechDrawGui_MOC_HDRS}) @@ -91,6 +93,7 @@ set(TechDrawGui_UIC_SRCS TaskCL2Lines.ui TaskLineDecor.ui TaskRestoreLines.ui + TaskWeldingSymbol.ui ) if(BUILD_QT5) @@ -168,6 +171,9 @@ SET(TechDrawGui_SRCS TaskLineDecor.h TaskRestoreLines.ui TaskCL2Lines.ui + TaskWeldingSymbol.ui + TaskWeldingSymbol.cpp + TaskWeldingSymbol.h DrawGuiUtil.cpp DrawGuiUtil.h Rez.cpp @@ -261,6 +267,10 @@ SET(TechDrawGuiView_SRCS QGIRichAnno.h QGMText.h QGMText.cpp + QGIWeldSymbol.h + QGIWeldSymbol.cpp + QGITile.h + QGITile.cpp TemplateTextField.cpp TemplateTextField.h ZVALUE.h @@ -302,6 +312,10 @@ SET(TechDrawGuiViewProvider_SRCS ViewProviderLeader.h ViewProviderRichAnno.cpp ViewProviderRichAnno.h + ViewProviderTile.cpp + ViewProviderTile.h + ViewProviderWeld.cpp + ViewProviderWeld.h ) SOURCE_GROUP("MRTE" FILES ${MRTE_SRCS}) @@ -323,6 +337,7 @@ SET(TechDrawGuiTaskDlgs_SRCS TaskLineDecor.ui TaskRestoreLines.ui TaskCL2Lines.ui + TaskWeldingSymbol.ui ) SOURCE_GROUP("TaskDialogs" FILES ${TechDrawGuiTaskDlgs_SRCS}) diff --git a/src/Mod/TechDraw/Gui/CommandAnnotate.cpp b/src/Mod/TechDraw/Gui/CommandAnnotate.cpp index f3801c7a1f..f6c4d09909 100644 --- a/src/Mod/TechDraw/Gui/CommandAnnotate.cpp +++ b/src/Mod/TechDraw/Gui/CommandAnnotate.cpp @@ -48,6 +48,8 @@ #include #include #include +#include +#include #include #include #include @@ -60,6 +62,7 @@ #include "TaskCosVertex.h" #include "TaskCenterLine.h" #include "TaskLineDecor.h" +#include "TaskWeldingSymbol.h" #include "ViewProviderPage.h" #include "ViewProviderViewPart.h" #include "QGVPage.h" @@ -1279,6 +1282,61 @@ bool CmdTechDrawShowAll::isActive(void) return (havePage && haveView); } +//=========================================================================== +// TechDraw_WeldSymbol +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawWeldSymbol); + +CmdTechDrawWeldSymbol::CmdTechDrawWeldSymbol() + : Command("TechDraw_WeldSymbol") +{ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Add welding information to a leader"); + sToolTipText = sMenuText; + sWhatsThis = "TechDraw_WeldSymbol"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-weldsymbol"; +} + +void CmdTechDrawWeldSymbol::activated(int iMsg) +{ + Q_UNUSED(iMsg); + + Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); + if (dlg != nullptr) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"), + QObject::tr("Close active task dialog and try again.")); + return; + } + + TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); + if (!page) { + return; + } + + std::vector leaders = getSelection(). + getObjectsOfType(TechDraw::DrawLeaderLine::getClassTypeId()); + if (leaders.size() != 1) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select exactly one Leader line.")); + return; + } + TechDraw::DrawLeaderLine* baseFeat = nullptr; + baseFeat = static_cast (leaders.front()); + + Gui::Control().showDialog(new TaskDlgWeldingSymbol(baseFeat)); +} + +bool CmdTechDrawWeldSymbol::isActive(void) +{ + bool havePage = DrawGuiUtil::needPage(this); + bool haveView = DrawGuiUtil::needView(this, false); + return (havePage && haveView); +} + + void CreateTechDrawCommandsAnnotate(void) { Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); @@ -1297,6 +1355,7 @@ void CreateTechDrawCommandsAnnotate(void) rcCmdMgr.addCommand(new CmdTechDrawCosmeticEraser()); rcCmdMgr.addCommand(new CmdTechDrawDecorateLine()); rcCmdMgr.addCommand(new CmdTechDrawShowAll()); + rcCmdMgr.addCommand(new CmdTechDrawWeldSymbol()); } //=========================================================================== diff --git a/src/Mod/TechDraw/Gui/MDIViewPage.cpp b/src/Mod/TechDraw/Gui/MDIViewPage.cpp index 0e089079ed..a153cb62f1 100644 --- a/src/Mod/TechDraw/Gui/MDIViewPage.cpp +++ b/src/Mod/TechDraw/Gui/MDIViewPage.cpp @@ -84,6 +84,7 @@ #include #include #include +#include #include "Rez.h" #include "QGIDrawingTemplate.h" @@ -365,6 +366,9 @@ bool MDIViewPage::attachView(App::DocumentObject *obj) } else if (typeId.isDerivedFrom(TechDraw::DrawRichAnno::getClassTypeId()) ) { qview = m_view->addRichAnno( static_cast(obj) ); + } else if (typeId.isDerivedFrom(TechDraw::DrawWeldSymbol::getClassTypeId()) ) { + qview = m_view->addWeldSymbol( static_cast(obj) ); + } else if (typeId.isDerivedFrom(TechDraw::DrawHatch::getClassTypeId()) ) { //Hatch is not attached like other Views (since it isn't really a View) return true; diff --git a/src/Mod/TechDraw/Gui/QGCustomText.cpp b/src/Mod/TechDraw/Gui/QGCustomText.cpp index c6796977d1..d35eafb2d5 100644 --- a/src/Mod/TechDraw/Gui/QGCustomText.cpp +++ b/src/Mod/TechDraw/Gui/QGCustomText.cpp @@ -49,7 +49,8 @@ using namespace TechDrawGui; -QGCustomText::QGCustomText() +QGCustomText::QGCustomText(QGraphicsItem* parent) : + QGraphicsTextItem(parent) { setCacheMode(QGraphicsItem::NoCache); setAcceptHoverEvents(false); @@ -64,12 +65,6 @@ QGCustomText::QGCustomText() void QGCustomText::centerAt(QPointF centerPos) { centerAt(centerPos.x(),centerPos.y()); -// QRectF box = boundingRect(); -// double width = box.width(); -// double height = box.height(); -// double newX = centerPos.x() - width/2.; -// double newY = centerPos.y() - height/2.; -// setPos(newX,newY); } void QGCustomText::centerAt(double cX, double cY) @@ -82,8 +77,52 @@ void QGCustomText::centerAt(double cX, double cY) setPos(newX,newY); } +void QGCustomText::justifyLeftAt(QPointF centerPos, bool vCenter) +{ + justifyLeftAt(centerPos.x(),centerPos.y(), vCenter); +} + +void QGCustomText::justifyLeftAt(double cX, double cY, bool vCenter) +{ + QRectF box = boundingRect(); + double height = box.height(); + double newY = cY - height; + if (vCenter) { + newY = cY - height/2.; + } + setPos(cX,newY); +} + +void QGCustomText::justifyRightAt(QPointF centerPos, bool vCenter) +{ + justifyRightAt(centerPos.x(),centerPos.y(), vCenter); +} + +void QGCustomText::justifyRightAt(double cX, double cY, bool vCenter) +{ + QRectF box = boundingRect(); + double width = box.width(); + double height = box.height(); + double newX = cX - width; + double newY = cY - height; + if (vCenter) { + newY = cY - height/2.; + } + setPos(newX,newY); +} + +double QGCustomText::getHeight(void) +{ + return boundingRect().height(); +} + +double QGCustomText::getWidth(void) +{ + return boundingRect().width(); +} QVariant QGCustomText::itemChange(GraphicsItemChange change, const QVariant &value) { +// Base::Console().Message("QGCT::itemChange - this: %X change: %d\n", this, change); if (change == ItemSelectedHasChanged && scene()) { if(isSelected()) { setPrettySel(); @@ -112,18 +151,20 @@ void QGCustomText::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) } void QGCustomText::setPrettyNormal() { -// m_colCurrent = getNormalColor(); m_colCurrent = m_colNormal; + setDefaultTextColor(m_colNormal); update(); } void QGCustomText::setPrettyPre() { m_colCurrent = getPreColor(); + setDefaultTextColor(m_colCurrent); update(); } void QGCustomText::setPrettySel() { m_colCurrent = getSelectColor(); + setDefaultTextColor(m_colCurrent); update(); } @@ -131,31 +172,19 @@ void QGCustomText::paint ( QPainter * painter, const QStyleOptionGraphicsItem * QStyleOptionGraphicsItem myOption(*option); myOption.state &= ~QStyle::State_Selected; +// painter->setPen(Qt::green); // painter->drawRect(boundingRect()); //good for debugging - setDefaultTextColor(m_colCurrent); QGraphicsTextItem::paint (painter, &myOption, widget); } -QColor QGCustomText::getNormalColor() +QColor QGCustomText::getNormalColor() //preference! { QColor result; - QGIView *parent; - QGraphicsItem* qparent = parentItem(); - if (qparent == nullptr) { - parent = nullptr; - } else { - parent = dynamic_cast (qparent); - } - - if (parent != nullptr) { - result = parent->getNormalColor(); - } else { - Base::Reference hGrp = getParmGroup(); - App::Color fcColor; - fcColor.setPackedValue(hGrp->GetUnsigned("NormalColor", 0x00000000)); - result = fcColor.asValue(); - } + Base::Reference hGrp = getParmGroup(); + App::Color fcColor; + fcColor.setPackedValue(hGrp->GetUnsigned("NormalColor", 0x00000000)); + result = fcColor.asValue(); return result; } diff --git a/src/Mod/TechDraw/Gui/QGCustomText.h b/src/Mod/TechDraw/Gui/QGCustomText.h index b2ad795ef5..a5397bd4c5 100644 --- a/src/Mod/TechDraw/Gui/QGCustomText.h +++ b/src/Mod/TechDraw/Gui/QGCustomText.h @@ -41,24 +41,34 @@ namespace TechDrawGui class TechDrawGuiExport QGCustomText : public QGraphicsTextItem { public: - explicit QGCustomText(void); + explicit QGCustomText(QGraphicsItem* parent = nullptr); ~QGCustomText() {} enum {Type = QGraphicsItem::UserType + 130}; int type() const { return Type;} + virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ); void setHighlighted(bool state); virtual void setPrettyNormal(); virtual void setPrettyPre(); virtual void setPrettySel(); - virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ); virtual void centerAt(QPointF centerPos); virtual void centerAt(double cX, double cY); + virtual void justifyLeftAt(QPointF centerPos, bool vCenter = true); + virtual void justifyLeftAt(double cX, double cY, bool vCenter = true); + virtual void justifyRightAt(QPointF centerPos, bool vCenter = true); + virtual void justifyRightAt(double cX, double cY, bool vCenter = true); + + virtual double getHeight(void); + virtual double getWidth(void); + virtual QColor getNormalColor(void); virtual QColor getPreColor(void); virtual QColor getSelectColor(void); - virtual void setColor(QColor c) { m_colNormal = c; } + virtual void setColor(QColor c) { m_colNormal = c; + setDefaultTextColor(c); } + void makeMark(double x, double y); void makeMark(Base::Vector3d v); diff --git a/src/Mod/TechDraw/Gui/QGIArrow.cpp b/src/Mod/TechDraw/Gui/QGIArrow.cpp index 001ef5739b..0de92f8d27 100644 --- a/src/Mod/TechDraw/Gui/QGIArrow.cpp +++ b/src/Mod/TechDraw/Gui/QGIArrow.cpp @@ -49,8 +49,10 @@ QGIArrow::QGIArrow() : m_dirMode(false), m_dir(Base::Vector3d(1.0,0.0,0.0)) { + isFlipped = false; + setFill(Qt::SolidPattern); m_brush.setStyle(m_fill); - + setCacheMode(QGraphicsItem::NoCache); setAcceptHoverEvents(false); setFlag(QGraphicsItem::ItemIsSelectable, false); @@ -60,6 +62,7 @@ QGIArrow::QGIArrow() : void QGIArrow::draw() { QPainterPath path; if (m_style == 0) { + setFill(Qt::SolidPattern); if (m_dirMode) { path = makeFilledTriangle(getDirection(), m_size,m_size/6.0); } else { diff --git a/src/Mod/TechDraw/Gui/QGIDecoration.cpp b/src/Mod/TechDraw/Gui/QGIDecoration.cpp index 876cc19aba..be44a56862 100644 --- a/src/Mod/TechDraw/Gui/QGIDecoration.cpp +++ b/src/Mod/TechDraw/Gui/QGIDecoration.cpp @@ -83,8 +83,43 @@ void QGIDecoration::setStyle(Qt::PenStyle s) void QGIDecoration::setColor(QColor c) { + m_colNormal = c; m_colCurrent = c; m_pen.setColor(m_colCurrent); + m_brush.setColor(m_colCurrent); +} + +QColor QGIDecoration::prefNormalColor() +{ + QColor result; + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors"); + App::Color fcColor; + fcColor.setPackedValue(hGrp->GetUnsigned("NormalColor", 0x00000000)); + result = fcColor.asValue(); + return result; +} + +QColor QGIDecoration::prefPreColor() +{ + QColor result; + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors"); + App::Color fcColor; + fcColor.setPackedValue(hGrp->GetUnsigned("PreSelectColor", 0x00000000)); + result = fcColor.asValue(); + return result; +} + +QColor QGIDecoration::prefSelectColor() +{ + QColor result; + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors"); + App::Color fcColor; + fcColor.setPackedValue(hGrp->GetUnsigned("SelectColor", 0x00000000)); + result = fcColor.asValue(); + return result; } void QGIDecoration::makeMark(double x, double y) diff --git a/src/Mod/TechDraw/Gui/QGIDecoration.h b/src/Mod/TechDraw/Gui/QGIDecoration.h index 00659959f8..b7697b6466 100644 --- a/src/Mod/TechDraw/Gui/QGIDecoration.h +++ b/src/Mod/TechDraw/Gui/QGIDecoration.h @@ -52,13 +52,22 @@ public: void setWidth(double w); void setStyle(Qt::PenStyle s); void setColor(QColor c); + QColor getColor(void) { return m_colNormal; } + void setFill(Qt::BrushStyle bs) { m_brushCurrent = bs; } void makeMark(double x, double y); void makeMark(Base::Vector3d v); protected: + void setPrettyNormal(); + void setPrettyPre(); + void setPrettySel(); + virtual QColor prefNormalColor(void); + virtual QColor prefPreColor(void); + virtual QColor prefSelectColor(void); QPen m_pen; QBrush m_brush; QColor m_colCurrent; + QColor m_colNormal; double m_width; Qt::PenStyle m_styleCurrent; Qt::BrushStyle m_brushCurrent; diff --git a/src/Mod/TechDraw/Gui/QGIEdge.cpp b/src/Mod/TechDraw/Gui/QGIEdge.cpp index 6a3f3dd081..2506845048 100644 --- a/src/Mod/TechDraw/Gui/QGIEdge.cpp +++ b/src/Mod/TechDraw/Gui/QGIEdge.cpp @@ -48,6 +48,7 @@ QGIEdge::QGIEdge(int index) : { m_width = 1.0; setCosmetic(isCosmetic); + setFill(Qt::NoBrush); } //NOTE this refers to Qt cosmetic lines diff --git a/src/Mod/TechDraw/Gui/QGILeaderLine.cpp b/src/Mod/TechDraw/Gui/QGILeaderLine.cpp index 2829661b63..a6589a3f4d 100644 --- a/src/Mod/TechDraw/Gui/QGILeaderLine.cpp +++ b/src/Mod/TechDraw/Gui/QGILeaderLine.cpp @@ -361,6 +361,7 @@ void QGILeaderLine::draw() return; } + m_line->setFill(Qt::NoBrush); m_line->setStyle(m_lineStyle); double scaler = 1.0; m_line->setWidth(scaler * m_lineWidth); @@ -498,6 +499,11 @@ void QGILeaderLine::abandonEdit(void) restoreState(); } +double QGILeaderLine::getLineWidth(void) +{ + return m_lineWidth; +} + TechDraw::DrawLeaderLine* QGILeaderLine::getFeature(void) { TechDraw::DrawLeaderLine* result = @@ -548,6 +554,7 @@ void QGILeaderLine::paint ( QPainter * painter, const QStyleOptionGraphicsItem * QStyleOptionGraphicsItem myOption(*option); myOption.state &= ~QStyle::State_Selected; +// painter->setPen(Qt::blue); // painter->drawRect(boundingRect()); //good for debugging QGIView::paint (painter, &myOption, widget); diff --git a/src/Mod/TechDraw/Gui/QGILeaderLine.h b/src/Mod/TechDraw/Gui/QGILeaderLine.h index 2be3c2a96e..0db864b315 100644 --- a/src/Mod/TechDraw/Gui/QGILeaderLine.h +++ b/src/Mod/TechDraw/Gui/QGILeaderLine.h @@ -82,6 +82,8 @@ public: void abandonEdit(void); void closeEdit(void); + + double getLineWidth(void); public Q_SLOTS: void onLineEditFinished(QPointF attach, std::vector deltas); //QGEPath is finished editing points diff --git a/src/Mod/TechDraw/Gui/QGIPrimPath.cpp b/src/Mod/TechDraw/Gui/QGIPrimPath.cpp index dc01533e0c..a6a1a7d013 100644 --- a/src/Mod/TechDraw/Gui/QGIPrimPath.cpp +++ b/src/Mod/TechDraw/Gui/QGIPrimPath.cpp @@ -42,7 +42,9 @@ using namespace TechDrawGui; QGIPrimPath::QGIPrimPath(): m_width(0), - m_capStyle(Qt::RoundCap) + m_capStyle(Qt::RoundCap), + m_fill(Qt::NoBrush) +// m_fill(Qt::SolidPattern) { setCacheMode(QGraphicsItem::NoCache); setFlag(QGraphicsItem::ItemIsSelectable, true); @@ -129,6 +131,11 @@ void QGIPrimPath::paint ( QPainter * painter, const QStyleOptionGraphicsItem * o m_pen.setColor(m_colCurrent); m_pen.setStyle(m_styleCurrent); setPen(m_pen); + + m_brush.setColor(m_colCurrent); + m_brush.setStyle(m_fill); + setBrush(m_brush); + QGraphicsPathItem::paint (painter, &myOption, widget); } @@ -256,15 +263,21 @@ Qt::PenCapStyle QGIPrimPath::prefCapStyle() void QGIPrimPath::mousePressEvent(QGraphicsSceneMouseEvent * event) { + //wf: this seems a bit of a hack. does it mess up selection of QGIPP?? QGIView *parent; QGraphicsItem* qparent = parentItem(); if (qparent != nullptr) { parent = dynamic_cast (qparent); if (parent != nullptr) { +// Base::Console().Message("QGIPP::mousePressEvent - passing event to QGIV parent\n"); parent->mousePressEvent(event); } else { +// qparent->mousePressEvent(event); //protected! + QGraphicsPathItem::mousePressEvent(event); Base::Console().Log("QGIPP::mousePressEvent - no QGIView parent\n"); } + } else { +// Base::Console().Message("QGIPP::mousePressEvent - passing event to ancestor\n"); + QGraphicsPathItem::mousePressEvent(event); } - QGraphicsPathItem::mousePressEvent(event); } diff --git a/src/Mod/TechDraw/Gui/QGIPrimPath.h b/src/Mod/TechDraw/Gui/QGIPrimPath.h index 25babf8075..6e4c5be519 100644 --- a/src/Mod/TechDraw/Gui/QGIPrimPath.h +++ b/src/Mod/TechDraw/Gui/QGIPrimPath.h @@ -58,6 +58,8 @@ public: void setStyle(int s); virtual void setNormalColor(QColor c); virtual void setCapStyle(Qt::PenCapStyle c); + Qt::BrushStyle getFill() { return m_fill; } + void setFill(Qt::BrushStyle f) { m_fill = f; } protected: virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override; @@ -79,6 +81,9 @@ protected: Qt::PenStyle m_styleCurrent; double m_width; Qt::PenCapStyle m_capStyle; + QBrush m_brush; + Qt::BrushStyle m_fill; + private: diff --git a/src/Mod/TechDraw/Gui/QGITile.cpp b/src/Mod/TechDraw/Gui/QGITile.cpp new file mode 100644 index 0000000000..629f8dcdd6 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGITile.cpp @@ -0,0 +1,351 @@ +/*************************************************************************** + * Copyright (c) 2019 WandererFan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ +#include +#include +#include +#include +#endif + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include "Rez.h" +#include "DrawGuiUtil.h" +#include "QGIView.h" +#include "QGITile.h" + +using namespace TechDrawGui; + +QGITile::QGITile(TechDraw::DrawTile* feat) : + m_tileFeat(feat), + m_textL(QString()), + m_textR(QString()), + m_textC(QString()), + m_textSize(0.0), + m_row(0), + m_col(0), + m_scale(1.0) +{ + m_qgSvg = new QGCustomSvg(); + m_qgSvg->setParentItem(this); + m_effect = new QGraphicsColorizeEffect(); + m_qgTextL = new QGCustomText(); + m_qgTextL->setParentItem(this); + m_qgTextR = new QGCustomText(); + m_qgTextR->setParentItem(this); + m_qgTextC = new QGCustomText(); + m_qgTextC->setParentItem(this); + + m_wide = getSymbolWidth(); + m_high = getFontSize(); + m_textSize = getFontSize(); + m_textL = QString(); + m_textR = QString(); + m_textC = QString(); + m_fontName = getTextFont(); + m_font = QFont(m_fontName); + +// setHandlesChildEvents(true); //qt4 + setFiltersChildEvents(true); //qt5 + setAcceptHoverEvents(true); + setFlag(QGraphicsItem::ItemIsSelectable, false); + setFlag(QGraphicsItem::ItemIsMovable, false); + setFlag(QGraphicsItem::ItemSendsScenePositionChanges, false); + setFlag(QGraphicsItem::ItemSendsGeometryChanges,true); + setFlag(QGraphicsItem::ItemStacksBehindParent, true); + + m_colNormal = prefNormalColor(); + m_colCurrent = m_colNormal; +} + +QVariant QGITile::itemChange(GraphicsItemChange change, const QVariant &value) +{ +// Base::Console().Message("QGIT::itemChange(%d)\n", change); + return QGIDecoration::itemChange(change, value); +} + +void QGITile::draw(void) +{ +// Base::Console().Message("QGIT::draw()\n"); + prepareGeometryChange(); + m_wide = getSymbolWidth(); + m_high = getSymbolHeight() * scaleToFont(); + + makeText(); + makeSymbol(); + + double textWidthL = m_qgTextL->boundingRect().width(); + double textWidthR = m_qgTextR->boundingRect().width(); + double totalWidth = m_wide + textWidthL + textWidthR; + + double x = m_origin.x() + m_col * totalWidth; //bit of a hack. sb 0.5 of prev tile + 0.5 of this tile + double y = m_origin.y() - (m_row * m_high) - (m_high * 0.5); //inverted y!! + setPos(x,y); +} + +void QGITile::makeSymbol(void) +{ +// Base::Console().Message("QGIT::makeSymbol()\n"); + m_effect->setColor(m_colCurrent); + + m_qgSvg->setGraphicsEffect(m_effect); + QFile svgFile(m_svgPath); + if(svgFile.open(QIODevice::ReadOnly)) { + QByteArray qba = svgFile.readAll(); + if (!m_qgSvg->load(&qba)) { + Base::Console().Error("Error - Could not load SVG renderer with %s\n", qPrintable(m_svgPath)); + } + svgFile.close(); + } else { + Base::Console().Error("Error - Could not open file %s\n", qPrintable(m_svgPath)); + } + + m_qgSvg->setScale(scaleToFont()); + m_qgSvg->centerAt(0.0, 0.0); //(0,0) is based on symbol size +} + +void QGITile::makeText(void) +{ +// Base::Console().Message("QGIT::makeText()\n"); + prepareGeometryChange(); + m_font.setPixelSize(getFontSize()); + double verticalFudge = 0.10; //% of textHeight + + m_qgTextL->setFont(m_font); + m_qgTextL->setPlainText(m_textL); + m_qgTextL->setColor(m_colCurrent); + double textWidth = m_qgTextL->boundingRect().width(); + double charWidth = textWidth / m_textL.size(); //not good for non-ASCII chars + double hMargin = (m_wide / 2.0) + (charWidth / 2.0); + + double textHeightL = m_qgTextL->boundingRect().height(); + double offsetAdjustL = 0.0; + if (m_row < 0) { + offsetAdjustL = -textHeightL * verticalFudge; + } else { + offsetAdjustL = textHeightL * verticalFudge; + } + double offset = (textHeightL * verticalFudge * m_row) + offsetAdjustL; + m_qgTextL->justifyRightAt(-hMargin, -offset, true); + + m_qgTextR->setFont(m_font); + m_qgTextR->setPlainText(m_textR); + m_qgTextR->setColor(m_colCurrent); + textWidth = m_qgTextR->boundingRect().width(); + charWidth = textWidth / m_textR.size(); + double textHeightR = m_qgTextR->boundingRect().height(); + double offsetAdjustR = 0.0; + if (m_row < 0) { + offsetAdjustR = -textHeightR * verticalFudge; + } else { + offsetAdjustR = textHeightR * verticalFudge; + } + offset = (textHeightR * verticalFudge * m_row) + offsetAdjustR; + m_qgTextR->justifyLeftAt(hMargin, -offset, true); + + m_qgTextC->setFont(m_font); + m_qgTextC->setPlainText(m_textC); + m_qgTextC->setColor(m_colCurrent); + double textHeightC = m_qgTextC->boundingRect().height(); + textHeightC = textHeightC; + int rowAdjustC = m_row; + if (m_row >= 0) { + rowAdjustC++; + } + double offsetAdjustC = textHeightC * verticalFudge; + if (m_row < 0) { + offsetAdjustC = - offsetAdjustC; + } + offset = (textHeightC * rowAdjustC) - offsetAdjustC; + m_qgTextC->centerAt(0.0, -offset); +} + +void QGITile::setTilePosition(QPointF org, int r, int c) +{ + m_origin = org; + m_row = r; + m_col = c; +} + +void QGITile::setTileScale(double s) +{ + m_scale = s; +} + +void QGITile::setTileTextLeft(std::string s) +{ + m_textL = QString::fromUtf8(s.c_str()); +} + +void QGITile::setTileTextRight(std::string s) +{ + m_textR = QString::fromUtf8(s.c_str()); +} + +void QGITile::setTileTextCenter(std::string s) +{ + m_textC = QString::fromUtf8(s.c_str()); +} + +//using label font and dimension font size. could change later +//void QGITile::setFont(QFont f, double fsize) +//{ +// m_font = f; +// m_textSize = fsize; +//} + +void QGITile::setSymbolFile(std::string s) +{ +// Base::Console().Message("QGIT::setSymbolFile(%s)\n",s.c_str()); + if (!s.empty()) { + m_svgPath = QString::fromUtf8(s.c_str()); + } +} + +void QGITile::setPrettyNormal() { + m_colCurrent = m_colNormal; + + m_effect->setColor(m_colNormal); + m_qgTextL->setColor(m_colNormal); + m_qgTextR->setColor(m_colNormal); + m_qgTextC->setColor(m_colNormal); + + draw(); +} + +void QGITile::setPrettyPre() { + m_colCurrent = prefPreColor(); + + m_effect->setColor(m_colCurrent); + m_qgTextL->setColor(m_colCurrent); + m_qgTextR->setColor(m_colCurrent); + m_qgTextC->setColor(m_colCurrent); + + draw(); +} + +void QGITile::setPrettySel() { + m_colCurrent = prefSelectColor(); + + m_effect->setColor(m_colCurrent); + m_qgTextL->setColor(m_colCurrent); + m_qgTextR->setColor(m_colCurrent); + m_qgTextC->setColor(m_colCurrent); + + draw(); +} + + +//TODO: this is Pen, not Brush. sb Brush to colour background +QColor QGITile::getTileColor(void) const +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Colors"); + App::Color fcColor = App::Color((uint32_t) hGrp->GetUnsigned("TileColor", 0x00000000)); + return fcColor.asValue(); +} + +double QGITile::getSymbolWidth(void) const +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")-> + GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions"); + double w = hGrp->GetFloat("SymbolSize",64); +// symbols are only nominally 64x64. they actually have a "border" of 4 - 0.5*stroke(0.5) +// so we'll say effectively 62x62? 60 x 60 +// double w = 64.0; + double fudge = 4.0; //allowance for tile border + w = w - fudge; + return w; +} + +double QGITile::getSymbolHeight(void) const +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")-> + GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions"); + double h = hGrp->GetFloat("SymbolSize",64); + double fudge = 4.0; + h = h - fudge; +// double h = 60.0; + return h; +} + +double QGITile::getSymbolFactor(void) const +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")-> + GetGroup("Preferences")->GetGroup("Mod/TechDraw/Decorations"); + double s = hGrp->GetFloat("SymbolFactor",1.25); +// double s = 1.25; + return s; +} + +double QGITile::getFontSize(void) const +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter(). + GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions"); + double sizeMM = hGrp->GetFloat("FontSize", QGIView::DefaultFontSizeInMM); + double fontSize = QGIView::calculateFontPixelSize(sizeMM); + return fontSize; +} + +//factor to scale symbol to match font size +double QGITile::scaleToFont(void) const +{ + double fpx = getFontSize(); + double spx = getSymbolHeight(); + double factor = getSymbolFactor(); + double sf = (fpx / spx) * factor; + return sf; +} + +QString QGITile::getTextFont(void) const +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter(). + GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Labels"); + std::string fontName = hGrp->GetASCII("LabelFont", "osifont"); + return QString::fromStdString(fontName); +} + +void QGITile::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { + QStyleOptionGraphicsItem myOption(*option); + myOption.state &= ~QStyle::State_Selected; + +// painter->setPen(Qt::magenta); +// painter->drawRect(boundingRect()); //good for debugging + + QGIDecoration::paint (painter, &myOption, widget); +} + +QRectF QGITile::boundingRect() const +{ + return childrenBoundingRect(); +} + diff --git a/src/Mod/TechDraw/Gui/QGITile.h b/src/Mod/TechDraw/Gui/QGITile.h new file mode 100644 index 0000000000..b04d859d31 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGITile.h @@ -0,0 +1,114 @@ +/*************************************************************************** + * Copyright (c) 2019 WandererFan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef TECHDRAWGUI_QGITILE_H +#define TECHDRAWGUI_QGITILE_H + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "QGIArrow.h" +#include "QGCustomText.h" +#include "QGCustomRect.h" +#include "QGCustomSvg.h" +#include "QGIDecoration.h" + +namespace TechDraw { +class DrawTile; +class DrawTileWeld; +} + +namespace TechDrawGui +{ + +class TechDrawGuiExport QGITile : public QGIDecoration +{ +public: + explicit QGITile(TechDraw::DrawTile* tileFeat); + ~QGITile(void) {} + + enum {Type = QGraphicsItem::UserType + 325}; + int type(void) const { return Type;} + + virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ); + virtual QRectF boundingRect() const; + + void setTileTextLeft(std::string s); + void setTileTextRight(std::string s); + void setTileTextCenter(std::string s); + void setFont(QFont f, double fsize); + void setSymbolFile(std::string s); + void setTilePosition(QPointF org, int row, int col); + void setTileScale(double s); +// double getSymbolScale(void) const; + virtual void draw(void); + +protected: + virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); + + QColor getTileColor(void) const; + void setPrettyNormal(); + void setPrettyPre(); + void setPrettySel(); + + double getSymbolWidth(void) const; + double getSymbolHeight(void) const; + double getSymbolFactor(void) const; + QString getTextFont(void) const; + double getFontSize(void) const; + double scaleToFont(void) const; + void makeSymbol(void); + void makeText(void); + +private: + TechDraw::DrawTile* m_tileFeat; + QGCustomText* m_qgTextL; + QGCustomText* m_qgTextR; + QGCustomText* m_qgTextC; + QGCustomSvg* m_qgSvg; + QGraphicsColorizeEffect* m_effect; + QString m_svgPath; + QString m_textL; + QString m_textR; + QString m_textC; + QString m_fontName; + QFont m_font; + double m_textSize; + int m_row; + int m_col; + QPointF m_origin; + double m_wide; + double m_high; + double m_scale; +}; + +} + +#endif // TECHDRAWGUI_QGITILE_H diff --git a/src/Mod/TechDraw/Gui/QGIUserTypes.h b/src/Mod/TechDraw/Gui/QGIUserTypes.h index fa573c94e6..9c7f2fb8b1 100644 --- a/src/Mod/TechDraw/Gui/QGIUserTypes.h +++ b/src/Mod/TechDraw/Gui/QGIUserTypes.h @@ -47,6 +47,8 @@ QGIRichAnno: 233 QGMText: 300 QGEPath: 301 QGMarker: 302 +QGITile: 325 +QGIWeldSymbol: 340 */ /* diff --git a/src/Mod/TechDraw/Gui/QGIVertex.cpp b/src/Mod/TechDraw/Gui/QGIVertex.cpp index 5583493da3..7f23b76bf3 100644 --- a/src/Mod/TechDraw/Gui/QGIVertex.cpp +++ b/src/Mod/TechDraw/Gui/QGIVertex.cpp @@ -35,15 +35,16 @@ #include //#include +#include "QGIPrimPath.h" #include "QGIVertex.h" using namespace TechDrawGui; QGIVertex::QGIVertex(int index) : projIndex(index), - m_radius(2), - m_fill(Qt::SolidPattern) + m_radius(2) { + m_fill = Qt::SolidPattern; m_brush.setStyle(m_fill); setRadius(m_radius); @@ -62,8 +63,11 @@ void QGIVertex::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QStyleOptionGraphicsItem myOption(*option); myOption.state &= ~QStyle::State_Selected; - m_brush.setColor(m_colCurrent); - m_brush.setStyle(m_fill); - setBrush(m_brush); +// painter->setPen(Qt::blue); +// painter->drawRect(boundingRect()); //good for debugging + +// m_brush.setColor(m_colCurrent); +// m_brush.setStyle(m_fill); +// setBrush(m_brush); QGIPrimPath::paint (painter, &myOption, widget); } diff --git a/src/Mod/TechDraw/Gui/QGIVertex.h b/src/Mod/TechDraw/Gui/QGIVertex.h index 542ebdef70..ecf1d068b7 100644 --- a/src/Mod/TechDraw/Gui/QGIVertex.h +++ b/src/Mod/TechDraw/Gui/QGIVertex.h @@ -42,14 +42,14 @@ public: float getRadius() { return m_radius; } virtual void setRadius(float r); - Qt::BrushStyle getFill() { return m_fill; } - void setFill(Qt::BrushStyle f) { m_fill = f; } +/* Qt::BrushStyle getFill() { return m_fill; }*/ +/* void setFill(Qt::BrushStyle f) { m_fill = f; }*/ protected: int projIndex; float m_radius; - QBrush m_brush; - Qt::BrushStyle m_fill; +/* QBrush m_brush;*/ +/* Qt::BrushStyle m_fill;*/ private: }; diff --git a/src/Mod/TechDraw/Gui/QGIView.cpp b/src/Mod/TechDraw/Gui/QGIView.cpp index b91eec3f88..415b291155 100644 --- a/src/Mod/TechDraw/Gui/QGIView.cpp +++ b/src/Mod/TechDraw/Gui/QGIView.cpp @@ -82,7 +82,8 @@ QGIView::QGIView() :QGraphicsItemGroup(), viewObj(nullptr), m_locked(false), - m_innerView(false) + m_innerView(false), + m_selectState(0) { setCacheMode(QGraphicsItem::NoCache); setHandlesChildEvents(false); @@ -215,8 +216,10 @@ QVariant QGIView::itemChange(GraphicsItemChange change, const QVariant &value) if (change == ItemSelectedHasChanged && scene()) { if(isSelected()) { m_colCurrent = getSelectColor(); + m_selectState = 2; } else { m_colCurrent = getNormalColor(); + m_selectState = 0; } drawBorder(); } @@ -257,8 +260,10 @@ void QGIView::hoverEnterEvent(QGraphicsSceneHoverEvent *event) // TODO don't like this but only solution at the minute (MLP) if (isSelected()) { m_colCurrent = getSelectColor(); + m_selectState = 2; } else { m_colCurrent = getPreColor(); + m_selectState = 1; } drawBorder(); } @@ -268,8 +273,10 @@ void QGIView::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) Q_UNUSED(event); if(isSelected()) { m_colCurrent = getSelectColor(); + m_selectState = 1; } else { m_colCurrent = getNormalColor(); + m_selectState = 0; } drawBorder(); } @@ -622,6 +629,7 @@ bool QGIView::getFrameState(void) return result; } +//TODO: change name to prefNormalColor() QColor QGIView::getNormalColor() { Base::Reference hGrp = getParmGroupCol(); diff --git a/src/Mod/TechDraw/Gui/QGIView.h b/src/Mod/TechDraw/Gui/QGIView.h index f82a8901d0..e24b3bdd44 100644 --- a/src/Mod/TechDraw/Gui/QGIView.h +++ b/src/Mod/TechDraw/Gui/QGIView.h @@ -105,9 +105,12 @@ public: void alignTo(QGraphicsItem*, const QString &alignment); void setLocked(bool b) { m_locked = b; } - virtual QColor getNormalColor(void); - virtual QColor getPreColor(void); - virtual QColor getSelectColor(void); + virtual QColor getNormalColor(void); //preference + virtual QColor getPreColor(void); //preference + virtual QColor getSelectColor(void); //preference + virtual QColor getCurrentColor(void) { return m_colCurrent; } + virtual QColor getSettingColor(void) { return m_colSetting; } + virtual void setSettingColor(QColor c) { m_colSetting = c; } static Gui::ViewProvider* getViewProvider(App::DocumentObject* obj); static QGVPage* getGraphicsView(TechDraw::DrawView* dv); @@ -156,6 +159,7 @@ protected: QColor m_colNormal; QColor m_colPre; QColor m_colSel; + QColor m_colSetting; QFont m_font; QGCustomLabel* m_label; QGCustomBorder* m_border; @@ -165,6 +169,7 @@ protected: double m_lockWidth; double m_lockHeight; + int m_selectState; }; } // namespace diff --git a/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp b/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp new file mode 100644 index 0000000000..f7b3e9cf6c --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp @@ -0,0 +1,441 @@ +/*************************************************************************** + * Copyright (c) 2019 WandererFan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ + #include + #include + # include + # include + # include + # include + # include + + # include + # include + # include + # include + + # include +#endif + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include "Rez.h" +#include "ZVALUE.h" +#include "ViewProviderWeld.h" +#include "MDIViewPage.h" +#include "DrawGuiUtil.h" +#include "QGVPage.h" +#include "QGIPrimPath.h" +#include "QGITile.h" +#include "QGILeaderLine.h" +#include "QGIVertex.h" +#include "QGCustomText.h" + +#include "QGIWeldSymbol.h" + +using namespace TechDraw; +using namespace TechDrawGui; + + +//************************************************************** +QGIWeldSymbol::QGIWeldSymbol(QGILeaderLine* myParent, + TechDraw::DrawWeldSymbol* weld) : + m_weldFeat(weld), + m_qgLead(myParent), + m_blockDraw(false) +{ +// setHandlesChildEvents(true); //qt4 deprecated in qt5 + setFiltersChildEvents(true); //qt5 + setFlag(QGraphicsItem::ItemIsMovable, false); + + setCacheMode(QGraphicsItem::NoCache); + + setParentItem(m_qgLead); + setViewFeature(weld); + m_leadFeat = m_qgLead->getFeature(); + setZValue(ZVALUE::DIMENSION); + + m_tailText = new QGCustomText(); + addToGroup(m_tailText); + m_colCurrent = getNormalColor(); //preference + m_colSetting = m_colCurrent; +} + +QVariant QGIWeldSymbol::itemChange(GraphicsItemChange change, const QVariant &value) +{ +// Base::Console().Message("QGIWS::itemChange(%d)\n", change); + if (change == ItemSelectedHasChanged && scene()) { + if(isSelected()) { + setPrettySel(); + } else { + setPrettyNormal(); + } + draw(); + } else if(change == ItemSceneChange && scene()) { + // nothing special! + } + return QGIView::itemChange(change, value); +} + +void QGIWeldSymbol::updateView(bool update) +{ +// Base::Console().Message("QGIWS::updateView() %s\n",m_weldFeat->getNameInDocument()); + Q_UNUSED(update); + if ( m_weldFeat == nullptr ) { + Base::Console().Warning("QGIWS::updateView - no feature!\n"); + return; + } + draw(); +} + +void QGIWeldSymbol::draw() +{ +// Base::Console().Message("QGIWS::draw()- %s\n", m_weldFeat->getNameInDocument()); + if (!isVisible()) { + return; + } + + removeDecorations(); + + std::vector tiles = m_weldFeat->getTiles(); + for (auto& t: tiles) { + if (t != nullptr) { + QGITile* qt = new QGITile(t); + qt->setParentItem(this); + m_tiles.push_back(qt); + drawTile(t, qt); + } + } + + if (m_weldFeat->AllAround.getValue()) { + drawAllAround(); + } + + if (m_weldFeat->FieldWeld.getValue()) { + drawFieldFlag(); + } + + if (strlen(m_weldFeat->TailText.getValue()) != 0) { + drawProcessText(); + } +} + +void QGIWeldSymbol::drawTile(TechDraw::DrawTileWeld* dtw, + QGITile* tile) +{ +// Base::Console().Message("QGIWS::drawTile()\n"); + double featScale = m_leadFeat->getScale(); + + std::string tileTextL = dtw->LeftText.getValue(); + std::string tileTextR = dtw->RightText.getValue(); + std::string tileTextC = dtw->CenterText.getValue(); + tile->setSymbolFile(dtw->SymbolFile.getValue()); + int tileRow = dtw->TileRow.getValue(); + int tileCol = dtw->TileColumn.getValue(); + tile->setTileScale(featScale); + + QPointF org = getTileOrigin(); + tile->setTilePosition(org, tileRow, tileCol); + tile->setColor(getCurrentColor()); + tile->setTileTextLeft(tileTextL); + tile->setTileTextRight(tileTextR); + tile->setTileTextCenter(tileTextC); + tile->setZValue(ZVALUE::DIMENSION); + tile->draw(); +} + +void QGIWeldSymbol::drawAllAround(void) +{ +// Base::Console().Message("QGIWS::drawAllAround()\n"); + m_allAround = new QGIVertex(-1); + m_allAround->setParentItem(this); + + m_allAround->setFlag(QGraphicsItem::ItemIsSelectable, false); + m_allAround->setFlag(QGraphicsItem::ItemIsMovable, false); + m_allAround->setAcceptHoverEvents(false); + + m_allAround->setNormalColor(getCurrentColor()); + + m_allAround->setFill(Qt::NoBrush); + m_allAround->setRadius(calculateFontPixelSize(getDimFontSize())); + double width = m_qgLead->getLineWidth(); + m_allAround->setWidth(width); + m_allAround->setZValue(ZVALUE::DIMENSION); + + QPointF allAroundPos = getKinkPoint(); + m_allAround->setPos(allAroundPos); +} + +void QGIWeldSymbol::drawProcessText(void) +{ +// Base::Console().Message("QGIWS::drawProcessText()\n"); + m_tailText = new QGCustomText(); + m_tailText->setParentItem(this); + + m_font.setFamily(getPrefFont()); + m_font.setPixelSize(calculateFontPixelSize(getDimFontSize())); + + m_tailText->setFont(m_font); + std::string tText = m_weldFeat->TailText.getValue(); + m_tailText->setPlainText( + QString::fromUtf8(tText.c_str())); + m_tailText->setColor(getCurrentColor()); + m_tailText->setZValue(ZVALUE::DIMENSION); + + QPointF textPos = getTailPoint(); + + double textWidth = m_tailText->boundingRect().width(); + double charWidth = textWidth / tText.size(); + double hMargin = charWidth + getPrefArrowSize(); + + if (isTextRightSide()) { + m_tailText->justifyLeftAt(textPos.x() + hMargin, textPos.y(), true); + } else { + m_tailText->justifyRightAt(textPos.x() - hMargin, textPos.y(), true); + } +} + +void QGIWeldSymbol::drawFieldFlag() +{ +// Base::Console().Message("QGIWS::drawFieldFlag()\n"); + std::vector flagPoints = { QPointF(0.0, 0.0), + QPointF(0.0, -3.0), + QPointF(-2.0, -2.5), + QPointF(0.0, -2.0) }; + //flag sb about 2x text? + double scale = calculateFontPixelSize(getDimFontSize()) / 2.0; + QPainterPath path; + path.moveTo(flagPoints.at(0) * scale); + int i = 1; + int stop = flagPoints.size(); + for ( ; i < stop; i++) { + path.lineTo(flagPoints.at(i) * scale); + } + + m_fieldFlag = new QGIPrimPath(); + m_fieldFlag->setParentItem(this); + + m_fieldFlag->setFlag(QGraphicsItem::ItemIsSelectable, false); + m_fieldFlag->setFlag(QGraphicsItem::ItemIsMovable, false); + m_fieldFlag->setAcceptHoverEvents(false); + m_fieldFlag->setPath(path); + + m_fieldFlag->setNormalColor(getCurrentColor()); + m_fieldFlag->setFill(Qt::SolidPattern); + double width = m_qgLead->getLineWidth(); + m_fieldFlag->setWidth(width); + m_fieldFlag->setZValue(ZVALUE::DIMENSION); + + QPointF fieldFlagPos = getKinkPoint(); + m_fieldFlag->setPos(fieldFlagPos); +} + +void QGIWeldSymbol::removeDecorations() +{ +// Base::Console().Message("QGIWS::removeDecorations()\n"); + QList children = childItems(); + for (auto& c:children) { + QGITile* tile = dynamic_cast(c); + QGIPrimPath* prim = dynamic_cast(c); //allAround, fieldFlag + if (tile) { + tile->setParentItem(nullptr); + scene()->removeItem(tile); + delete tile; + } else if (prim) { + prim->setParentItem(nullptr); + scene()->removeItem(prim); + delete prim; + } + } + if (m_tailText != nullptr) { + m_tailText->setParentItem(nullptr); + scene()->removeItem(m_tailText); + delete m_tailText; + } + std::vector noTiles; + m_tiles = noTiles; +} + +void QGIWeldSymbol::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +{ + Q_UNUSED(event); + if (isSelected()) { + setPrettySel(); + m_colCurrent = getSelectColor(); + } else { + m_colCurrent = getPreColor(); + setPrettyPre(); + } + QGIView::hoverEnterEvent(event); +} + +void QGIWeldSymbol::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + Q_UNUSED(event); + if(isSelected()) { + m_colCurrent = getSelectColor(); + setPrettySel(); + } else { + m_colCurrent = m_colNormal; + setPrettyNormal(); + } + QGIView::hoverLeaveEvent(event); +} + +void QGIWeldSymbol::drawBorder() +{ +////Weld Symbols have no border! +// QGIView::drawBorder(); //good for debugging +} + +void QGIWeldSymbol::setPrettyNormal() +{ + for (auto t: m_tiles) { + t->setColor(m_colNormal); + t->draw(); + } + m_fieldFlag->setPrettyNormal(); + m_allAround->setPrettyNormal(); + m_tailText->setPrettyNormal(); +} + +void QGIWeldSymbol::setPrettyPre() +{ +// Base::Console().Message("QGIWS::setPrettyPre()\n"); + for (auto t: m_tiles) { + t->setColor(getPreColor()); + t->draw(); + } + m_fieldFlag->setPrettyPre(); + m_allAround->setPrettyPre(); + m_tailText->setPrettyPre(); +} + +void QGIWeldSymbol::setPrettySel() +{ +// Base::Console().Message("QGIWS::setPrettySel()\n"); + for (auto t: m_tiles) { + t->setColor(getSelectColor()); + t->draw(); + } + m_fieldFlag->setPrettySel(); + m_allAround->setPrettySel(); + m_tailText->setPrettySel(); +} + +QPointF QGIWeldSymbol::getTileOrigin(void) +{ + Base::Vector3d org = m_leadFeat->getTileOrigin(); + QPointF result(org.x, org.y); + return result; +} + +QPointF QGIWeldSymbol::getKinkPoint(void) +{ + Base::Vector3d org = m_leadFeat->getKinkPoint(); + QPointF result(org.x, org.y); + return result; +} + +QPointF QGIWeldSymbol::getTailPoint(void) +{ + Base::Vector3d org = m_leadFeat->getTailPoint(); + QPointF result(org.x, org.y); + return result; +} + +bool QGIWeldSymbol::isTextRightSide() +{ + bool result = true; + Base::Vector3d tail = m_leadFeat->getTailPoint(); + Base::Vector3d kink = m_leadFeat->getKinkPoint(); + if (tail.x < kink.x) { //tail is to left + result = false; + } + return result; +} + +TechDraw::DrawWeldSymbol* QGIWeldSymbol::getFeature(void) +{ + TechDraw::DrawWeldSymbol* result = + static_cast(getViewObject()); + return result; +} + +//preference +QColor QGIWeldSymbol::getNormalColor() +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/LeaderLines"); + App::Color fcColor; + fcColor.setPackedValue(hGrp->GetUnsigned("Color", 0x00000000)); + m_colNormal = fcColor.asValue(); + return m_colNormal; +} + +double QGIWeldSymbol::getPrefArrowSize() +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter(). + GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions"); + double size = Rez::guiX(hGrp->GetFloat("ArrowSize", 3.5)); + return size; +} + + +QRectF QGIWeldSymbol::boundingRect() const +{ + return customChildrenBoundingRect(); +} + +QPainterPath QGIWeldSymbol::shape() const +{ + return QGraphicsItemGroup::shape(); +} + +void QGIWeldSymbol::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { + QStyleOptionGraphicsItem myOption(*option); + myOption.state &= ~QStyle::State_Selected; + +// painter->setPen(Qt::red); +// painter->drawRect(boundingRect()); //good for debugging + + QGIView::paint (painter, &myOption, widget); +} + +#include diff --git a/src/Mod/TechDraw/Gui/QGIWeldSymbol.h b/src/Mod/TechDraw/Gui/QGIWeldSymbol.h new file mode 100644 index 0000000000..8fd9c80b6f --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIWeldSymbol.h @@ -0,0 +1,120 @@ +/*************************************************************************** + * Copyright (c) 2019 WandererFan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef DRAWINGGUI_QGRAPHICSITEMWELDSYMBOL_H +#define DRAWINGGUI_QGRAPHICSITEMWELDSYMBOL_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "QGIView.h" + +namespace TechDraw { +class DrawWeldSymbol; +class DrawWeldSymbol; +class DrawView; +} + +namespace TechDrawGui +{ +class QGIPrimPath; +class QGITile; +class QGIVertex; +class QGCustomText; + +//******************************************************************* + +class TechDrawGuiExport QGIWeldSymbol : public QGIView +{ + Q_OBJECT + +public: + enum {Type = QGraphicsItem::UserType + 340}; + + explicit QGIWeldSymbol(QGILeaderLine* myParent = nullptr, + TechDraw::DrawWeldSymbol* lead = nullptr); + ~QGIWeldSymbol() = default; + + int type() const override { return Type;} + virtual void paint( QPainter * painter, + const QStyleOptionGraphicsItem * option, + QWidget * widget = 0 ) override; + virtual QRectF boundingRect() const override; + virtual QPainterPath shape(void) const override; + double getEdgeFuzz(void) const; + + virtual void drawBorder() override; + virtual void updateView(bool update = false) override; + + virtual TechDraw::DrawWeldSymbol* getFeature(void); + QPointF getTileOrigin(void); + QPointF getKinkPoint(void); + QPointF getTailPoint(void); + bool isTextRightSide(void); + + virtual void setPrettyNormal(); + virtual void setPrettySel(); + virtual void setPrettyPre(); + +protected: + virtual QVariant itemChange( GraphicsItemChange change, + const QVariant &value ) override; + virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override; + virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override; + + virtual void draw() override; + void drawTile(TechDraw::DrawTileWeld* dtw, + QGITile* tile); + void drawAllAround(void); + void drawProcessText(void); + void drawFieldFlag(); + void removeDecorations(); + +protected: + virtual QColor getNormalColor() override; + double getPrefArrowSize(); + + TechDraw::DrawWeldSymbol* m_weldFeat; + TechDraw::DrawLeaderLine* m_leadFeat; + + QGILeaderLine* m_qgLead; + std::vector m_tiles; + QGCustomText* m_tailText; + QGIPrimPath* m_fieldFlag; + QGIVertex* m_allAround; + + QFont m_font; + + bool m_blockDraw; //prevent redraws while updating. +}; + +} + +#endif // DRAWINGGUI_QGRAPHICSITEMWELDSYMBOL_H diff --git a/src/Mod/TechDraw/Gui/QGVPage.cpp b/src/Mod/TechDraw/Gui/QGVPage.cpp index 30775824f5..3cabcef82d 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.cpp +++ b/src/Mod/TechDraw/Gui/QGVPage.cpp @@ -75,6 +75,7 @@ #include #include #include +#include #include #include "Rez.h" @@ -96,6 +97,7 @@ #include "QGIFace.h" #include "QGILeaderLine.h" #include "QGIRichAnno.h" +#include "QGIWeldSymbol.h" #include "ZVALUE.h" #include "ViewProviderPage.h" @@ -545,6 +547,34 @@ QGIView * QGVPage::addRichAnno(TechDraw::DrawRichAnno* anno) return annoGroup; } +QGIView * QGVPage::addWeldSymbol(TechDraw::DrawWeldSymbol* weld) +{ +// Base::Console().Message("QGVP::addWeldSymbol()\n"); + QGIWeldSymbol* weldGroup = nullptr; + TechDraw::DrawView* parentDV = nullptr; + + App::DocumentObject* parentObj = weld->Leader.getValue(); + if (parentObj != nullptr) { + parentDV = dynamic_cast(parentObj); + } else { + Base::Console().Message("QGVP::addWeldSymbol - no parent doc obj\n"); + } + if (parentDV != nullptr) { + QGIView* parentQV = findQViewForDocObj(parentObj); + QGILeaderLine* leadParent = dynamic_cast(parentQV); + if (leadParent != nullptr) { + weldGroup = new QGIWeldSymbol(leadParent, weld); + weldGroup->updateView(true); + } else { + Base::Console().Message("QGVP::addWeldSymbol - no parent QGILL\n"); + } + } else { + Base::Console().Message("QGVP::addWeldSymbol - parent is not DV!\n"); + } + return weldGroup; +} + + //! find the graphic for a DocumentObject QGIView * QGVPage::findQViewForDocObj(App::DocumentObject *obj) const { diff --git a/src/Mod/TechDraw/Gui/QGVPage.h b/src/Mod/TechDraw/Gui/QGVPage.h index 52904916ac..65f350730f 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.h +++ b/src/Mod/TechDraw/Gui/QGVPage.h @@ -45,6 +45,7 @@ class DrawViewImage; class DrawLeaderLine; class DrawViewBalloon; class DrawRichAnno; +class DrawWeldSymbol; } namespace TechDrawGui @@ -84,6 +85,7 @@ public: QGIView * addDrawViewImage(TechDraw::DrawViewImage *view); QGIView * addViewLeader(TechDraw::DrawLeaderLine* view); QGIView * addRichAnno(TechDraw::DrawRichAnno* anno); + QGIView * addWeldSymbol(TechDraw::DrawWeldSymbol* weld); QGIView* findQViewForDocObj(App::DocumentObject *obj) const; QGIView* getQGIVByName(std::string name); diff --git a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc index 207cd03eef..0c0c5060e1 100644 --- a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc +++ b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc @@ -73,6 +73,8 @@ icons/actions/techdraw-linedecor.svg icons/actions/techdraw-facedecor.svg icons/actions/techdraw-showall.svg + icons/actions/techdraw-weldsymbol.svg + icons/actions/techdraw-tile.svg icons/actions/section-up.svg icons/actions/section-down.svg icons/actions/section-left.svg diff --git a/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-tile.svg b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-tile.svg new file mode 100644 index 0000000000..e746e04f5a --- /dev/null +++ b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-tile.svg @@ -0,0 +1,158 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-weldsymbol.svg b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-weldsymbol.svg new file mode 100644 index 0000000000..578a705c73 --- /dev/null +++ b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-weldsymbol.svg @@ -0,0 +1,171 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp new file mode 100644 index 0000000000..917f2d9478 --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp @@ -0,0 +1,533 @@ +/*************************************************************************** + * Copyright (c) 2019 Wandererfan +#include +#include + +#endif // #ifndef _PreComp_ + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "DrawGuiStd.h" +#include "QGVPage.h" +#include "QGIView.h" +#include "QGIPrimPath.h" +#include "QGILeaderLine.h" +#include "MDIViewPage.h" +#include "ViewProviderPage.h" +#include "ViewProviderViewPart.h" +#include "Rez.h" + +#include "TaskWeldingSymbol.h" + +using namespace Gui; +using namespace TechDraw; +using namespace TechDrawGui; + +//ctor for creation +TaskWeldingSymbol::TaskWeldingSymbol(TechDraw::DrawLeaderLine* leader) : + ui(new Ui_TaskWeldingSymbol), + m_leadFeat(leader), + m_arrowCount(0), + m_otherCount(0) +{ +// Base::Console().Message("TWS::TWS() - create mode\n"); + if (m_leadFeat == nullptr) { + //should be caught in CMD caller + Base::Console().Error("TaskWeldingSymbol - bad parameters. Can not proceed.\n"); + return; + } + + ui->setupUi(this); + connect(ui->pbArrow0, SIGNAL(clicked(bool)), + this, SLOT(onArrow0Clicked(bool))); + connect(ui->pbArrow1, SIGNAL(clicked(bool)), + this, SLOT(onArrow1Clicked(bool))); + connect(ui->pbOther0, SIGNAL(clicked(bool)), + this, SLOT(onOther0Clicked(bool))); + connect(ui->pbOther1, SIGNAL(clicked(bool)), + this, SLOT(onOther1Clicked(bool))); + connect(ui->fcSymbolDir, SIGNAL(fileNameSelected(const QString&)), + this, SLOT(onDirectorySelected(const QString&))); + + setUiPrimary(); +} + +TaskWeldingSymbol::~TaskWeldingSymbol() +{ + delete ui; +} + +void TaskWeldingSymbol::updateTask() +{ +// blockUpdate = true; + +// blockUpdate = false; +} + +void TaskWeldingSymbol::changeEvent(QEvent *e) +{ + if (e->type() == QEvent::LanguageChange) { + ui->retranslateUi(this); + } +} + +void TaskWeldingSymbol::setUiPrimary() +{ +// Base::Console().Message("TWS::setUiPrimary()\n"); + setWindowTitle(QObject::tr("Create Welding Symbol")); + m_currDir = QString::fromUtf8(prefSymbolDir().c_str()); + ui->fcSymbolDir->setFileName(m_currDir); + loadSymbolNames(m_currDir); + + ui->lwSymbols->setViewMode(QListView::IconMode); + ui->lwSymbols->setFlow(QListView::LeftToRight); + ui->lwSymbols->setWrapping(true); + ui->lwSymbols->setDragEnabled(true); + ui->lwSymbols->setSelectionMode(QAbstractItemView::SingleSelection); + ui->lwSymbols->setAcceptDrops(false); +} + +void TaskWeldingSymbol::setUiEdit() +{ +// Base::Console().Message("TWS::setUiEdit()\n"); + setWindowTitle(QObject::tr("Edit Welding Symbol")); +} + +void TaskWeldingSymbol::onArrow0Clicked(bool b) +{ +// Base::Console().Message("TWS::OnArrow0Clicked()\n"); + Q_UNUSED(b); + Qt::KeyboardModifiers km = QApplication::keyboardModifiers(); + if (km & Qt::ControlModifier) { + ui->pbArrow0->setText(QString::fromUtf8("Add")); + ui->pbArrow0->setIcon(QIcon()); + removePendingTile(0,0); + return; + } + + QListWidgetItem* sourceItem = ui->lwSymbols->currentItem(); + QString targetText = sourceItem->text(); + TechDrawGui::Tile2Add newTile; + + QString iconPath = m_currDir + + targetText + + QString::fromUtf8(".svg") ; + + QIcon targetIcon(iconPath); + QSize iconSize(32,32); + ui->pbArrow0->setIcon(targetIcon); + ui->pbArrow0->setIconSize(iconSize); + ui->pbArrow0->setText(QString()); + + newTile.arrowSide = true; + newTile.symbolPath = Base::Tools::toStdString(iconPath); + newTile.leftText = Base::Tools::toStdString(ui->leLeftText->text()); + newTile.centerText = Base::Tools::toStdString(ui->leCenterText->text()); + newTile.rightText = Base::Tools::toStdString(ui->leRightText->text()); + newTile.row = 0; + newTile.col = 0; + m_tiles2Add.push_back(newTile); + m_arrowCount++; +} + +void TaskWeldingSymbol::onArrow1Clicked(bool b) +{ +// Base::Console().Message("TWS::OnArrow1Clicked()\n"); + Q_UNUSED(b); + Qt::KeyboardModifiers km = QApplication::keyboardModifiers(); + if (km & Qt::ControlModifier) { + ui->pbArrow1->setText(QString::fromUtf8("Add")); + ui->pbArrow1->setIcon(QIcon()); + removePendingTile(0,1); + return; + } + + QListWidgetItem* sourceItem = ui->lwSymbols->currentItem(); + QString targetText = sourceItem->text(); + TechDrawGui::Tile2Add newTile; + + QString iconPath = m_currDir + + targetText + + QString::fromUtf8(".svg") ; + + QIcon targetIcon(iconPath); + QSize iconSize(32,32); + ui->pbArrow1->setIcon(targetIcon); + ui->pbArrow1->setIconSize(iconSize); + ui->pbArrow1->setText(QString()); + + newTile.arrowSide = true; + newTile.symbolPath = Base::Tools::toStdString(iconPath); + newTile.leftText = Base::Tools::toStdString(ui->leLeftText->text()); + newTile.centerText = Base::Tools::toStdString(ui->leCenterText->text()); + newTile.rightText = Base::Tools::toStdString(ui->leRightText->text()); + newTile.row = 0; + newTile.col = 1; + m_tiles2Add.push_back(newTile); + m_arrowCount++; +} + +void TaskWeldingSymbol::onOther0Clicked(bool b) +{ +// Base::Console().Message("TWS::onOther0Clicked()\n"); + Q_UNUSED(b); + Qt::KeyboardModifiers km = QApplication::keyboardModifiers(); + if (km & Qt::ControlModifier) { + ui->pbOther0->setText(QString::fromUtf8("Add")); + ui->pbOther0->setIcon(QIcon()); + removePendingTile(-1,0); + return; + } + + QListWidgetItem* sourceItem = ui->lwSymbols->currentItem(); + QString targetText = sourceItem->text(); + TechDrawGui::Tile2Add newTile; + + QString iconPath = m_currDir + + targetText + + QString::fromUtf8(".svg") ; + + QIcon targetIcon(iconPath); + QSize iconSize(32,32); + ui->pbOther0->setIcon(targetIcon); + ui->pbOther0->setIconSize(iconSize); + ui->pbOther0->setText(QString()); + + newTile.arrowSide = false; + newTile.symbolPath = Base::Tools::toStdString(iconPath); + newTile.leftText = Base::Tools::toStdString(ui->leLeftText->text()); + newTile.centerText = Base::Tools::toStdString(ui->leCenterText->text()); + newTile.rightText = Base::Tools::toStdString(ui->leRightText->text()); + newTile.row = -1; + newTile.col = 0; + m_tiles2Add.push_back(newTile); + m_otherCount++; +} + +void TaskWeldingSymbol::onOther1Clicked(bool b) +{ +// Base::Console().Message("TWS::onOther1Clicked()\n"); + Q_UNUSED(b); + Qt::KeyboardModifiers km = QApplication::keyboardModifiers(); + if (km & Qt::ControlModifier) { + ui->pbOther1->setText(QString::fromUtf8("Add")); + ui->pbOther1->setIcon(QIcon()); + removePendingTile(-1,1); + return; + } + + QListWidgetItem* sourceItem = ui->lwSymbols->currentItem(); + QString targetText = sourceItem->text(); + TechDrawGui::Tile2Add newTile; + + QString iconPath = m_currDir + + targetText + + QString::fromUtf8(".svg") ; + + QIcon targetIcon(iconPath); + QSize iconSize(32,32); + ui->pbOther1->setIcon(targetIcon); + ui->pbOther1->setIconSize(iconSize); + ui->pbOther1->setText(QString()); + + newTile.arrowSide = false; + newTile.symbolPath = Base::Tools::toStdString(iconPath); + newTile.leftText = Base::Tools::toStdString(ui->leLeftText->text()); + newTile.centerText = Base::Tools::toStdString(ui->leCenterText->text()); + newTile.rightText = Base::Tools::toStdString(ui->leRightText->text()); + newTile.row = -1; + newTile.col = 1; + m_tiles2Add.push_back(newTile); + m_otherCount++; +} + +void TaskWeldingSymbol::onDirectorySelected(const QString& newDir) +{ +// Base::Console().Message("TWS::onDirectorySelected(%s)\n", qPrintable(newDir)); + m_currDir = newDir + QString::fromUtf8("/"); + loadSymbolNames(m_currDir); +} + +void TaskWeldingSymbol::removePendingTile(int row, int col) +{ +// Base::Console().Message("TWS::removePendingIcon(%d, %d) - tiles in: %d\n", +// row, col, m_tiles2Add.size()); + std::vector newList; + for (auto& t: m_tiles2Add) { + if ((t.row == row) && + (t.col == col) ) { + continue; + } else { + newList.push_back(t); + } + } + m_tiles2Add = newList; +} + + +void TaskWeldingSymbol::blockButtons(bool b) +{ + Q_UNUSED(b); +} + +void TaskWeldingSymbol::loadSymbolNames(QString pathToSymbols) +{ + //fill selection list with names and icons + QDir symbolDir(pathToSymbols); + symbolDir.setFilter(QDir::Files); + QStringList fileNames = symbolDir.entryList(); + + for (auto& fn: fileNames) { + QListWidgetItem* item = new QListWidgetItem(fn, ui->lwSymbols); + QFileInfo fi(fn); + item->setText(fi.baseName()); + QIcon symbolIcon(pathToSymbols + fn); + item->setIcon(symbolIcon); + ui->lwSymbols->addItem(item); + } + ui->lwSymbols->setCurrentRow(0); + ui->lwSymbols->setAcceptDrops(false); //have to do this every time you update the items +} + +//****************************************************************************** +App::DocumentObject* TaskWeldingSymbol::createWeldingSymbol(void) +{ +// Base::Console().Message("TWS::createWeldingSymbol()\n"); + Gui::Command::openCommand("Create WeldSymbol"); + + std::string symbolName = m_leadFeat->getDocument()->getUniqueObjectName("DrawWeldSymbol"); + std::string symbolType = "TechDraw::DrawWeldSymbol"; + + TechDraw::DrawPage* page = m_leadFeat->findParentPage(); + std::string pageName = page->getNameInDocument(); + + Command::doCommand(Command::Doc,"App.activeDocument().addObject('%s','%s')", + symbolType.c_str(),symbolName.c_str()); + Command::doCommand(Command::Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)", + pageName.c_str(), symbolName.c_str()); + Command::doCommand(Command::Doc,"App.activeDocument().%s.Leader = App.activeDocument().%s", + symbolName.c_str(),m_leadFeat->getNameInDocument()); + + bool allAround = ui->rbAllAround->isChecked(); + std::string allAroundText = allAround ? "True" : "False"; + Command::doCommand(Command::Doc,"App.activeDocument().%s.AllAround = %s", + symbolName.c_str(), allAroundText.c_str()); + + bool fieldWeld = ui->rbFieldWeld->isChecked(); + std::string fieldWeldText = fieldWeld ? "True" : "False"; + Command::doCommand(Command::Doc,"App.activeDocument().%s.FieldWeld = %s", + symbolName.c_str(), fieldWeldText.c_str()); + + std::string tailText = Base::Tools::toStdString(ui->leProcessText->text()); + Command::doCommand(Command::Doc,"App.activeDocument().%s.TailText = '%s'", + symbolName.c_str(), tailText.c_str()); + + App::DocumentObject* newObj = m_leadFeat->getDocument()->getObject(symbolName.c_str()); + if (newObj == nullptr) { + throw Base::RuntimeError("TaskWeldingSymbol - new symbol object not found"); + } + newObj->recomputeFeature(); + Gui::Command::updateActive(); + Gui::Command::commitCommand(); + return newObj; +} + +std::vector TaskWeldingSymbol::createTiles(void) +{ +// Base::Console().Message("TWS::createTiles()\n"); + Gui::Command::openCommand("Create Welding Tiles"); + std::vector tileFeats; + std::string tileType("TechDraw::DrawTileWeld"); + for (auto& t: m_tiles2Add) { + std::string tileName = m_leadFeat->getDocument()->getUniqueObjectName("DrawTileWeld"); + Command::doCommand(Command::Doc,"App.activeDocument().addObject('%s','%s')", + tileType.c_str(),tileName.c_str()); + Command::doCommand(Command::Doc,"App.activeDocument().%s.TileRow = %d", + tileName.c_str(), t.row); + Command::doCommand(Command::Doc,"App.activeDocument().%s.TileColumn = %d", + tileName.c_str(), t.col); + Command::doCommand(Command::Doc,"App.activeDocument().%s.SymbolFile = '%s'", + tileName.c_str(), t.symbolPath.c_str()); + Command::doCommand(Command::Doc,"App.activeDocument().%s.LeftText = '%s'", + tileName.c_str(), t.leftText.c_str()); + Command::doCommand(Command::Doc,"App.activeDocument().%s.RightText = '%s'", + tileName.c_str(), t.rightText.c_str()); + Command::doCommand(Command::Doc,"App.activeDocument().%s.CenterText = '%s'", + tileName.c_str(), t.centerText.c_str()); + + App::DocumentObject* newTile = m_leadFeat->getDocument()->getObject(tileName.c_str()); + if (newTile == nullptr) { + throw Base::RuntimeError("TaskWeldingSymbol - new tile object not found"); + } + tileFeats.push_back(newTile); + } + + Gui::Command::updateActive(); + Gui::Command::commitCommand(); + return tileFeats; +} + +void TaskWeldingSymbol::updateWeldingSymbol(void) +{ +// Base::Console().Message("TWS::updateWeldingSymbol()\n"); + Gui::Command::openCommand("Edit WeldingSymbol"); + m_weldFeat->requestPaint(); + + Gui::Command::updateActive(); + Gui::Command::commitCommand(); +} + +void TaskWeldingSymbol::saveButtons(QPushButton* btnOK, + QPushButton* btnCancel) +{ + m_btnOK = btnOK; + m_btnCancel = btnCancel; +} + +void TaskWeldingSymbol::enableTaskButtons(bool b) +{ + m_btnOK->setEnabled(b); + m_btnCancel->setEnabled(b); +} + +std::string TaskWeldingSymbol::prefSymbolDir() +{ + std::string defaultDir = App::Application::getResourceDir() + "Mod/TechDraw/Symbols/Welding/AWS/"; + Base::Reference hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")-> + GetGroup("Preferences")->GetGroup("Mod/TechDraw/Files"); + + std::string symbolDir = hGrp->GetASCII("WeldingDir", defaultDir.c_str()); + return symbolDir; +} + +//****************************************************************************** + +bool TaskWeldingSymbol::accept() +{ +// Base::Console().Message("TWS::accept()\n"); + std::vector tileFeats = createTiles(); + App::DocumentObject* weldFeat = createWeldingSymbol(); + for (auto& obj: tileFeats) { + TechDraw::DrawTileWeld* tile = dynamic_cast(obj); + tile->TileParent.setValue(weldFeat); + } + weldFeat->recomputeFeature(); +// weldFeat->requestPaint(); //not a dv! + + Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); + + return true; +} + +bool TaskWeldingSymbol::reject() +{ +// Base::Console().Message("TWS::reject()\n"); + //nothing to remove. + + Gui::Command::doCommand(Gui::Command::Gui,"App.activeDocument().recompute()"); + Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); + + return false; +} +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +TaskDlgWeldingSymbol::TaskDlgWeldingSymbol(TechDraw::DrawLeaderLine* leader) + : TaskDialog() +{ + widget = new TaskWeldingSymbol(leader); + taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/techdraw-weldsymbol"), + widget->windowTitle(), true, 0); + taskbox->groupLayout()->addWidget(widget); + Content.push_back(taskbox); +} + +TaskDlgWeldingSymbol::~TaskDlgWeldingSymbol() +{ +} + +void TaskDlgWeldingSymbol::update() +{ +// widget->updateTask(); +} + +void TaskDlgWeldingSymbol::modifyStandardButtons(QDialogButtonBox* box) +{ + QPushButton* btnOK = box->button(QDialogButtonBox::Ok); + QPushButton* btnCancel = box->button(QDialogButtonBox::Cancel); + widget->saveButtons(btnOK, btnCancel); +} + +//==== calls from the TaskView =============================================================== +void TaskDlgWeldingSymbol::open() +{ +} + +void TaskDlgWeldingSymbol::clicked(int) +{ +} + +bool TaskDlgWeldingSymbol::accept() +{ + widget->accept(); + return true; +} + +bool TaskDlgWeldingSymbol::reject() +{ + widget->reject(); + return true; +} + +#include diff --git a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.h b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.h new file mode 100644 index 0000000000..a935545f62 --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.h @@ -0,0 +1,178 @@ +/*************************************************************************** + * Copyright (c) 2019 WandererFan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef TECHDRAWGUI_TASKWELDINGSYMBOL_H +#define TECHDRAWGUI_TASKWELDINGSYMBOL_H + +#include + +#include +#include +#include +#include + +#include + + +class Ui_TaskWeldingSymbol; +class Ui_TaskCL2Lines; + +namespace App { +class DocumentObject; +} + +namespace TechDraw +{ +class DrawPage; +class DrawView; +class DrawLeaderLine; +class DrawWeldSymbol; +} + +namespace TechDraw +{ +class Face; +} + +namespace TechDrawGui +{ +class QGVPage; +class QGIView; +class QGILeaderLine; +class QGIWeldSymbol; +class MDIViewPage; +//class ViewProviderWeld; + +class Tile2Add +{ +public: + Tile2Add() {}; + ~Tile2Add() = default; + bool arrowSide; // or is row enough? + int row; + int col; + std::string leftText; + std::string centerText; + std::string rightText; + std::string symbolPath; +}; + +class TaskWeldingSymbol : public QWidget +{ + Q_OBJECT + +public: + TaskWeldingSymbol(TechDraw::DrawLeaderLine* baseFeat); + ~TaskWeldingSymbol(); + +public Q_SLOTS: + void onArrow0Clicked(bool b); + void onArrow1Clicked(bool b); + void onOther0Clicked(bool b); + void onOther1Clicked(bool b); + void onDirectorySelected(const QString& newDir); + +public: + virtual bool accept(); + virtual bool reject(); + void updateTask(); + void saveButtons(QPushButton* btnOK, + QPushButton* btnCancel); + void enableTaskButtons(bool b); + void setFlipped(bool b); + +protected Q_SLOTS: + +protected: + void changeEvent(QEvent *e); + + void blockButtons(bool b); + void setUiPrimary(void); + void setUiEdit(); + + void turnOnArrow(); + void turnOnOther(); + void removePendingTile(int row, int col); + + + App::DocumentObject* createWeldingSymbol(void); + void updateWeldingSymbol(void); + std::vector createTiles(void); + + void loadSymbolNames(QString pathToSymbols); + + std::string prefSymbolDir(); + QString m_currDir; + + +private: + Ui_TaskWeldingSymbol * ui; + + TechDraw::DrawLeaderLine* m_leadFeat; + TechDraw::DrawWeldSymbol* m_weldFeat; + + std::vector m_tiles2Add; + + QPushButton* m_btnOK; + QPushButton* m_btnCancel; + + int m_arrowCount; + int m_otherCount; +}; + + +class TaskDlgWeldingSymbol : public Gui::TaskView::TaskDialog +{ + Q_OBJECT + +public: + TaskDlgWeldingSymbol(TechDraw::DrawLeaderLine* leader); + ~TaskDlgWeldingSymbol(); + +public: + /// is called the TaskView when the dialog is opened + virtual void open(); + /// is called by the framework if an button is clicked which has no accept or reject role + virtual void clicked(int); + /// is called by the framework if the dialog is accepted (Ok) + virtual bool accept(); + /// is called by the framework if the dialog is rejected (Cancel) + virtual bool reject(); + /// is called by the framework if the user presses the help button + virtual void helpRequested() { return;} + virtual bool isAllowedAlterDocument(void) const + { return false; } + void update(); + + void modifyStandardButtons(QDialogButtonBox* box); + +protected: + +private: + TaskWeldingSymbol* widget; + Gui::TaskView::TaskBox* taskbox; + +}; + +} //namespace TechDrawGui + +#endif // #ifndef TECHDRAWGUI_TASKWELDINGSYMBOL_H diff --git a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.ui b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.ui new file mode 100644 index 0000000000..711dd4c0e2 --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.ui @@ -0,0 +1,398 @@ + + + TaskWeldingSymbol + + + + 0 + 0 + 409 + 578 + + + + + 0 + 0 + + + + + 250 + 0 + + + + Welding Symbol + + + + :/icons/actions/techdraw-weldsymbol.svg:/icons/actions/techdraw-weldsymbol.svg + + + + + + + 0 + 0 + + + + QFrame::Box + + + QFrame::Raised + + + + + + + + + + + 0 + 0 + + + + + 0 + 32 + + + + + 0 + 32 + + + + Add an Arrow Side Symbol + + + + + + Add + + + + + + + + 0 + 0 + + + + + 0 + 32 + + + + + 0 + 32 + + + + Add an Arrow Side Symbol + + + Add + + + + + + + + + QFrame::Plain + + + 5 + + + Qt::Horizontal + + + + + + + + + + 0 + 0 + + + + + 0 + 32 + + + + + 0 + 32 + + + + Add an Other Side Symbol + + + Add + + + + + + + + 0 + 0 + + + + + 0 + 32 + + + + + 0 + 32 + + + + Add an Other Side Symbol + + + Add + + + + + + + + + + + + 0 + 0 + + + + + 0 + 128 + + + + + 16777215 + 256 + + + + + 0 + 64 + + + + + 0 + 128 + + + + Select a symbol + + + QListView::Static + + + QListView::LeftToRight + + + true + + + QListView::Adjust + + + + 64 + 64 + + + + QListView::IconMode + + + false + + + false + + + -1 + + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Left Text + + + + + + + Text before symbol + + + + + + + Center Text + + + + + + + Text above/below symbol + + + + + + + Right Text + + + + + + + Text after symbol + + + + + + + + + + + + + Qt::Horizontal + + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Symbol Directory + + + + + + + Pick a directory of welding symbols + + + Gui::FileChooser::Directory + + + *.svg + + + + + + + Process Text + + + + + + + Text at end of symbol + + + + + + + Show on site flag + + + Field Weld + + + false + + + + + + + show perimeter circle + + + All Around + + + false + + + + + + + + + + + + + Gui::FileChooser + QWidget +
Gui/FileDialog.h
+
+
+ + + + +
diff --git a/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp b/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp index a91b8a8da3..9dbc73ba9c 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp @@ -88,9 +88,17 @@ void ViewProviderDrawingView::attach(App::DocumentObject *pcFeat) connectGuiRepaint = feature->signalGuiPaint.connect(bnd); //TODO: would be good to start the QGIV creation process here, but no guarantee we actually have // MDIVP or QGVP yet. + // but parent page might. we may not be part of the document yet though! + // :( we're not part of the page yet either! } else { Base::Console().Warning("VPDV::attach has no Feature!\n"); } +// TechDraw::DrawView* view = static_cast(pcFeat); +// TechDraw::DrawPage* page = view->findParentPage(); +// TechDraw::DrawPage* page = feature->findParentPage(); +// Base::Console().Message("VPDV::attach(%X) - parent: %X\n", +// pcFeat, page); +// pcFeat->getNameInDocument(), page->getNameInDocument()); } void ViewProviderDrawingView::setDisplayMode(const char* ModeName) @@ -232,7 +240,7 @@ MDIViewPage* ViewProviderDrawingView::getMDIViewPage() const { MDIViewPage* result = nullptr; Gui::Document* guiDoc = Gui::Application::Instance->getDocument(getViewObject()->getDocument()); - Gui::ViewProvider* vp = guiDoc->getViewProvider(getViewObject()->findParentPage()); + Gui::ViewProvider* vp = guiDoc->getViewProvider(getViewObject()->findParentPage()); //if not in page.views, !@#$% ViewProviderPage* dvp = dynamic_cast(vp); if (dvp) { result = dvp->getMDIViewPage(); @@ -256,6 +264,9 @@ void ViewProviderDrawingView::onGuiRepaint(const TechDraw::DrawView* dv) } else { //we are not part of the Gui page yet. ask page to add us. //TODO: this bit causes trouble. Should move QGIV creation to attach? // is MDIVP/QGVP available at attach time? + // wf: mdivp/qgvp is not necessarily directly available at attach time. It should be available + // via the parent DrawPage since the DP is created before any views. +// Base::Console().Message("VPDV::onGuiRepaint - no QGIV for: %s\n",dv->getNameInDocument()); MDIViewPage* page = getMDIViewPage(); if (page != nullptr) { page->addView(dv); diff --git a/src/Mod/TechDraw/Gui/ViewProviderLeader.cpp b/src/Mod/TechDraw/Gui/ViewProviderLeader.cpp index 050a9131cd..83e4b1e5b8 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderLeader.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderLeader.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include "MDIViewPage.h" #include "QGVPage.h" @@ -153,12 +154,15 @@ std::vector ViewProviderLeader::claimChildren(void) const // Collect any child Document Objects and put them in the right place in the Feature tree // valid children of a ViewLeader are: // - Rich Annotations + // - Weld Symbols std::vector temp; const std::vector &views = getFeature()->getInList(); try { for(std::vector::const_iterator it = views.begin(); it != views.end(); ++it) { if ((*it)->getTypeId().isDerivedFrom(TechDraw::DrawRichAnno::getClassTypeId())) { temp.push_back((*it)); + } else if ((*it)->getTypeId().isDerivedFrom(TechDraw::DrawWeldSymbol::getClassTypeId())) { + temp.push_back((*it)); } } return temp; diff --git a/src/Mod/TechDraw/Gui/ViewProviderPage.cpp b/src/Mod/TechDraw/Gui/ViewProviderPage.cpp index beba8cea54..f1bb574649 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderPage.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderPage.cpp @@ -58,6 +58,7 @@ #include #include #include +#include #include #include "MDIViewPage.h" @@ -283,10 +284,11 @@ std::vector ViewProviderPage::claimChildren(void) const // for Page, valid children are any View except: DrawProjGroupItem // DrawViewDimension // DrawViewBalloon - // DrawLeader - // DrawRichAnno (if not a child of View) + // DrawLeaderLine + // DrawRichAnno // any FeatuerView in a DrawViewClip // DrawHatch + // DrawWeldSymbol const std::vector &views = getDrawPage()->Views.getValues(); @@ -312,6 +314,7 @@ std::vector ViewProviderPage::claimChildren(void) const docObj->isDerivedFrom(TechDraw::DrawViewBalloon::getClassTypeId()) || docObj->isDerivedFrom(TechDraw::DrawRichAnno::getClassTypeId()) || docObj->isDerivedFrom(TechDraw::DrawLeaderLine::getClassTypeId()) || + docObj->isDerivedFrom(TechDraw::DrawWeldSymbol::getClassTypeId()) || (featView && featView->isInClip()) ) continue; else diff --git a/src/Mod/TechDraw/Gui/ViewProviderTile.cpp b/src/Mod/TechDraw/Gui/ViewProviderTile.cpp new file mode 100644 index 0000000000..90fdec3170 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderTile.cpp @@ -0,0 +1,90 @@ +/*************************************************************************** + * Copyright (c) 2019 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" + +#ifndef _PreComp_ +#endif + +/// Here the FreeCAD includes sorted by Base,App,Gui...... +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ViewProviderTile.h" + +using namespace TechDrawGui; + +PROPERTY_SOURCE(TechDrawGui::ViewProviderTile, Gui::ViewProviderDocumentObject) + +//************************************************************************** +// Construction/Destruction + +ViewProviderTile::ViewProviderTile() +{ + sPixmap = "actions/techdraw-tile"; +} + +ViewProviderTile::~ViewProviderTile() +{ +} + +void ViewProviderTile::attach(App::DocumentObject *pcFeat) +{ + // call parent attach method + ViewProviderDocumentObject::attach(pcFeat); +} + +void ViewProviderTile::setDisplayMode(const char* ModeName) +{ + ViewProviderDocumentObject::setDisplayMode(ModeName); +} + +std::vector ViewProviderTile::getDisplayModes(void) const +{ + // get the modes of the father + std::vector StrList = ViewProviderDocumentObject::getDisplayModes(); + + return StrList; +} + +void ViewProviderTile::updateData(const App::Property* prop) +{ + ViewProviderDocumentObject::updateData(prop); +} + +//TechDraw::DrawTile* ViewProviderTile::getViewObject() const +//{ +// return dynamic_cast(pcObject); +//} + +TechDraw::DrawTile* ViewProviderTile::getFeature() const +{ + return dynamic_cast(pcObject); +} diff --git a/src/Mod/TechDraw/Gui/ViewProviderTile.h b/src/Mod/TechDraw/Gui/ViewProviderTile.h new file mode 100644 index 0000000000..d791202b8f --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderTile.h @@ -0,0 +1,59 @@ +/*************************************************************************** + * Copyright (c) 2019 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef DRAWINGGUI_VIEWPROVIDERTILE_H +#define DRAWINGGUI_VIEWPROVIDERTILE_H + +#include + +#include + +namespace TechDrawGui { + + +class TechDrawGuiExport ViewProviderTile : public Gui::ViewProviderDocumentObject +{ + PROPERTY_HEADER(TechDrawGui::ViewProviderTile); + +public: + /// constructor + ViewProviderTile(); + /// destructor + virtual ~ViewProviderTile(); + + + virtual void attach(App::DocumentObject *); + virtual void setDisplayMode(const char* ModeName); + virtual bool useNewSelectionModel(void) const {return false;} + /// returns a list of all possible modes + virtual std::vector getDisplayModes(void) const; + virtual void updateData(const App::Property*); + +/* virtual TechDraw::DrawTile* getViewObject() const;*/ + virtual TechDraw::DrawTile* getFeature() const; +}; + +} // namespace TechDrawGui + + +#endif // DRAWINGGUI_VIEWPROVIDERTILE_H diff --git a/src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp b/src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp index 1c445eb6d5..347c6013f4 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include diff --git a/src/Mod/TechDraw/Gui/ViewProviderWeld.cpp b/src/Mod/TechDraw/Gui/ViewProviderWeld.cpp new file mode 100644 index 0000000000..f74656befc --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderWeld.cpp @@ -0,0 +1,110 @@ +/*************************************************************************** + * Copyright (c) 2019 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" + +#ifndef _PreComp_ +#endif + +/// Here the FreeCAD includes sorted by Base,App,Gui...... +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ViewProviderWeld.h" + +using namespace TechDrawGui; + +PROPERTY_SOURCE(TechDrawGui::ViewProviderWeld, TechDrawGui::ViewProviderDrawingView) + +//************************************************************************** +// Construction/Destruction + +ViewProviderWeld::ViewProviderWeld() +{ + sPixmap = "actions/techdraw-weldsymbol"; +} + +ViewProviderWeld::~ViewProviderWeld() +{ +} + +void ViewProviderWeld::attach(App::DocumentObject *pcFeat) +{ + // call parent attach method + ViewProviderDrawingView::attach(pcFeat); +} + +void ViewProviderWeld::setDisplayMode(const char* ModeName) +{ + ViewProviderDrawingView::setDisplayMode(ModeName); +} + +std::vector ViewProviderWeld::getDisplayModes(void) const +{ + // get the modes of the father + std::vector StrList = ViewProviderDrawingView::getDisplayModes(); + + return StrList; +} + +void ViewProviderWeld::updateData(const App::Property* prop) +{ + ViewProviderDrawingView::updateData(prop); +} + +std::vector ViewProviderWeld::claimChildren(void) const +{ + // Collect any child Document Objects and put them in the right place in the Feature tree + // valid children of a DrawWeldSymbol are: + // - DrawTiles + std::vector temp; + const std::vector &tiles = getFeature()->getInList(); + try { + for(std::vector::const_iterator it = tiles.begin(); it != tiles.end(); ++it) { + if ((*it)->getTypeId().isDerivedFrom(TechDraw::DrawTile::getClassTypeId())) { + temp.push_back((*it)); + } + } + return temp; + } catch (...) { + std::vector tmp; + return tmp; + } +} + +TechDraw::DrawWeldSymbol* ViewProviderWeld::getViewObject() const +{ + return dynamic_cast(pcObject); +} + +TechDraw::DrawWeldSymbol* ViewProviderWeld::getFeature() const +{ + return getViewObject(); +} diff --git a/src/Mod/TechDraw/Gui/ViewProviderWeld.h b/src/Mod/TechDraw/Gui/ViewProviderWeld.h new file mode 100644 index 0000000000..49adea59f7 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderWeld.h @@ -0,0 +1,63 @@ +/*************************************************************************** + * Copyright (c) 2019 Wanderer Fan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef DRAWINGGUI_VIEWPROVIDERWELD_H +#define DRAWINGGUI_VIEWPROVIDERWELD_H + +#include + +#include "ViewProviderDrawingView.h" +#include +#include +#include + + +namespace TechDrawGui { + + +class TechDrawGuiExport ViewProviderWeld : public ViewProviderDrawingView +{ + PROPERTY_HEADER(TechDrawGui::ViewProviderWeld); + +public: + /// constructor + ViewProviderWeld(); + /// destructor + virtual ~ViewProviderWeld(); + + virtual void attach(App::DocumentObject *); + virtual void setDisplayMode(const char* ModeName); + virtual bool useNewSelectionModel(void) const {return false;} + /// returns a list of all possible modes + virtual std::vector getDisplayModes(void) const; + virtual void updateData(const App::Property*); + virtual std::vector claimChildren(void) const; + + virtual TechDraw::DrawWeldSymbol* getViewObject() const; + virtual TechDraw::DrawWeldSymbol* getFeature() const; +}; + +} // namespace TechDrawGui + + +#endif // DRAWINGGUI_VIEWPROVIDERWELD_H diff --git a/src/Mod/TechDraw/Gui/Workbench.cpp b/src/Mod/TechDraw/Gui/Workbench.cpp index cd58e4d122..1ed47127a3 100644 --- a/src/Mod/TechDraw/Gui/Workbench.cpp +++ b/src/Mod/TechDraw/Gui/Workbench.cpp @@ -87,6 +87,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const *draw << "TechDraw_Image"; *draw << "TechDraw_ToggleFrame"; // *decor << "TechDraw_RedrawPage"; + *draw << "Separator"; *draw << "TechDraw_Annotation"; *draw << "TechDraw_LeaderLine"; *draw << "TechDraw_RichAnno"; @@ -99,7 +100,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const *draw << "TechDraw_CosmeticEraser"; *draw << "TechDraw_DecorateLine"; *draw << "TechDraw_ShowAll"; - + *draw << "TechDraw_WeldSymbol"; return root; } @@ -168,6 +169,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const *anno << "TechDraw_CosmeticEraser"; *anno << "TechDraw_DecorateLine"; *anno << "TechDraw_ShowAll"; + *anno << "TechDraw_WeldSymbol"; return root; } @@ -234,6 +236,7 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const *anno << "TechDraw_CosmeticEraser"; *anno << "TechDraw_DecorateLine"; *anno << "TechDraw_ShowAll"; + *anno << "TechDraw_WeldSymbol"; return root; } diff --git a/src/Mod/TechDraw/Symbols/Welding/AWS/SquareDown.svg b/src/Mod/TechDraw/Symbols/Welding/AWS/SquareDown.svg new file mode 100644 index 0000000000..29770b5e48 --- /dev/null +++ b/src/Mod/TechDraw/Symbols/Welding/AWS/SquareDown.svg @@ -0,0 +1,175 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/src/Mod/TechDraw/Symbols/Welding/AWS/SquareUp.svg b/src/Mod/TechDraw/Symbols/Welding/AWS/SquareUp.svg new file mode 100644 index 0000000000..d65822c61a --- /dev/null +++ b/src/Mod/TechDraw/Symbols/Welding/AWS/SquareUp.svg @@ -0,0 +1,171 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/src/Mod/TechDraw/Symbols/Welding/AWS/VDown.svg b/src/Mod/TechDraw/Symbols/Welding/AWS/VDown.svg new file mode 100644 index 0000000000..932dbdb008 --- /dev/null +++ b/src/Mod/TechDraw/Symbols/Welding/AWS/VDown.svg @@ -0,0 +1,166 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/src/Mod/TechDraw/Symbols/Welding/AWS/VUp.svg b/src/Mod/TechDraw/Symbols/Welding/AWS/VUp.svg new file mode 100644 index 0000000000..180cdcdb74 --- /dev/null +++ b/src/Mod/TechDraw/Symbols/Welding/AWS/VUp.svg @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/src/Mod/TechDraw/Symbols/Welding/AWS/beadDown.svg b/src/Mod/TechDraw/Symbols/Welding/AWS/beadDown.svg new file mode 100644 index 0000000000..d299798c52 --- /dev/null +++ b/src/Mod/TechDraw/Symbols/Welding/AWS/beadDown.svg @@ -0,0 +1,152 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + diff --git a/src/Mod/TechDraw/Symbols/Welding/AWS/beadUp.svg b/src/Mod/TechDraw/Symbols/Welding/AWS/beadUp.svg new file mode 100644 index 0000000000..62e7048ed3 --- /dev/null +++ b/src/Mod/TechDraw/Symbols/Welding/AWS/beadUp.svg @@ -0,0 +1,152 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + diff --git a/src/Mod/TechDraw/Symbols/Welding/AWS/filletDown.svg b/src/Mod/TechDraw/Symbols/Welding/AWS/filletDown.svg new file mode 100644 index 0000000000..2e16d297ce --- /dev/null +++ b/src/Mod/TechDraw/Symbols/Welding/AWS/filletDown.svg @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + diff --git a/src/Mod/TechDraw/Symbols/Welding/AWS/filletUp.svg b/src/Mod/TechDraw/Symbols/Welding/AWS/filletUp.svg new file mode 100644 index 0000000000..448cefc1b1 --- /dev/null +++ b/src/Mod/TechDraw/Symbols/Welding/AWS/filletUp.svg @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + diff --git a/src/Mod/TechDraw/Symbols/Welding/AWS/filletUpPlain.svg b/src/Mod/TechDraw/Symbols/Welding/AWS/filletUpPlain.svg new file mode 100644 index 0000000000..49de22b4eb --- /dev/null +++ b/src/Mod/TechDraw/Symbols/Welding/AWS/filletUpPlain.svg @@ -0,0 +1,30 @@ + + + + + + + image/svg+xml + + + + + + + diff --git a/src/Mod/TechDraw/Symbols/Welding/AWS/plug.svg b/src/Mod/TechDraw/Symbols/Welding/AWS/plug.svg new file mode 100644 index 0000000000..944ce43b0e --- /dev/null +++ b/src/Mod/TechDraw/Symbols/Welding/AWS/plug.svg @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + From 0d01744098b6350fb926a7d54eb0421fa90a8acc Mon Sep 17 00:00:00 2001 From: wandererfan Date: Thu, 1 Aug 2019 19:29:34 -0400 Subject: [PATCH 10/19] [TD]Clean up Welding Symbol creation --- src/Mod/TechDraw/Gui/QGCustomText.cpp | 2 +- src/Mod/TechDraw/Gui/QGIArrow.cpp | 12 +++- src/Mod/TechDraw/Gui/QGIFace.cpp | 50 +++++++-------- src/Mod/TechDraw/Gui/QGIFace.h | 30 ++++----- src/Mod/TechDraw/Gui/QGIPrimPath.cpp | 74 ++++++++++++++++------ src/Mod/TechDraw/Gui/QGIPrimPath.h | 19 +++++- src/Mod/TechDraw/Gui/QGIVertex.cpp | 2 + src/Mod/TechDraw/Gui/QGIViewPart.cpp | 1 + src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp | 40 ++++++++---- src/Mod/TechDraw/Gui/QGIWeldSymbol.h | 2 +- src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp | 2 +- src/Mod/TechDraw/Gui/TaskWeldingSymbol.ui | 2 +- 12 files changed, 156 insertions(+), 80 deletions(-) diff --git a/src/Mod/TechDraw/Gui/QGCustomText.cpp b/src/Mod/TechDraw/Gui/QGCustomText.cpp index d35eafb2d5..ed0a534823 100644 --- a/src/Mod/TechDraw/Gui/QGCustomText.cpp +++ b/src/Mod/TechDraw/Gui/QGCustomText.cpp @@ -152,7 +152,7 @@ void QGCustomText::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) void QGCustomText::setPrettyNormal() { m_colCurrent = m_colNormal; - setDefaultTextColor(m_colNormal); + setDefaultTextColor(m_colCurrent); update(); } diff --git a/src/Mod/TechDraw/Gui/QGIArrow.cpp b/src/Mod/TechDraw/Gui/QGIArrow.cpp index 0de92f8d27..3f8908a15b 100644 --- a/src/Mod/TechDraw/Gui/QGIArrow.cpp +++ b/src/Mod/TechDraw/Gui/QGIArrow.cpp @@ -45,20 +45,24 @@ QGIArrow::QGIArrow() : m_fill(Qt::SolidPattern), m_size(5.0), m_style(0), - m_flipped(false), m_dirMode(false), m_dir(Base::Vector3d(1.0,0.0,0.0)) { isFlipped = false; setFill(Qt::SolidPattern); m_brush.setStyle(m_fill); - + setCacheMode(QGraphicsItem::NoCache); setAcceptHoverEvents(false); setFlag(QGraphicsItem::ItemIsSelectable, false); setFlag(QGraphicsItem::ItemIsMovable, false); } + +void QGIArrow::flip(bool state) { + isFlipped = state; +} + void QGIArrow::draw() { QPainterPath path; if (m_style == 0) { @@ -69,22 +73,26 @@ void QGIArrow::draw() { path = makeFilledTriangle(m_size,m_size/6.0,isFlipped()); //"arrow l/w sb 3/1" ?? } } else if (m_style == 1) { + setFill(Qt::NoBrush); if (m_dirMode) { path = makeOpenArrow(getDirection(), m_size,m_size/3.0); //broad arrow? } else { path = makeOpenArrow(m_size,m_size/3.0,isFlipped()); } } else if (m_style == 2) { + setFill(Qt::NoBrush); if (m_dirMode) { path = makeHashMark(getDirection(), m_size/2.0,m_size/2.0); //big enough? } else { path = makeHashMark(m_size/2.0,m_size/2.0,isFlipped()); //big enough? } } else if (m_style == 3) { + setFill(Qt::SolidPattern); path = makeDot(m_size/2.0,m_size/2.0,isFlipped()); } else if (m_style == 4) { path = makeOpenDot(m_size/2.0,m_size/2.0,isFlipped()); } else if (m_style == 5) { + setFill(Qt::NoBrush); if (m_dirMode) { path = makeForkArrow(getDirection(), m_size/2.0,m_size/2.0); //big enough? } else { diff --git a/src/Mod/TechDraw/Gui/QGIFace.cpp b/src/Mod/TechDraw/Gui/QGIFace.cpp index 2dfb03bac6..42fcb63a14 100644 --- a/src/Mod/TechDraw/Gui/QGIFace.cpp +++ b/src/Mod/TechDraw/Gui/QGIFace.cpp @@ -62,16 +62,14 @@ #include "QGCustomSvg.h" #include "QGCustomRect.h" #include "QGIViewPart.h" +#include "QGIPrimPath.h" #include "QGIFace.h" using namespace TechDrawGui; using namespace TechDraw; QGIFace::QGIFace(int index) : - projIndex(index), - m_colDefFill(Qt::white), - m_styleDef(Qt::SolidPattern), - m_styleSelect(Qt::SolidPattern) + projIndex(index) { m_segCount = 0; setFillMode(NoFill); @@ -80,10 +78,6 @@ QGIFace::QGIFace(int index) : //setStyle(Qt::NoPen); //don't draw face lines, just fill for debugging setStyle(Qt::DashLine); - - m_styleNormal = m_styleDef; - m_fillStyle = m_styleDef; - m_colNormalFill = m_colDefFill; m_geomColor = QColor(Qt::black); setLineWeight(0.5); //0 = cosmetic @@ -99,6 +93,15 @@ QGIFace::QGIFace(int index) : m_fillScale = 1.0; getParameters(); + + m_styleNormal = m_styleDef; + m_fillStyle = m_styleDef; + m_fill = m_styleDef; + m_colDefFill = Qt::white; + m_colNormalFill = m_colDefFill; + m_styleDef = Qt::SolidPattern; + m_styleSelect = Qt::SolidPattern; + } QGIFace::~QGIFace() @@ -115,6 +118,7 @@ void QGIFace::draw() if (!m_lineSets.empty()) { m_brush.setTexture(QPixmap()); m_fillStyle = m_styleDef; + m_fill = m_styleDef; m_styleNormal = m_fillStyle; for (auto& ls: m_lineSets) { lineSetToFillItems(ls); @@ -130,6 +134,7 @@ void QGIFace::draw() setFillMode(SvgFill); m_brush.setTexture(QPixmap()); m_fillStyle = m_styleDef; + m_fill = m_styleDef; m_styleNormal = m_fillStyle; loadSvgHatch(m_fileSpec); buildSvgHatch(); @@ -141,6 +146,7 @@ void QGIFace::draw() setFillMode(BitmapFill); toggleSvg(false); m_fillStyle = Qt::TexturePattern; + m_fill = Qt::TexturePattern; m_texture = textureFromBitmap(m_fileSpec); m_brush.setTexture(m_texture); } @@ -154,11 +160,14 @@ void QGIFace::setPrettyNormal() { if (isHatched() && (m_mode == BitmapFill) ) { //hatch with bitmap fill m_fillStyle = Qt::TexturePattern; + m_fill = Qt::TexturePattern; m_brush.setTexture(m_texture); } else { m_fillStyle = m_styleNormal; + m_fill = m_styleNormal; m_brush.setTexture(QPixmap()); - m_brush.setStyle(m_fillStyle); +// m_brush.setStyle(m_fillStyle); + m_brush.setStyle(m_fill); //??? m_fillColor = m_colNormalFill; } QGIPrimPath::setPrettyNormal(); @@ -167,6 +176,7 @@ void QGIFace::setPrettyNormal() { void QGIFace::setPrettyPre() { m_brush.setTexture(QPixmap()); m_fillStyle = m_styleSelect; + m_fill = m_styleSelect; m_fillColor = getPreColor(); QGIPrimPath::setPrettyPre(); } @@ -174,6 +184,7 @@ void QGIFace::setPrettyPre() { void QGIFace::setPrettySel() { m_brush.setTexture(QPixmap()); m_fillStyle = m_styleSelect; + m_fill = m_styleSelect; m_fillColor = getSelectColor(); QGIPrimPath::setPrettySel(); } @@ -595,21 +606,6 @@ QPixmap QGIFace::textureFromBitmap(std::string fileSpec) return pix; } -void QGIFace::setFill(QColor c, Qt::BrushStyle s) { - m_colNormalFill = c; - m_styleNormal = s; -} - -void QGIFace::setFill(QBrush b) { - m_colNormalFill = b.color(); - m_styleNormal = b.style(); -} - -void QGIFace::resetFill() { - m_colNormalFill = m_colDefFill; - m_styleNormal = m_styleDef; -} - void QGIFace::setLineWeight(double w) { m_geomWeight = w; } @@ -642,9 +638,9 @@ void QGIFace::paint ( QPainter * painter, const QStyleOptionGraphicsItem * optio myOption.state &= ~QStyle::State_Selected; // painter->drawRect(boundingRect()); //good for debugging - m_brush.setStyle(m_fillStyle); - m_brush.setColor(m_fillColor); - setBrush(m_brush); +// m_brush.setStyle(m_fillStyle); +// m_brush.setColor(m_fillColor); +// setBrush(m_brush); QGIPrimPath::paint (painter, &myOption, widget); } diff --git a/src/Mod/TechDraw/Gui/QGIFace.h b/src/Mod/TechDraw/Gui/QGIFace.h index ad224a192b..92c13c4568 100644 --- a/src/Mod/TechDraw/Gui/QGIFace.h +++ b/src/Mod/TechDraw/Gui/QGIFace.h @@ -74,9 +74,9 @@ public: int getProjIndex() const { return projIndex; } void draw(); - void setPrettyNormal(); - void setPrettyPre(); - void setPrettySel(); + virtual void setPrettyNormal() override; + virtual void setPrettyPre() override; + void setPrettySel() override; void setDrawEdges(bool b); virtual void setOutline(const QPainterPath& path); @@ -85,10 +85,10 @@ public: bool isHatched(void) {return m_isHatched;} void setFillMode(fillMode m); - //plain color fill parms - void setFill(QColor c, Qt::BrushStyle s); - void setFill(QBrush b); - void resetFill(); +/* //plain color fill parms*/ +/* void setFill(QColor c, Qt::BrushStyle s);*/ +/* void setFill(QBrush b);*/ +/* void resetFill();*/ //general hatch parms & methods void setHatchColor(App::Color c); @@ -151,15 +151,15 @@ protected: private: - QBrush m_brush; - Qt::BrushStyle m_fillStyle; //current fill style - QColor m_fillColor; //current fill color +/* QBrush m_brush;*/ +/* Qt::BrushStyle m_fillStyle; //current fill style*/ +/* QColor m_fillColor; //current fill color*/ - QColor m_colDefFill; //"no color" default normal fill color - QColor m_colNormalFill; //current Normal fill color - Qt::BrushStyle m_styleDef; //default Normal fill style - Qt::BrushStyle m_styleNormal; //current Normal fill style - Qt::BrushStyle m_styleSelect; //Select/preSelect fill style +/* QColor m_colDefFill; //"no color" default normal fill color*/ +/* QColor m_colNormalFill; //current Normal fill color*/ +/* Qt::BrushStyle m_styleDef; //default Normal fill style*/ +/* Qt::BrushStyle m_styleNormal; //current Normal fill style*/ +/* Qt::BrushStyle m_styleSelect; //Select/preSelect fill style*/ QPixmap m_texture; // diff --git a/src/Mod/TechDraw/Gui/QGIPrimPath.cpp b/src/Mod/TechDraw/Gui/QGIPrimPath.cpp index a6a1a7d013..0fb4ab283b 100644 --- a/src/Mod/TechDraw/Gui/QGIPrimPath.cpp +++ b/src/Mod/TechDraw/Gui/QGIPrimPath.cpp @@ -55,16 +55,27 @@ QGIPrimPath::QGIPrimPath(): isHighlighted = false; - m_colNormal = Qt::white; m_colOverride = false; - m_colCurrent = getNormalColor(); + m_colNormal = getNormalColor(); + m_colCurrent = m_colNormal; m_styleCurrent = Qt::SolidLine; m_pen.setStyle(m_styleCurrent); m_capStyle = prefCapStyle(); m_pen.setCapStyle(m_capStyle); -// m_pen.setCapStyle(Qt::FlatCap); m_pen.setWidthF(m_width); + m_styleDef = Qt::NoBrush; + m_styleSelect = Qt::SolidPattern; + m_styleNormal = m_styleDef; + + m_colDefFill = Qt::white; +// m_colDefFill = Qt::transparent; + m_fillStyle = m_styleDef; + m_fill = m_styleDef; + m_colNormalFill = m_colDefFill; + m_brush.setStyle(m_styleDef); + m_brush.setColor(m_colDefFill); + setPrettyNormal(); } @@ -109,36 +120,24 @@ void QGIPrimPath::setHighlighted(bool b) } void QGIPrimPath::setPrettyNormal() { - m_colCurrent = getNormalColor(); + m_colCurrent = m_colNormal; + m_fillColor = m_colNormalFill; +// m_colCurrent = getNormalColor(); update(); } void QGIPrimPath::setPrettyPre() { m_colCurrent = getPreColor(); + m_fillColor = getPreColor(); update(); } void QGIPrimPath::setPrettySel() { m_colCurrent = getSelectColor(); + m_fillColor = getSelectColor(); update(); } -void QGIPrimPath::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { - QStyleOptionGraphicsItem myOption(*option); - myOption.state &= ~QStyle::State_Selected; - - m_pen.setWidthF(m_width); - m_pen.setColor(m_colCurrent); - m_pen.setStyle(m_styleCurrent); - setPen(m_pen); - - m_brush.setColor(m_colCurrent); - m_brush.setStyle(m_fill); - setBrush(m_brush); - - QGraphicsPathItem::paint (painter, &myOption, widget); -} - QColor QGIPrimPath::getNormalColor() { @@ -281,3 +280,38 @@ void QGIPrimPath::mousePressEvent(QGraphicsSceneMouseEvent * event) QGraphicsPathItem::mousePressEvent(event); } } + +void QGIPrimPath::setFill(QColor c, Qt::BrushStyle s) { + m_colNormalFill = c; + m_styleNormal = s; + m_fill = s; +} + +void QGIPrimPath::setFill(QBrush b) { + m_colNormalFill = b.color(); + m_styleNormal = b.style(); + m_fill = b.style(); +} + +void QGIPrimPath::resetFill() { + m_colNormalFill = m_colDefFill; + m_styleNormal = m_styleDef; + m_fill = m_styleDef; +} + +void QGIPrimPath::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { + QStyleOptionGraphicsItem myOption(*option); + myOption.state &= ~QStyle::State_Selected; + + m_pen.setWidthF(m_width); + m_pen.setColor(m_colCurrent); + m_pen.setStyle(m_styleCurrent); + setPen(m_pen); + + m_brush.setColor(m_fillColor); //pencolr + m_brush.setStyle(m_fill); + setBrush(m_brush); + + QGraphicsPathItem::paint (painter, &myOption, widget); +} + diff --git a/src/Mod/TechDraw/Gui/QGIPrimPath.h b/src/Mod/TechDraw/Gui/QGIPrimPath.h index 6e4c5be519..46bd71b0dc 100644 --- a/src/Mod/TechDraw/Gui/QGIPrimPath.h +++ b/src/Mod/TechDraw/Gui/QGIPrimPath.h @@ -59,7 +59,14 @@ public: virtual void setNormalColor(QColor c); virtual void setCapStyle(Qt::PenCapStyle c); Qt::BrushStyle getFill() { return m_fill; } + + //plain color fill parms void setFill(Qt::BrushStyle f) { m_fill = f; } + void setFill(QColor c, Qt::BrushStyle s); + void setFill(QBrush b); + void resetFill(); + void setFillColor(QColor c) { m_colNormalFill = c; + m_colDefFill = c; } protected: virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override; @@ -74,6 +81,7 @@ protected: virtual Qt::PenCapStyle prefCapStyle(void); bool isHighlighted; + QPen m_pen; QColor m_colCurrent; QColor m_colNormal; @@ -81,8 +89,17 @@ protected: Qt::PenStyle m_styleCurrent; double m_width; Qt::PenCapStyle m_capStyle; + QBrush m_brush; - Qt::BrushStyle m_fill; + Qt::BrushStyle m_fill; //current fille style + Qt::BrushStyle m_fillStyle; //current fill style*/ + QColor m_fillColor; //current fill color + + QColor m_colDefFill; //"no color" default normal fill color + QColor m_colNormalFill; //current Normal fill color + Qt::BrushStyle m_styleDef; //default Normal fill style + Qt::BrushStyle m_styleNormal; //current Normal fill style + Qt::BrushStyle m_styleSelect; //Select/preSelect fill style private: diff --git a/src/Mod/TechDraw/Gui/QGIVertex.cpp b/src/Mod/TechDraw/Gui/QGIVertex.cpp index 7f23b76bf3..a7494164a6 100644 --- a/src/Mod/TechDraw/Gui/QGIVertex.cpp +++ b/src/Mod/TechDraw/Gui/QGIVertex.cpp @@ -44,6 +44,8 @@ QGIVertex::QGIVertex(int index) : projIndex(index), m_radius(2) { + m_colDefFill = getNormalColor(); + m_colNormalFill = m_colDefFill; m_fill = Qt::SolidPattern; m_brush.setStyle(m_fill); diff --git a/src/Mod/TechDraw/Gui/QGIViewPart.cpp b/src/Mod/TechDraw/Gui/QGIViewPart.cpp index 0e826fb2b4..50ae13322a 100644 --- a/src/Mod/TechDraw/Gui/QGIViewPart.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewPart.cpp @@ -560,6 +560,7 @@ void QGIViewPart::drawViewPart() item->setRadius(cv->size); } else { item->setNormalColor(vertexColor); + item->setFillColor(vertexColor); item->setRadius(lineWidth * vertexScaleFactor); } addToGroup(item); diff --git a/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp b/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp index f7b3e9cf6c..eac2392006 100644 --- a/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp +++ b/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp @@ -80,8 +80,12 @@ QGIWeldSymbol::QGIWeldSymbol(QGILeaderLine* myParent, m_qgLead(myParent), m_blockDraw(false) { -// setHandlesChildEvents(true); //qt4 deprecated in qt5 + +#if PY_MAJOR_VERSION < 3 + setHandlesChildEvents(true); //qt4 deprecated in qt5 +#else setFiltersChildEvents(true); //qt5 +#endif setFlag(QGraphicsItem::ItemIsMovable, false); setCacheMode(QGraphicsItem::NoCache); @@ -106,7 +110,6 @@ QVariant QGIWeldSymbol::itemChange(GraphicsItemChange change, const QVariant &va } else { setPrettyNormal(); } - draw(); } else if(change == ItemSceneChange && scene()) { // nothing special! } @@ -152,7 +155,7 @@ void QGIWeldSymbol::draw() } if (strlen(m_weldFeat->TailText.getValue()) != 0) { - drawProcessText(); + drawTailText(); } } @@ -186,9 +189,12 @@ void QGIWeldSymbol::drawAllAround(void) m_allAround = new QGIVertex(-1); m_allAround->setParentItem(this); + m_allAround->setAcceptHoverEvents(false); m_allAround->setFlag(QGraphicsItem::ItemIsSelectable, false); m_allAround->setFlag(QGraphicsItem::ItemIsMovable, false); - m_allAround->setAcceptHoverEvents(false); + m_allAround->setFlag(QGraphicsItem::ItemSendsScenePositionChanges, false); + m_allAround->setFlag(QGraphicsItem::ItemSendsGeometryChanges,true); + m_allAround->setFlag(QGraphicsItem::ItemStacksBehindParent, true); m_allAround->setNormalColor(getCurrentColor()); @@ -202,9 +208,9 @@ void QGIWeldSymbol::drawAllAround(void) m_allAround->setPos(allAroundPos); } -void QGIWeldSymbol::drawProcessText(void) +void QGIWeldSymbol::drawTailText(void) { -// Base::Console().Message("QGIWS::drawProcessText()\n"); +// Base::Console().Message("QGIWS::drawTailText()\n"); m_tailText = new QGCustomText(); m_tailText->setParentItem(this); @@ -251,17 +257,24 @@ void QGIWeldSymbol::drawFieldFlag() m_fieldFlag = new QGIPrimPath(); m_fieldFlag->setParentItem(this); + m_fieldFlag->setAcceptHoverEvents(false); m_fieldFlag->setFlag(QGraphicsItem::ItemIsSelectable, false); m_fieldFlag->setFlag(QGraphicsItem::ItemIsMovable, false); - m_fieldFlag->setAcceptHoverEvents(false); - m_fieldFlag->setPath(path); + m_fieldFlag->setFlag(QGraphicsItem::ItemSendsScenePositionChanges, false); + m_fieldFlag->setFlag(QGraphicsItem::ItemSendsGeometryChanges,true); + m_fieldFlag->setFlag(QGraphicsItem::ItemStacksBehindParent, true); - m_fieldFlag->setNormalColor(getCurrentColor()); - m_fieldFlag->setFill(Qt::SolidPattern); + m_fieldFlag->setNormalColor(getCurrentColor()); //penColor double width = m_qgLead->getLineWidth(); + + m_fieldFlag->setFillColor(getCurrentColor()); + m_fieldFlag->setFill(Qt::SolidPattern); + m_fieldFlag->setWidth(width); m_fieldFlag->setZValue(ZVALUE::DIMENSION); + m_fieldFlag->setPath(path); + QPointF fieldFlagPos = getKinkPoint(); m_fieldFlag->setPos(fieldFlagPos); } @@ -296,8 +309,8 @@ void QGIWeldSymbol::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); if (isSelected()) { - setPrettySel(); m_colCurrent = getSelectColor(); + setPrettySel(); } else { m_colCurrent = getPreColor(); setPrettyPre(); @@ -330,8 +343,13 @@ void QGIWeldSymbol::setPrettyNormal() t->setColor(m_colNormal); t->draw(); } + m_colCurrent = m_colNormal; + m_fieldFlag->setNormalColor(m_colCurrent); + m_fieldFlag->setFillColor(m_colCurrent); m_fieldFlag->setPrettyNormal(); + m_allAround->setNormalColor(m_colCurrent); m_allAround->setPrettyNormal(); + m_tailText->setColor(m_colCurrent); m_tailText->setPrettyNormal(); } diff --git a/src/Mod/TechDraw/Gui/QGIWeldSymbol.h b/src/Mod/TechDraw/Gui/QGIWeldSymbol.h index 8fd9c80b6f..cea74598d6 100644 --- a/src/Mod/TechDraw/Gui/QGIWeldSymbol.h +++ b/src/Mod/TechDraw/Gui/QGIWeldSymbol.h @@ -93,7 +93,7 @@ protected: void drawTile(TechDraw::DrawTileWeld* dtw, QGITile* tile); void drawAllAround(void); - void drawProcessText(void); + void drawTailText(void); void drawFieldFlag(); void removeDecorations(); diff --git a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp index 917f2d9478..c5318dff29 100644 --- a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp +++ b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp @@ -371,7 +371,7 @@ App::DocumentObject* TaskWeldingSymbol::createWeldingSymbol(void) Command::doCommand(Command::Doc,"App.activeDocument().%s.FieldWeld = %s", symbolName.c_str(), fieldWeldText.c_str()); - std::string tailText = Base::Tools::toStdString(ui->leProcessText->text()); + std::string tailText = Base::Tools::toStdString(ui->leTailText->text()); Command::doCommand(Command::Doc,"App.activeDocument().%s.TailText = '%s'", symbolName.c_str(), tailText.c_str()); diff --git a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.ui b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.ui index 711dd4c0e2..a72b219b08 100644 --- a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.ui +++ b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.ui @@ -345,7 +345,7 @@ - + Text at end of symbol From f0155052f3c23de76963ede90487721770c6f18e Mon Sep 17 00:00:00 2001 From: wandererfan Date: Sat, 3 Aug 2019 22:39:37 -0400 Subject: [PATCH 11/19] [TD]Welding Symbol Editor alpha release --- CMakeLists.txt.user | 827 +++++++++++++++++++++ src/Mod/TechDraw/App/DrawTile.cpp | 6 +- src/Mod/TechDraw/App/DrawTile.h | 2 +- src/Mod/TechDraw/App/DrawTileWeld.cpp | 2 +- src/Mod/TechDraw/App/DrawWeldSymbol.cpp | 20 +- src/Mod/TechDraw/App/DrawWeldSymbol.h | 4 +- src/Mod/TechDraw/Gui/CMakeLists.txt | 6 + src/Mod/TechDraw/Gui/CommandAnnotate.cpp | 20 +- src/Mod/TechDraw/Gui/QGIArrow.cpp | 13 +- src/Mod/TechDraw/Gui/QGITile.cpp | 153 ++-- src/Mod/TechDraw/Gui/QGITile.h | 14 +- src/Mod/TechDraw/Gui/QGIView.cpp | 6 + src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp | 162 ++-- src/Mod/TechDraw/Gui/QGIWeldSymbol.h | 4 +- src/Mod/TechDraw/Gui/SymbolChooser.cpp | 156 ++++ src/Mod/TechDraw/Gui/SymbolChooser.h | 65 ++ src/Mod/TechDraw/Gui/SymbolChooser.ui | 124 +++ src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp | 669 +++++++++++------ src/Mod/TechDraw/Gui/TaskWeldingSymbol.h | 80 +- src/Mod/TechDraw/Gui/TaskWeldingSymbol.ui | 455 +++++------- src/Mod/TechDraw/Gui/ViewProviderWeld.cpp | 46 +- src/Mod/TechDraw/Gui/ViewProviderWeld.h | 3 + 22 files changed, 2197 insertions(+), 640 deletions(-) create mode 100644 CMakeLists.txt.user create mode 100644 src/Mod/TechDraw/Gui/SymbolChooser.cpp create mode 100644 src/Mod/TechDraw/Gui/SymbolChooser.h create mode 100644 src/Mod/TechDraw/Gui/SymbolChooser.ui diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user new file mode 100644 index 0000000000..6df35fe60d --- /dev/null +++ b/CMakeLists.txt.user @@ -0,0 +1,827 @@ + + + + + + EnvironmentId + {2bb8d980-59c2-4103-9ad9-f84df3b67da6} + + + ProjectExplorer.Project.ActiveTarget + 1 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop + {6576b0bd-ff13-47bd-97c2-c8159848c669} + 0 + 0 + 0 + + + /home/huxster/Target/freecad-qtcdb-build + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Default + Default + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=Debug + + /home/huxster/Source/build-FreeCAD-src-Desktop-Debug + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Debug + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=Release + + /home/huxster/Source/build-FreeCAD-src-Desktop-Release + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Release + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=RelWithDebInfo + + /home/huxster/Source/build-FreeCAD-src-Desktop-Release with Debug Information + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release with Debug Information + Release with Debug Information + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=MinSizeRel + + /home/huxster/Source/build-FreeCAD-src-Desktop-Minimum Size Release + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Minimum Size Release + Minimum Size Release + CMakeProjectManager.CMakeBuildConfiguration + + 5 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + FreeCADMainCmd + + + /home/huxster/Target/freecad-qtcdb-build/bin + 2 + + FreeCADMainCmd + + CMakeProjectManager.CMakeRunConfiguration.FreeCADMainCmd + 3768 + false + true + false + false + true + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + FreeCADMain + + + /home/huxster/Target/freecad-qtcdb-build/bin + -1 + + FreeCADMain + + CMakeProjectManager.CMakeRunConfiguration.FreeCADMain + 3768 + false + true + false + false + true + + 2 + + + + ProjectExplorer.Project.Target.1 + + FCPy3 + FCPy3 + {e6789b53-bada-4b34-95c2-99709681bbbb} + 1 + 0 + 1 + + + /home/huxster/Target/freecad-qtc-build + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Default + Default + CMakeProjectManager.CMakeBuildConfiguration + + + + BUILD_ADDONMGR:INTERNAL=ON + BUILD_ARCH:INTERNAL=ON + BUILD_ASSEMBLY:INTERNAL=OFF + BUILD_COMPLETE:INTERNAL=OFF + BUILD_DRAFT:INTERNAL=ON + BUILD_DRAWING:INTERNAL=ON + BUILD_FEM:INTERNAL=OFF + BUILD_FLAT_MESH:INTERNAL=OFF + BUILD_IDF:INTERNAL=OFF + BUILD_IMAGE:INTERNAL=OFF + BUILD_IMPORT:INTERNAL=ON + BUILD_INSPECTION:INTERNAL=OFF + BUILD_JTREADER:INTERNAL=OFF + BUILD_MATERIAL:INTERNAL=ON + BUILD_MESH:INTERNAL=ON + BUILD_MESH_PART:INTERNAL=ON + BUILD_OPENSCAD:INTERNAL=OFF + BUILD_PART:INTERNAL=ON + BUILD_PART_DESIGN:INTERNAL=ON + BUILD_PATH:INTERNAL=OFF + BUILD_PLOT:INTERNAL=OFF + BUILD_POINTS:INTERNAL=OFF + BUILD_QT5:INTERNAL=ON + BUILD_RAYTRACING:INTERNAL=OFF + BUILD_REVERSEENGINEERING:INTERNAL=OFF + BUILD_ROBOT:INTERNAL=OFF + BUILD_SANDBOX:INTERNAL=OFF + BUILD_SHIP:INTERNAL=OFF + BUILD_SHOW:INTERNAL=ON + BUILD_SKETCHER:INTERNAL=ON + BUILD_SPREADSHEET:INTERNAL=ON + BUILD_START:INTERNAL=OFF + BUILD_SURFACE:INTERNAL=OFF + BUILD_TECHDRAW:INTERNAL=ON + BUILD_TEMPLATE:INTERNAL=OFF + BUILD_TEST:INTERNAL=ON + BUILD_TUX:INTERNAL=ON + BUILD_VR:INTERNAL=OFF + BUILD_WEB:INTERNAL=OFF + CMAKE_BUILD_TYPE:STRING=Debug + FREECAD_USE_OCC_VARIANT:INTERNAL="Official Version" + OpenCASCADE_DIR:PATH=/usr/local/lib/cmake/opencascade72obs + PYTHON_EXECUTABLE:INTERNAL=/usr/bin/python3 + + /home/huxster/Target/freecad-qtcdb-build + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Debug + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=Release + + /home/huxster/Source/build-FreeCAD-src-FCPy3-Release + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Release + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=RelWithDebInfo + + /home/huxster/Source/build-FreeCAD-src-FCPy3-Release with Debug Information + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release with Debug Information + Release with Debug Information + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=MinSizeRel + + /home/huxster/Source/build-FreeCAD-src-FCPy3-Minimum Size Release + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Minimum Size Release + Minimum Size Release + CMakeProjectManager.CMakeBuildConfiguration + + 5 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + FreeCADMainCmd + + + /home/huxster/Target/freecad-qtcdb-build/bin + 2 + + FreeCADMainCmd + + CMakeProjectManager.CMakeRunConfiguration.FreeCADMainCmd + 3768 + false + true + false + false + true + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + FreeCADMain + -l + + /home/huxster/Target/freecad-qtcdb-build/bin + 2 + + FreeCADMain + + CMakeProjectManager.CMakeRunConfiguration.FreeCADMain + 3768 + false + true + false + false + true + + 2 + + + + ProjectExplorer.Project.TargetCount + 2 + + + ProjectExplorer.Project.Updater.FileVersion + 18 + + + Version + 18 + + diff --git a/src/Mod/TechDraw/App/DrawTile.cpp b/src/Mod/TechDraw/App/DrawTile.cpp index 65bb6e45b8..9965b97f7f 100644 --- a/src/Mod/TechDraw/App/DrawTile.cpp +++ b/src/Mod/TechDraw/App/DrawTile.cpp @@ -47,12 +47,12 @@ DrawTile::DrawTile(void) { static const char *group = "Tile"; - Base::Vector3d defOrg(0.0, 0.0, 0.0); +// Base::Vector3d defOrg(0.0, 0.0, 0.0); ADD_PROPERTY_TYPE(TileParent,(0),group,(App::PropertyType)(App::Prop_None), "Object to which this tile is attached"); ADD_PROPERTY_TYPE(TileRow, (0), group, App::Prop_None, "Row in parent"); ADD_PROPERTY_TYPE(TileColumn, (0), group, App::Prop_None, "Column in parent"); - ADD_PROPERTY_TYPE(TileOrigin, (defOrg), group, App::Prop_None, "Width limit before auto wrap"); +// ADD_PROPERTY_TYPE(TileOrigin, (defOrg), group, App::Prop_None, "Width limit before auto wrap"); } DrawTile::~DrawTile() @@ -81,7 +81,7 @@ App::DocumentObjectExecReturn *DrawTile::execute(void) DrawView* DrawTile::getParent(void) const { - Base::Console().Message("DT::getParent() - %s\n", getNameInDocument()); +// Base::Console().Message("DT::getParent() - %s\n", getNameInDocument()); DrawView* result = nullptr; App::DocumentObject* baseObj = TileParent.getValue(); if (baseObj != nullptr) { diff --git a/src/Mod/TechDraw/App/DrawTile.h b/src/Mod/TechDraw/App/DrawTile.h index 6b80bd6e75..1f3de65d43 100644 --- a/src/Mod/TechDraw/App/DrawTile.h +++ b/src/Mod/TechDraw/App/DrawTile.h @@ -42,7 +42,7 @@ public: App::PropertyLink TileParent; //eg DrawWeldSymbol App::PropertyInteger TileRow; App::PropertyInteger TileColumn; - App::PropertyVector TileOrigin; //sb call to TileParent - WeldingSymbol +/* App::PropertyVector TileOrigin; //sb call to TileParent - WeldingSymbol*/ virtual short mustExecute() const; virtual App::DocumentObjectExecReturn *execute(void); diff --git a/src/Mod/TechDraw/App/DrawTileWeld.cpp b/src/Mod/TechDraw/App/DrawTileWeld.cpp index 851d356743..0664e1ace7 100644 --- a/src/Mod/TechDraw/App/DrawTileWeld.cpp +++ b/src/Mod/TechDraw/App/DrawTileWeld.cpp @@ -74,7 +74,7 @@ short DrawTileWeld::mustExecute() const App::DocumentObjectExecReturn *DrawTileWeld::execute(void) { -// Base::Console().Message("DT::execute()\n"); +// Base::Console().Message("DTW::execute()\n"); return DrawTile::execute(); } diff --git a/src/Mod/TechDraw/App/DrawWeldSymbol.cpp b/src/Mod/TechDraw/App/DrawWeldSymbol.cpp index 7dd0fbfaa8..c3ecb1e29b 100644 --- a/src/Mod/TechDraw/App/DrawWeldSymbol.cpp +++ b/src/Mod/TechDraw/App/DrawWeldSymbol.cpp @@ -36,6 +36,7 @@ #include // generated from DrawWeldSymbolPy.xml +#include "DrawLeaderLine.h" #include "DrawTile.h" #include "DrawTileWeld.h" #include "DrawWeldSymbol.h" @@ -55,6 +56,7 @@ DrawWeldSymbol::DrawWeldSymbol(void) ADD_PROPERTY_TYPE(Leader,(0),group,(App::PropertyType)(App::Prop_None), "Parent Leader"); ADD_PROPERTY_TYPE(AllAround, (false), group, App::Prop_None, "All Around Symbol on/off"); ADD_PROPERTY_TYPE(FieldWeld, (false), group, App::Prop_None, "Field Weld Symbol on/off"); + ADD_PROPERTY_TYPE(AlternatingWeld, (false), group, App::Prop_None, "Alternating Weld true/false"); ADD_PROPERTY_TYPE(TailText, (""), group, App::Prop_None, "Text at tail of symbol"); Caption.setStatus(App::Property::Hidden,true); @@ -87,7 +89,6 @@ App::DocumentObjectExecReturn *DrawWeldSymbol::execute(void) return App::DocumentObject::StdReturn; } - return DrawView::execute(); } @@ -107,10 +108,25 @@ std::vector DrawWeldSymbol::getTiles(void) const } } } -// Base::Console().Message("DWS::getTiles - returns: %d tiles\n",result.size()); return result; } +bool DrawWeldSymbol::isTailRightSide() +{ + bool result = true; + App::DocumentObject* obj = Leader.getValue(); + TechDraw::DrawLeaderLine* realLeader = dynamic_cast(obj); + if (realLeader != nullptr) { + Base::Vector3d tail = realLeader->getTailPoint(); + Base::Vector3d kink = realLeader->getKinkPoint(); + if (tail.x < kink.x) { //tail is to left + result = false; + } + } + return result; +} + + PyObject *DrawWeldSymbol::getPyObject(void) { if (PythonObject.is(Py::_None())) { diff --git a/src/Mod/TechDraw/App/DrawWeldSymbol.h b/src/Mod/TechDraw/App/DrawWeldSymbol.h index 0ab74871ea..59d89e7496 100644 --- a/src/Mod/TechDraw/App/DrawWeldSymbol.h +++ b/src/Mod/TechDraw/App/DrawWeldSymbol.h @@ -43,9 +43,9 @@ public: virtual ~DrawWeldSymbol(); App::PropertyLink Leader; -// App::PropertyLinkList Tiles; App::PropertyBool AllAround; App::PropertyBool FieldWeld; + App::PropertyBool AlternatingWeld; App::PropertyString TailText; virtual short mustExecute() const; @@ -57,8 +57,8 @@ public: virtual PyObject *getPyObject(void); virtual QRectF getRect() const { return QRectF(0,0,1,1);} + bool isTailRightSide(); std::vector getTiles(void) const; -// void addTile(App::DocumentObject* d); protected: virtual void onChanged(const App::Property* prop); diff --git a/src/Mod/TechDraw/Gui/CMakeLists.txt b/src/Mod/TechDraw/Gui/CMakeLists.txt index e31c45a3ec..bc6f126ef1 100644 --- a/src/Mod/TechDraw/Gui/CMakeLists.txt +++ b/src/Mod/TechDraw/Gui/CMakeLists.txt @@ -65,6 +65,7 @@ set(TechDrawGui_MOC_HDRS mtextedit.h TaskBalloon.h QGIWeldSymbol.h + SymbolChooser.h ) fc_wrap_cpp(TechDrawGui_MOC_SRCS ${TechDrawGui_MOC_HDRS}) @@ -94,6 +95,7 @@ set(TechDrawGui_UIC_SRCS TaskLineDecor.ui TaskRestoreLines.ui TaskWeldingSymbol.ui + SymbolChooser.ui ) if(BUILD_QT5) @@ -178,6 +180,9 @@ SET(TechDrawGui_SRCS DrawGuiUtil.h Rez.cpp Rez.h + SymbolChooser.ui + SymbolChooser.cpp + SymbolChooser.h ) SET(TechDrawGuiView_SRCS @@ -338,6 +343,7 @@ SET(TechDrawGuiTaskDlgs_SRCS TaskRestoreLines.ui TaskCL2Lines.ui TaskWeldingSymbol.ui + SymbolChooser.ui ) SOURCE_GROUP("TaskDialogs" FILES ${TechDrawGuiTaskDlgs_SRCS}) diff --git a/src/Mod/TechDraw/Gui/CommandAnnotate.cpp b/src/Mod/TechDraw/Gui/CommandAnnotate.cpp index f6c4d09909..cc13ebdd9b 100644 --- a/src/Mod/TechDraw/Gui/CommandAnnotate.cpp +++ b/src/Mod/TechDraw/Gui/CommandAnnotate.cpp @@ -1318,15 +1318,23 @@ void CmdTechDrawWeldSymbol::activated(int iMsg) std::vector leaders = getSelection(). getObjectsOfType(TechDraw::DrawLeaderLine::getClassTypeId()); - if (leaders.size() != 1) { + std::vector welds = getSelection(). + getObjectsOfType(TechDraw::DrawWeldSymbol::getClassTypeId()); + TechDraw::DrawLeaderLine* leadFeat = nullptr; + TechDraw::DrawWeldSymbol* weldFeat = nullptr; + if ( (leaders.size() != 1) && + (welds.size() != 1) ) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), - QObject::tr("Select exactly one Leader line.")); + QObject::tr("Select exactly one Leader line or one Weld symbol.")); return; } - TechDraw::DrawLeaderLine* baseFeat = nullptr; - baseFeat = static_cast (leaders.front()); - - Gui::Control().showDialog(new TaskDlgWeldingSymbol(baseFeat)); + if (!leaders.empty()) { + leadFeat = static_cast (leaders.front()); + Gui::Control().showDialog(new TaskDlgWeldingSymbol(leadFeat)); + } else if (!welds.empty()) { + weldFeat = static_cast (welds.front()); + Gui::Control().showDialog(new TaskDlgWeldingSymbol(weldFeat)); + } } bool CmdTechDrawWeldSymbol::isActive(void) diff --git a/src/Mod/TechDraw/Gui/QGIArrow.cpp b/src/Mod/TechDraw/Gui/QGIArrow.cpp index 3f8908a15b..fa0e4bcbc9 100644 --- a/src/Mod/TechDraw/Gui/QGIArrow.cpp +++ b/src/Mod/TechDraw/Gui/QGIArrow.cpp @@ -48,9 +48,11 @@ QGIArrow::QGIArrow() : m_dirMode(false), m_dir(Base::Vector3d(1.0,0.0,0.0)) { - isFlipped = false; + setFlipped(false); setFill(Qt::SolidPattern); m_brush.setStyle(m_fill); + m_colDefFill = getNormalColor(); + m_colNormalFill = m_colDefFill; setCacheMode(QGraphicsItem::NoCache); setAcceptHoverEvents(false); @@ -58,11 +60,6 @@ QGIArrow::QGIArrow() : setFlag(QGraphicsItem::ItemIsMovable, false); } - -void QGIArrow::flip(bool state) { - isFlipped = state; -} - void QGIArrow::draw() { QPainterPath path; if (m_style == 0) { @@ -122,7 +119,7 @@ QPainterPath QGIArrow::makeFilledTriangle(double length, double width, bool flip path.lineTo(QPointF(Rez::guiX(length),Rez::guiX(-width))); path.lineTo(QPointF(Rez::guiX(length),Rez::guiX(width))); path.closeSubpath(); - m_fill = Qt::SolidPattern; + setFill(Qt::SolidPattern); return path; } @@ -141,7 +138,7 @@ QPainterPath QGIArrow::makeFilledTriangle(Base::Vector3d dir, double length, dou path.lineTo(QPointF(Rez::guiX(barb1.x),Rez::guiX(barb1.y))); path.lineTo(QPointF(Rez::guiX(barb2.x),Rez::guiX(barb2.y))); path.closeSubpath(); - m_fill = Qt::SolidPattern; + setFill(Qt::SolidPattern); return path; } diff --git a/src/Mod/TechDraw/Gui/QGITile.cpp b/src/Mod/TechDraw/Gui/QGITile.cpp index 629f8dcdd6..0e00d33729 100644 --- a/src/Mod/TechDraw/Gui/QGITile.cpp +++ b/src/Mod/TechDraw/Gui/QGITile.cpp @@ -23,9 +23,9 @@ #include "PreCompiled.h" #ifndef _PreComp_ #include -#include #include #include +#include #endif #include @@ -36,6 +36,7 @@ #include #include #include +#include #include #include "Rez.h" @@ -45,14 +46,11 @@ using namespace TechDrawGui; -QGITile::QGITile(TechDraw::DrawTile* feat) : +QGITile::QGITile(TechDraw::DrawTileWeld* feat) : m_tileFeat(feat), m_textL(QString()), m_textR(QString()), m_textC(QString()), - m_textSize(0.0), - m_row(0), - m_col(0), m_scale(1.0) { m_qgSvg = new QGCustomSvg(); @@ -67,15 +65,17 @@ QGITile::QGITile(TechDraw::DrawTile* feat) : m_wide = getSymbolWidth(); m_high = getFontSize(); - m_textSize = getFontSize(); m_textL = QString(); m_textR = QString(); m_textC = QString(); m_fontName = getTextFont(); m_font = QFont(m_fontName); -// setHandlesChildEvents(true); //qt4 +#if PY_MAJOR_VERSION < 3 + setHandlesChildEvents(true); //qt4 deprecated in qt5 +#else setFiltersChildEvents(true); //qt5 +#endif setAcceptHoverEvents(true); setFlag(QGraphicsItem::ItemIsSelectable, false); setFlag(QGraphicsItem::ItemIsMovable, false); @@ -106,31 +106,67 @@ void QGITile::draw(void) double textWidthL = m_qgTextL->boundingRect().width(); double textWidthR = m_qgTextR->boundingRect().width(); double totalWidth = m_wide + textWidthL + textWidthR; - - double x = m_origin.x() + m_col * totalWidth; //bit of a hack. sb 0.5 of prev tile + 0.5 of this tile - double y = m_origin.y() - (m_row * m_high) - (m_high * 0.5); //inverted y!! - setPos(x,y); + int row = m_tileFeat->TileRow.getValue(); + int col = m_tileFeat->TileColumn.getValue(); + if (row == 0) { //arrowSide + double x = m_origin.x(); + double y = m_origin.y() - (m_high * 0.5); //inverted y!! + setPos(x,y); + } else if (row == -1) { //otherSide + if (getAltWeld()) { + if (isTailRight()) { + double x = m_origin.x() + (0.5 * totalWidth); //move to right 1/2 tile width + double y = m_origin.y() + (m_high * 0.5); //inverted y!! + setPos(x,y); + } else { + double x = m_origin.x() - (0.5 * totalWidth); //move to left 1/2 tile width + double y = m_origin.y() + (m_high * 0.5); //inverted y!! + setPos(x,y); + } + } else { + double x = m_origin.x(); + double y = m_origin.y() + (m_high * 0.5); //inverted y!! + setPos(x,y); + } + } else { + double x = m_origin.x() + col * totalWidth; + double y = m_origin.y() - (row * m_high) - (m_high * 0.5); //inverted y!! + setPos(x,y); + } } void QGITile::makeSymbol(void) { // Base::Console().Message("QGIT::makeSymbol()\n"); m_effect->setColor(m_colCurrent); - + + if (m_svgPath.isEmpty()) { + Base::Console().Warning("QGIT::makeSymbol - no symbol file set\n"); + return; + } + m_qgSvg->setGraphicsEffect(m_effect); - QFile svgFile(m_svgPath); - if(svgFile.open(QIODevice::ReadOnly)) { - QByteArray qba = svgFile.readAll(); - if (!m_qgSvg->load(&qba)) { - Base::Console().Error("Error - Could not load SVG renderer with %s\n", qPrintable(m_svgPath)); - } - svgFile.close(); - } else { - Base::Console().Error("Error - Could not open file %s\n", qPrintable(m_svgPath)); - } - m_qgSvg->setScale(scaleToFont()); - m_qgSvg->centerAt(0.0, 0.0); //(0,0) is based on symbol size + QFileInfo fi(m_svgPath); + if (fi.isReadable()) { + QFile svgFile(m_svgPath); + if(svgFile.open(QIODevice::ReadOnly)) { + QByteArray qba = svgFile.readAll(); + if (!m_qgSvg->load(&qba)) { + Base::Console().Error("Error - Could not load SVG renderer with **%s**\n", qPrintable(m_svgPath)); + return; + } + svgFile.close(); + m_qgSvg->setScale(scaleToFont()); + m_qgSvg->centerAt(0.0, 0.0); //(0,0) is based on symbol size + } else { + Base::Console().Error("Error - Could not open file **%s**\n", qPrintable(m_svgPath)); + } + } else { + Base::Console().Error("QGIT::makeSymbol - file: **%s** is not readable\n",qPrintable(m_svgPath)); + return; + } + } void QGITile::makeText(void) @@ -138,8 +174,11 @@ void QGITile::makeText(void) // Base::Console().Message("QGIT::makeText()\n"); prepareGeometryChange(); m_font.setPixelSize(getFontSize()); - double verticalFudge = 0.10; //% of textHeight + double verticalFudge = 0.10; + int row = m_tileFeat->TileRow.getValue(); + + //(0, 0) is 1/2 up (above line symbol)! m_qgTextL->setFont(m_font); m_qgTextL->setPlainText(m_textL); m_qgTextL->setColor(m_colCurrent); @@ -148,52 +187,45 @@ void QGITile::makeText(void) double hMargin = (m_wide / 2.0) + (charWidth / 2.0); double textHeightL = m_qgTextL->boundingRect().height(); - double offsetAdjustL = 0.0; - if (m_row < 0) { - offsetAdjustL = -textHeightL * verticalFudge; + double vOffset = 0.0; + if (row < 0) { // below line + vOffset = textHeightL * verticalFudge; } else { - offsetAdjustL = textHeightL * verticalFudge; + vOffset = 0.0; } - double offset = (textHeightL * verticalFudge * m_row) + offsetAdjustL; - m_qgTextL->justifyRightAt(-hMargin, -offset, true); + m_qgTextL->justifyRightAt(-hMargin, vOffset, true); m_qgTextR->setFont(m_font); m_qgTextR->setPlainText(m_textR); m_qgTextR->setColor(m_colCurrent); textWidth = m_qgTextR->boundingRect().width(); charWidth = textWidth / m_textR.size(); + hMargin = (m_wide / 2.0) + (charWidth / 2.0); double textHeightR = m_qgTextR->boundingRect().height(); - double offsetAdjustR = 0.0; - if (m_row < 0) { - offsetAdjustR = -textHeightR * verticalFudge; + if (row < 0) { // below line + vOffset = textHeightR * verticalFudge; } else { - offsetAdjustR = textHeightR * verticalFudge; + vOffset = 0.0; } - offset = (textHeightR * verticalFudge * m_row) + offsetAdjustR; - m_qgTextR->justifyLeftAt(hMargin, -offset, true); + m_qgTextR->justifyLeftAt(hMargin, vOffset, true); m_qgTextC->setFont(m_font); m_qgTextC->setPlainText(m_textC); m_qgTextC->setColor(m_colCurrent); double textHeightC = m_qgTextC->boundingRect().height(); textHeightC = textHeightC; - int rowAdjustC = m_row; - if (m_row >= 0) { - rowAdjustC++; + if (row < 0) { // below line + vOffset = m_high * (1 + verticalFudge); + } else { + vOffset = -0.5 * (m_high + textHeightC); } - double offsetAdjustC = textHeightC * verticalFudge; - if (m_row < 0) { - offsetAdjustC = - offsetAdjustC; - } - offset = (textHeightC * rowAdjustC) - offsetAdjustC; - m_qgTextC->centerAt(0.0, -offset); + m_qgTextC->centerAt(0.0, vOffset); } -void QGITile::setTilePosition(QPointF org, int r, int c) +void QGITile::setTilePosition(QPointF org) + { m_origin = org; - m_row = r; - m_col = c; } void QGITile::setTileScale(double s) @@ -264,6 +296,29 @@ void QGITile::setPrettySel() { draw(); } +bool QGITile::isTailRight(void) +{ + bool right = false; + App::DocumentObject* obj = m_tileFeat->TileParent.getValue(); + TechDraw::DrawWeldSymbol* realParent = dynamic_cast(obj); + if (realParent != nullptr) { + right = realParent->isTailRightSide(); + } + return right; +} + +bool QGITile::getAltWeld(void) +{ + bool alt = false; + App::DocumentObject* obj = m_tileFeat->TileParent.getValue(); + TechDraw::DrawWeldSymbol* realParent = dynamic_cast(obj); + if (realParent != nullptr) { + alt = realParent->AlternatingWeld.getValue(); + } else { + Base::Console().Message("QGIT::getAltWeld - real parent not found!\n"); + } + return alt; +} //TODO: this is Pen, not Brush. sb Brush to colour background QColor QGITile::getTileColor(void) const diff --git a/src/Mod/TechDraw/Gui/QGITile.h b/src/Mod/TechDraw/Gui/QGITile.h index b04d859d31..0a67d9247c 100644 --- a/src/Mod/TechDraw/Gui/QGITile.h +++ b/src/Mod/TechDraw/Gui/QGITile.h @@ -51,7 +51,7 @@ namespace TechDrawGui class TechDrawGuiExport QGITile : public QGIDecoration { public: - explicit QGITile(TechDraw::DrawTile* tileFeat); + explicit QGITile(TechDraw::DrawTileWeld* tileFeat); ~QGITile(void) {} enum {Type = QGraphicsItem::UserType + 325}; @@ -65,10 +65,11 @@ public: void setTileTextCenter(std::string s); void setFont(QFont f, double fsize); void setSymbolFile(std::string s); - void setTilePosition(QPointF org, int row, int col); + void setTilePosition(QPointF org); void setTileScale(double s); -// double getSymbolScale(void) const; virtual void draw(void); + bool isTailRight(void); + protected: virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); @@ -87,8 +88,10 @@ protected: void makeSymbol(void); void makeText(void); + bool getAltWeld(void); + private: - TechDraw::DrawTile* m_tileFeat; + TechDraw::DrawTileWeld* m_tileFeat; QGCustomText* m_qgTextL; QGCustomText* m_qgTextR; QGCustomText* m_qgTextC; @@ -100,9 +103,6 @@ private: QString m_textC; QString m_fontName; QFont m_font; - double m_textSize; - int m_row; - int m_col; QPointF m_origin; double m_wide; double m_high; diff --git a/src/Mod/TechDraw/Gui/QGIView.cpp b/src/Mod/TechDraw/Gui/QGIView.cpp index 415b291155..57b87887df 100644 --- a/src/Mod/TechDraw/Gui/QGIView.cpp +++ b/src/Mod/TechDraw/Gui/QGIView.cpp @@ -525,6 +525,7 @@ void QGIView::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q QStyleOptionGraphicsItem myOption(*option); myOption.state &= ~QStyle::State_Selected; +// painter->setPen(Qt::red); // painter->drawRect(boundingRect()); //good for debugging QGraphicsItemGroup::paint(painter, &myOption, widget); @@ -541,8 +542,12 @@ QRectF QGIView::customChildrenBoundingRect() const int textLeaderItemType = QGraphicsItem::UserType + 233; // TODO: Magic number warning int editablePathItemType = QGraphicsItem::UserType + 301; // TODO: Magic number warning int movableTextItemType = QGraphicsItem::UserType + 300; + int weldingSymbolItemType = QGraphicsItem::UserType + 340; QRectF result; for (QList::iterator it = children.begin(); it != children.end(); ++it) { + if (!(*it)->isVisible()) { + continue; + } if ( ((*it)->type() != dimItemType) && ((*it)->type() != leaderItemType) && ((*it)->type() != textLeaderItemType) && @@ -550,6 +555,7 @@ QRectF QGIView::customChildrenBoundingRect() const ((*it)->type() != movableTextItemType) && ((*it)->type() != borderItemType) && ((*it)->type() != labelItemType) && + ((*it)->type() != weldingSymbolItemType) && ((*it)->type() != captionItemType) ) { QRectF childRect = mapFromItem(*it,(*it)->boundingRect()).boundingRect(); result = result.united(childRect); diff --git a/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp b/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp index eac2392006..ea436f3151 100644 --- a/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp +++ b/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp @@ -97,6 +97,14 @@ QGIWeldSymbol::QGIWeldSymbol(QGILeaderLine* myParent, m_tailText = new QGCustomText(); addToGroup(m_tailText); + m_tailText->hide(); + m_tailText->setPos(0.0, 0.0); //avoid bRect issues + + m_allAround = new QGIVertex(-1); + m_allAround->setParentItem(this); + m_fieldFlag = new QGIPrimPath(); + m_fieldFlag->setParentItem(this); + m_colCurrent = getNormalColor(); //preference m_colSetting = m_colCurrent; } @@ -137,15 +145,40 @@ void QGIWeldSymbol::draw() removeDecorations(); std::vector tiles = m_weldFeat->getTiles(); - for (auto& t: tiles) { - if (t != nullptr) { - QGITile* qt = new QGITile(t); - qt->setParentItem(this); - m_tiles.push_back(qt); - drawTile(t, qt); + + TechDraw::DrawTileWeld* arrowTile = nullptr; + TechDraw::DrawTileWeld* otherTile = nullptr; + if (!tiles.empty()) { + TechDraw::DrawTileWeld* tempTile = tiles.at(0); + if (tempTile->TileRow.getValue() == 0) { + arrowTile = tempTile; + } else { + otherTile = tempTile; } } - + if (tiles.size() > 1) { + TechDraw::DrawTileWeld* tempTile = tiles.at(1); + if (tempTile->TileRow.getValue() == 0) { + arrowTile = tempTile; + } else { + otherTile = tempTile; + } + } + + if (arrowTile != nullptr) { + QGITile* qt = new QGITile(arrowTile); + m_arrowTile = qt; + qt->setParentItem(this); + drawTile(arrowTile, m_arrowTile); + } + + if (otherTile != nullptr) { + QGITile* qt = new QGITile(otherTile); + m_otherTile = qt; + qt->setParentItem(this); + drawTile(otherTile, m_otherTile); + } + if (m_weldFeat->AllAround.getValue()) { drawAllAround(); } @@ -154,9 +187,7 @@ void QGIWeldSymbol::draw() drawFieldFlag(); } - if (strlen(m_weldFeat->TailText.getValue()) != 0) { - drawTailText(); - } + drawTailText(); } void QGIWeldSymbol::drawTile(TechDraw::DrawTileWeld* dtw, @@ -169,12 +200,10 @@ void QGIWeldSymbol::drawTile(TechDraw::DrawTileWeld* dtw, std::string tileTextR = dtw->RightText.getValue(); std::string tileTextC = dtw->CenterText.getValue(); tile->setSymbolFile(dtw->SymbolFile.getValue()); - int tileRow = dtw->TileRow.getValue(); - int tileCol = dtw->TileColumn.getValue(); tile->setTileScale(featScale); - + QPointF org = getTileOrigin(); - tile->setTilePosition(org, tileRow, tileCol); + tile->setTilePosition(org); tile->setColor(getCurrentColor()); tile->setTileTextLeft(tileTextL); tile->setTileTextRight(tileTextR); @@ -211,26 +240,30 @@ void QGIWeldSymbol::drawAllAround(void) void QGIWeldSymbol::drawTailText(void) { // Base::Console().Message("QGIWS::drawTailText()\n"); - m_tailText = new QGCustomText(); - m_tailText->setParentItem(this); + QPointF textPos = getTailPoint(); + m_tailText->setPos(textPos); //avoid messing up brect with empty item at 0,0 + std::string tText = m_weldFeat->TailText.getValue(); + if (tText.empty()) { + m_tailText->hide(); + return; + } else { + m_tailText->show(); + } m_font.setFamily(getPrefFont()); m_font.setPixelSize(calculateFontPixelSize(getDimFontSize())); m_tailText->setFont(m_font); - std::string tText = m_weldFeat->TailText.getValue(); m_tailText->setPlainText( QString::fromUtf8(tText.c_str())); m_tailText->setColor(getCurrentColor()); m_tailText->setZValue(ZVALUE::DIMENSION); - QPointF textPos = getTailPoint(); - double textWidth = m_tailText->boundingRect().width(); double charWidth = textWidth / tText.size(); double hMargin = charWidth + getPrefArrowSize(); - if (isTextRightSide()) { + if (getFeature()->isTailRightSide()) { m_tailText->justifyLeftAt(textPos.x() + hMargin, textPos.y(), true); } else { m_tailText->justifyRightAt(textPos.x() - hMargin, textPos.y(), true); @@ -287,22 +320,18 @@ void QGIWeldSymbol::removeDecorations() QGITile* tile = dynamic_cast(c); QGIPrimPath* prim = dynamic_cast(c); //allAround, fieldFlag if (tile) { - tile->setParentItem(nullptr); scene()->removeItem(tile); delete tile; } else if (prim) { - prim->setParentItem(nullptr); scene()->removeItem(prim); - delete prim; + delete tile; } } - if (m_tailText != nullptr) { - m_tailText->setParentItem(nullptr); - scene()->removeItem(m_tailText); - delete m_tailText; - } - std::vector noTiles; - m_tiles = noTiles; + m_arrowTile = nullptr; + m_otherTile = nullptr; + +// std::vector noTiles; +// m_tiles = noTiles; } void QGIWeldSymbol::hoverEnterEvent(QGraphicsSceneHoverEvent *event) @@ -339,10 +368,19 @@ void QGIWeldSymbol::drawBorder() void QGIWeldSymbol::setPrettyNormal() { - for (auto t: m_tiles) { - t->setColor(m_colNormal); - t->draw(); +// for (auto t: m_tiles) { +// t->setColor(m_colNormal); +// t->draw(); +// } + if (m_arrowTile != nullptr) { + m_arrowTile->setColor(m_colNormal); + m_arrowTile->draw(); } + if (m_otherTile != nullptr) { + m_otherTile->setColor(m_colNormal); + m_otherTile->draw(); + } + m_colCurrent = m_colNormal; m_fieldFlag->setNormalColor(m_colCurrent); m_fieldFlag->setFillColor(m_colCurrent); @@ -356,24 +394,50 @@ void QGIWeldSymbol::setPrettyNormal() void QGIWeldSymbol::setPrettyPre() { // Base::Console().Message("QGIWS::setPrettyPre()\n"); - for (auto t: m_tiles) { - t->setColor(getPreColor()); - t->draw(); +// for (auto t: m_tiles) { +// t->setColor(getPreColor()); +// t->draw(); +// } + if (m_arrowTile != nullptr) { + m_arrowTile->setColor(getPreColor()); + m_arrowTile->draw(); } + if (m_otherTile != nullptr) { + m_otherTile->setColor(getPreColor()); + m_otherTile->draw(); + } + m_colCurrent = getPreColor(); + m_fieldFlag->setNormalColor(getPreColor()); + m_fieldFlag->setFillColor(getPreColor()); m_fieldFlag->setPrettyPre(); + m_allAround->setNormalColor(getPreColor()); m_allAround->setPrettyPre(); + m_tailText->setColor(getPreColor()); m_tailText->setPrettyPre(); } void QGIWeldSymbol::setPrettySel() { // Base::Console().Message("QGIWS::setPrettySel()\n"); - for (auto t: m_tiles) { - t->setColor(getSelectColor()); - t->draw(); +// for (auto t: m_tiles) { +// t->setColor(getSelectColor()); +// t->draw(); +// } + if (m_arrowTile != nullptr) { + m_arrowTile->setColor(getSelectColor()); + m_arrowTile->draw(); } + if (m_otherTile != nullptr) { + m_otherTile->setColor(getSelectColor()); + m_otherTile->draw(); + } + m_colCurrent = getSelectColor(); + m_fieldFlag->setNormalColor(getSelectColor()); + m_fieldFlag->setFillColor(getSelectColor()); m_fieldFlag->setPrettySel(); + m_allAround->setNormalColor(getSelectColor()); m_allAround->setPrettySel(); + m_tailText->setColor(getSelectColor()); m_tailText->setPrettySel(); } @@ -398,16 +462,16 @@ QPointF QGIWeldSymbol::getTailPoint(void) return result; } -bool QGIWeldSymbol::isTextRightSide() -{ - bool result = true; - Base::Vector3d tail = m_leadFeat->getTailPoint(); - Base::Vector3d kink = m_leadFeat->getKinkPoint(); - if (tail.x < kink.x) { //tail is to left - result = false; - } - return result; -} +//bool QGIWeldSymbol::isTailRightSide() +//{ +// bool result = true; +// Base::Vector3d tail = m_leadFeat->getTailPoint(); +// Base::Vector3d kink = m_leadFeat->getKinkPoint(); +// if (tail.x < kink.x) { //tail is to left +// result = false; +// } +// return result; +//} TechDraw::DrawWeldSymbol* QGIWeldSymbol::getFeature(void) { diff --git a/src/Mod/TechDraw/Gui/QGIWeldSymbol.h b/src/Mod/TechDraw/Gui/QGIWeldSymbol.h index cea74598d6..7b30becd6f 100644 --- a/src/Mod/TechDraw/Gui/QGIWeldSymbol.h +++ b/src/Mod/TechDraw/Gui/QGIWeldSymbol.h @@ -77,7 +77,6 @@ public: QPointF getTileOrigin(void); QPointF getKinkPoint(void); QPointF getTailPoint(void); - bool isTextRightSide(void); virtual void setPrettyNormal(); virtual void setPrettySel(); @@ -105,7 +104,8 @@ protected: TechDraw::DrawLeaderLine* m_leadFeat; QGILeaderLine* m_qgLead; - std::vector m_tiles; + QGITile* m_arrowTile; + QGITile* m_otherTile; QGCustomText* m_tailText; QGIPrimPath* m_fieldFlag; QGIVertex* m_allAround; diff --git a/src/Mod/TechDraw/Gui/SymbolChooser.cpp b/src/Mod/TechDraw/Gui/SymbolChooser.cpp new file mode 100644 index 0000000000..3ed8a9e809 --- /dev/null +++ b/src/Mod/TechDraw/Gui/SymbolChooser.cpp @@ -0,0 +1,156 @@ +/*************************************************************************** + * Copyright (c) 2019 Wandererfan +#include + +#include "DrawGuiStd.h" +#include "Rez.h" + +#include + +#include "SymbolChooser.h" + +using namespace Gui; +using namespace TechDraw; +using namespace TechDrawGui; + + +SymbolChooser::SymbolChooser(QWidget *parent, + QString startDir, + QString source) : + QDialog(parent), + ui(new Ui_SymbolChooser), + m_symbolDir(startDir), + m_source(source) +{ + ui->setupUi(this); + connect(ui->pbOK, SIGNAL(clicked(bool)), + this, SLOT(onOKClicked(bool))); + connect(ui->pbCancel, SIGNAL(clicked(bool)), + this, SLOT(onCancelClicked(bool))); + connect(ui->fcSymbolDir, SIGNAL(fileNameSelected(const QString&)), + this, SLOT(onDirectorySelected(const QString&))); + connect(ui->lwSymbols, SIGNAL(itemClicked(QListWidgetItem*)), //double click? + this, SLOT(onItemClicked(QListWidgetItem*))); + + setUiPrimary(); +} + +void SymbolChooser::setUiPrimary() +{ +// Base::Console().Message("SC::setUiPrimary()\n"); + setWindowTitle(QObject::tr("Select a symbol")); + if (!m_symbolDir.isEmpty()) { + ui->fcSymbolDir->setFileName(m_symbolDir); + loadSymbolNames(m_symbolDir); + } else { + std::string resourceDir = App::Application::getResourceDir(); + QString defDir = QString::fromUtf8(resourceDir.c_str()); + ui->fcSymbolDir->setFileName(defDir); + loadSymbolNames(defDir); + m_symbolDir = defDir; + } + + ui->lwSymbols->setViewMode(QListView::IconMode); + ui->lwSymbols->setFlow(QListView::LeftToRight); + ui->lwSymbols->setWrapping(true); + ui->lwSymbols->setDragEnabled(true); + ui->lwSymbols->setSelectionMode(QAbstractItemView::SingleSelection); + ui->lwSymbols->setAcceptDrops(false); +} + +void SymbolChooser::onOKClicked(bool b) +{ + Q_UNUSED(b); +// Base::Console().Message("SC::OnOKClicked()\n"); + QListWidgetItem* sourceItem = ui->lwSymbols->currentItem(); + QString targetText = sourceItem->text(); + m_symbolPath = m_symbolDir + + targetText + + QString::fromUtf8(".svg"); + + Q_EMIT symbolSelected(m_symbolPath, m_source); +// Base::Console().Message("SC::onOKClicked - symbol; %s\n", qPrintable(m_symbolPath)); + accept(); +} + +void SymbolChooser::onCancelClicked(bool b) +{ + Q_UNUSED(b); +// Base::Console().Message("SC::OnCancelCicked()\n"); + reject(); +} + +void SymbolChooser::onItemClicked(QListWidgetItem* item) +{ + Q_UNUSED(item); +// Base::Console().Message("SCS::onItemClicked(%s)\n", qPrintable(item->text())); + //are item and currentItem() the same? should use item? + QListWidgetItem* sourceItem = ui->lwSymbols->currentItem(); + QString targetText = sourceItem->text(); + m_symbolPath = m_symbolDir + + targetText + + QString::fromUtf8(".svg"); + Q_EMIT symbolSelected(m_symbolPath, m_source); + +// Base::Console().Message("SC::onOKClicked - symbol: %s\n", qPrintable(m_symbolPath)); + accept(); +} + +void SymbolChooser::onDirectorySelected(const QString& newDir) +{ +// Base::Console().Message("SC::onDirectorySelected(%s)\n", qPrintable(newDir)); + m_symbolDir = newDir + QString::fromUtf8("/"); + loadSymbolNames(m_symbolDir); +} + +void SymbolChooser::loadSymbolNames(QString pathToSymbols) +{ + //fill selection list with names and icons + QDir symbolDir(pathToSymbols); + symbolDir.setFilter(QDir::Files); + QStringList fileNames = symbolDir.entryList(); + + for (auto& fn: fileNames) { + QListWidgetItem* item = new QListWidgetItem(fn, ui->lwSymbols); + QFileInfo fi(fn); + item->setText(fi.baseName()); + QIcon symbolIcon(pathToSymbols + fn); + item->setIcon(symbolIcon); + ui->lwSymbols->addItem(item); + } + ui->lwSymbols->setCurrentRow(0); + ui->lwSymbols->setAcceptDrops(false); //have to do this every time you update the items +} + +//QString SymbolChooser::getSymbolPath(void) +//{ +// Base::Console().Message("SC::getSymbolPath returns: %s\n", qPrintable(m_symbolPath)); +// return m_symbolPath; +//} + +#include diff --git a/src/Mod/TechDraw/Gui/SymbolChooser.h b/src/Mod/TechDraw/Gui/SymbolChooser.h new file mode 100644 index 0000000000..d45fc58eee --- /dev/null +++ b/src/Mod/TechDraw/Gui/SymbolChooser.h @@ -0,0 +1,65 @@ +/*************************************************************************** + * Copyright (c) 2019 Wandererfan +#include +#include + +#include + +namespace TechDrawGui { + +class TechDrawGuiExport SymbolChooser : public QDialog +{ + Q_OBJECT + +public: + SymbolChooser(QWidget *parent = 0, + QString startDir = QString(), + QString source = QString()); + +public Q_SLOTS: + void onOKClicked(bool b); + void onCancelClicked(bool b); + void onItemClicked(QListWidgetItem* item); + void onDirectorySelected(const QString& newDir); + +Q_SIGNALS: + void symbolSelected(QString symbolPath, + QString source); + +protected: + void setUiPrimary(void); + void loadSymbolNames(QString pathToSymbols); + +private: + Ui_SymbolChooser* ui; + QString m_symbolDir; + QString m_symbolPath; + QString m_source; +}; + +} +#endif // #ifndef TECHDRAWGUI_SYMBOLCHOOSER_H + diff --git a/src/Mod/TechDraw/Gui/SymbolChooser.ui b/src/Mod/TechDraw/Gui/SymbolChooser.ui new file mode 100644 index 0000000000..634b025821 --- /dev/null +++ b/src/Mod/TechDraw/Gui/SymbolChooser.ui @@ -0,0 +1,124 @@ + + + SymbolChooser + + + Qt::WindowModal + + + + 0 + 0 + 400 + 394 + + + + SymbolChooser + + + true + + + + + 19 + 19 + 361 + 341 + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + 2 + + + + + 9 + 19 + 341 + 191 + + + + + + + + + + + + 10 + 220 + 341 + 41 + + + + + + + Cancel + + + + + + + OK + + + + + + + + + 10 + 280 + 341 + 35 + + + + + + + Symbol Dir + + + + + + + Gui::FileChooser::Directory + + + + + + + + + + Gui::FileChooser + QWidget +
Gui/FileDialog.h
+
+
+ + +
diff --git a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp index c5318dff29..369098f957 100644 --- a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp +++ b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp @@ -68,6 +68,7 @@ #include "MDIViewPage.h" #include "ViewProviderPage.h" #include "ViewProviderViewPart.h" +#include "SymbolChooser.h" #include "Rez.h" #include "TaskWeldingSymbol.h" @@ -80,8 +81,12 @@ using namespace TechDrawGui; TaskWeldingSymbol::TaskWeldingSymbol(TechDraw::DrawLeaderLine* leader) : ui(new Ui_TaskWeldingSymbol), m_leadFeat(leader), - m_arrowCount(0), - m_otherCount(0) + m_weldFeat(nullptr), + m_arrowIn(nullptr), + m_otherIn(nullptr), + m_createMode(true), + m_arrowDirty(false), + m_otherDirty(false) { // Base::Console().Message("TWS::TWS() - create mode\n"); if (m_leadFeat == nullptr) { @@ -89,22 +94,94 @@ TaskWeldingSymbol::TaskWeldingSymbol(TechDraw::DrawLeaderLine* leader) : Base::Console().Error("TaskWeldingSymbol - bad parameters. Can not proceed.\n"); return; } - ui->setupUi(this); - connect(ui->pbArrow0, SIGNAL(clicked(bool)), - this, SLOT(onArrow0Clicked(bool))); - connect(ui->pbArrow1, SIGNAL(clicked(bool)), - this, SLOT(onArrow1Clicked(bool))); - connect(ui->pbOther0, SIGNAL(clicked(bool)), - this, SLOT(onOther0Clicked(bool))); - connect(ui->pbOther1, SIGNAL(clicked(bool)), - this, SLOT(onOther1Clicked(bool))); + + connect(ui->pbArrowSymbol, SIGNAL(clicked(bool)), + this, SLOT(onArrowSymbolClicked(bool))); + connect(ui->pbOtherSymbol, SIGNAL(clicked(bool)), + this, SLOT(onOtherSymbolClicked(bool))); + connect(ui->pbOtherErase, SIGNAL(clicked(bool)), + this, SLOT(onOtherEraseClicked(bool))); + connect(ui->fcSymbolDir, SIGNAL(fileNameSelected(const QString&)), this, SLOT(onDirectorySelected(const QString&))); + connect(ui->leArrowTextL, SIGNAL(textEdited(const QString&)), + this, SLOT(onArrowTextChanged(const QString&))); + connect(ui->leArrowTextR, SIGNAL(textEdited(const QString&)), + this, SLOT(onArrowTextChanged(const QString&))); + connect(ui->leArrowTextC, SIGNAL(textEdited(const QString&)), + this, SLOT(onArrowTextChanged(const QString&))); + + connect(ui->leOtherTextL, SIGNAL(textEdited(const QString&)), + this, SLOT(onOtherTextChanged(const QString&))); + connect(ui->leOtherTextR, SIGNAL(textEdited(const QString&)), + this, SLOT(onOtherTextChanged(const QString&))); + connect(ui->leOtherTextC, SIGNAL(textEdited(const QString&)), + this, SLOT(onOtherTextChanged(const QString&))); + + setUiPrimary(); } +//ctor for edit +TaskWeldingSymbol::TaskWeldingSymbol(TechDraw::DrawWeldSymbol* weld) : + ui(new Ui_TaskWeldingSymbol), + m_leadFeat(nullptr), + m_weldFeat(weld), + m_arrowIn(nullptr), + m_otherIn(nullptr), + m_createMode(false), + m_arrowDirty(false), + m_otherDirty(false) +{ +// Base::Console().Message("TWS::TWS() - edit mode\n"); + if (m_weldFeat == nullptr) { + //should be caught in CMD caller + Base::Console().Error("TaskWeldingSymbol - bad parameters. Can not proceed.\n"); + return; + } + + App::DocumentObject* obj = m_weldFeat->Leader.getValue(); + if ( (obj != nullptr) && + (obj->isDerivedFrom(TechDraw::DrawLeaderLine::getClassTypeId())) ) { + m_leadFeat = static_cast(obj); + } else { + Base::Console().Error("TaskWeldingSymbol - no leader for welding symbol. Can not proceed.\n"); + return; + } + + ui->setupUi(this); + + connect(ui->pbArrowSymbol, SIGNAL(clicked(bool)), + this, SLOT(onArrowSymbolClicked(bool))); + + connect(ui->pbOtherSymbol, SIGNAL(clicked(bool)), + this, SLOT(onOtherSymbolClicked(bool))); + connect(ui->pbOtherErase, SIGNAL(clicked(bool)), + this, SLOT(onOtherEraseClicked(bool))); + + connect(ui->fcSymbolDir, SIGNAL(fileNameSelected(const QString&)), + this, SLOT(onDirectorySelected(const QString&))); + + connect(ui->leArrowTextL, SIGNAL(textEdited(const QString&)), + this, SLOT(onArrowTextChanged(const QString&))); + connect(ui->leArrowTextR, SIGNAL(textEdited(const QString&)), + this, SLOT(onArrowTextChanged(const QString&))); + connect(ui->leArrowTextC, SIGNAL(textEdited(const QString&)), + this, SLOT(onArrowTextChanged(const QString&))); + + connect(ui->leOtherTextL, SIGNAL(textEdited(const QString&)), + this, SLOT(onOtherTextChanged(const QString&))); + connect(ui->leOtherTextR, SIGNAL(textEdited(const QString&)), + this, SLOT(onOtherTextChanged(const QString&))); + connect(ui->leOtherTextC, SIGNAL(textEdited(const QString&)), + this, SLOT(onOtherTextChanged(const QString&))); + + saveState(); + setUiEdit(); +} + TaskWeldingSymbol::~TaskWeldingSymbol() { delete ui; @@ -130,220 +207,214 @@ void TaskWeldingSymbol::setUiPrimary() setWindowTitle(QObject::tr("Create Welding Symbol")); m_currDir = QString::fromUtf8(prefSymbolDir().c_str()); ui->fcSymbolDir->setFileName(m_currDir); - loadSymbolNames(m_currDir); - ui->lwSymbols->setViewMode(QListView::IconMode); - ui->lwSymbols->setFlow(QListView::LeftToRight); - ui->lwSymbols->setWrapping(true); - ui->lwSymbols->setDragEnabled(true); - ui->lwSymbols->setSelectionMode(QAbstractItemView::SingleSelection); - ui->lwSymbols->setAcceptDrops(false); + ui->pbArrowSymbol->setFocus(); + m_arrowOut.init(); + m_arrowPath = QString(); + m_otherOut.init(); + m_otherPath = QString(); } void TaskWeldingSymbol::setUiEdit() { // Base::Console().Message("TWS::setUiEdit()\n"); setWindowTitle(QObject::tr("Edit Welding Symbol")); -} -void TaskWeldingSymbol::onArrow0Clicked(bool b) -{ -// Base::Console().Message("TWS::OnArrow0Clicked()\n"); - Q_UNUSED(b); - Qt::KeyboardModifiers km = QApplication::keyboardModifiers(); - if (km & Qt::ControlModifier) { - ui->pbArrow0->setText(QString::fromUtf8("Add")); - ui->pbArrow0->setIcon(QIcon()); - removePendingTile(0,0); - return; - } - - QListWidgetItem* sourceItem = ui->lwSymbols->currentItem(); - QString targetText = sourceItem->text(); - TechDrawGui::Tile2Add newTile; + m_currDir = QString::fromUtf8(prefSymbolDir().c_str()); //sb path part of 1st symbol file?? + ui->fcSymbolDir->setFileName(m_currDir); - QString iconPath = m_currDir + - targetText + - QString::fromUtf8(".svg") ; + ui->cbAllAround->setChecked(m_weldFeat->AllAround.getValue()); + ui->cbFieldWeld->setChecked(m_weldFeat->FieldWeld.getValue()); + ui->cbAltWeld->setChecked(m_weldFeat->AlternatingWeld.getValue()); + ui->leTailText->setText(QString::fromUtf8(m_weldFeat->TailText.getValue())); - QIcon targetIcon(iconPath); - QSize iconSize(32,32); - ui->pbArrow0->setIcon(targetIcon); - ui->pbArrow0->setIconSize(iconSize); - ui->pbArrow0->setText(QString()); - - newTile.arrowSide = true; - newTile.symbolPath = Base::Tools::toStdString(iconPath); - newTile.leftText = Base::Tools::toStdString(ui->leLeftText->text()); - newTile.centerText = Base::Tools::toStdString(ui->leCenterText->text()); - newTile.rightText = Base::Tools::toStdString(ui->leRightText->text()); - newTile.row = 0; - newTile.col = 0; - m_tiles2Add.push_back(newTile); - m_arrowCount++; -} + //save existing tiles done in saveState + if (m_arrowIn != nullptr) { + QString qTemp = QString::fromUtf8(m_arrowIn->LeftText.getValue()); + ui->leArrowTextL->setText(qTemp); + qTemp = QString::fromUtf8(m_arrowIn->RightText.getValue()); + ui->leArrowTextR->setText(qTemp); + qTemp = QString::fromUtf8(m_arrowIn->CenterText.getValue()); + ui->leArrowTextC->setText(qTemp); -void TaskWeldingSymbol::onArrow1Clicked(bool b) -{ -// Base::Console().Message("TWS::OnArrow1Clicked()\n"); - Q_UNUSED(b); - Qt::KeyboardModifiers km = QApplication::keyboardModifiers(); - if (km & Qt::ControlModifier) { - ui->pbArrow1->setText(QString::fromUtf8("Add")); - ui->pbArrow1->setIcon(QIcon()); - removePendingTile(0,1); - return; + std::string inFile = m_arrowIn->SymbolFile.getValue(); + auto fi = Base::FileInfo(inFile); + if (fi.isReadable()) { + qTemp = QString::fromUtf8(m_arrowIn->SymbolFile.getValue()); + QIcon targetIcon(qTemp); + QSize iconSize(32,32); + ui->pbArrowSymbol->setIcon(targetIcon); + ui->pbArrowSymbol->setIconSize(iconSize); + ui->pbArrowSymbol->setText(QString()); + } } - QListWidgetItem* sourceItem = ui->lwSymbols->currentItem(); - QString targetText = sourceItem->text(); - TechDrawGui::Tile2Add newTile; + if (m_otherIn != nullptr) { + QString qTemp = QString::fromUtf8(m_otherIn->LeftText.getValue()); + ui->leOtherTextL->setText(qTemp); + qTemp = QString::fromUtf8(m_otherIn->RightText.getValue()); + ui->leOtherTextR->setText(qTemp); + qTemp = QString::fromUtf8(m_otherIn->CenterText.getValue()); + ui->leOtherTextC->setText(qTemp); - QString iconPath = m_currDir + - targetText + - QString::fromUtf8(".svg") ; - - QIcon targetIcon(iconPath); - QSize iconSize(32,32); - ui->pbArrow1->setIcon(targetIcon); - ui->pbArrow1->setIconSize(iconSize); - ui->pbArrow1->setText(QString()); - - newTile.arrowSide = true; - newTile.symbolPath = Base::Tools::toStdString(iconPath); - newTile.leftText = Base::Tools::toStdString(ui->leLeftText->text()); - newTile.centerText = Base::Tools::toStdString(ui->leCenterText->text()); - newTile.rightText = Base::Tools::toStdString(ui->leRightText->text()); - newTile.row = 0; - newTile.col = 1; - m_tiles2Add.push_back(newTile); - m_arrowCount++; -} - -void TaskWeldingSymbol::onOther0Clicked(bool b) -{ -// Base::Console().Message("TWS::onOther0Clicked()\n"); - Q_UNUSED(b); - Qt::KeyboardModifiers km = QApplication::keyboardModifiers(); - if (km & Qt::ControlModifier) { - ui->pbOther0->setText(QString::fromUtf8("Add")); - ui->pbOther0->setIcon(QIcon()); - removePendingTile(-1,0); - return; + std::string inFile = m_otherIn->SymbolFile.getValue(); + auto fi = Base::FileInfo(inFile); + if (fi.isReadable()) { + qTemp = QString::fromUtf8(m_otherIn->SymbolFile.getValue()); + QIcon targetIcon(qTemp); + QSize iconSize(32,32); + ui->pbOtherSymbol->setIcon(targetIcon); + ui->pbOtherSymbol->setIconSize(iconSize); + ui->pbOtherSymbol->setText(QString()); + } } - QListWidgetItem* sourceItem = ui->lwSymbols->currentItem(); - QString targetText = sourceItem->text(); - TechDrawGui::Tile2Add newTile; - - QString iconPath = m_currDir + - targetText + - QString::fromUtf8(".svg") ; - - QIcon targetIcon(iconPath); - QSize iconSize(32,32); - ui->pbOther0->setIcon(targetIcon); - ui->pbOther0->setIconSize(iconSize); - ui->pbOther0->setText(QString()); - - newTile.arrowSide = false; - newTile.symbolPath = Base::Tools::toStdString(iconPath); - newTile.leftText = Base::Tools::toStdString(ui->leLeftText->text()); - newTile.centerText = Base::Tools::toStdString(ui->leCenterText->text()); - newTile.rightText = Base::Tools::toStdString(ui->leRightText->text()); - newTile.row = -1; - newTile.col = 0; - m_tiles2Add.push_back(newTile); - m_otherCount++; + ui->pbArrowSymbol->setFocus(); } -void TaskWeldingSymbol::onOther1Clicked(bool b) +void TaskWeldingSymbol::onArrowSymbolClicked(bool b) { -// Base::Console().Message("TWS::onOther1Clicked()\n"); +// Base::Console().Message("TWS::OnArrowSymbolClicked()\n"); Q_UNUSED(b); - Qt::KeyboardModifiers km = QApplication::keyboardModifiers(); - if (km & Qt::ControlModifier) { - ui->pbOther1->setText(QString::fromUtf8("Add")); - ui->pbOther1->setIcon(QIcon()); - removePendingTile(-1,1); - return; - } - - QListWidgetItem* sourceItem = ui->lwSymbols->currentItem(); - QString targetText = sourceItem->text(); - TechDrawGui::Tile2Add newTile; - QString iconPath = m_currDir + - targetText + - QString::fromUtf8(".svg") ; + QString source = QString::fromUtf8("arrow"); + SymbolChooser* dlg = new SymbolChooser(this, m_currDir, source); + connect(dlg, SIGNAL(symbolSelected(QString, QString)), + this, SLOT(onSymbolSelected(QString, QString))); + dlg->setAttribute(Qt::WA_DeleteOnClose); - QIcon targetIcon(iconPath); - QSize iconSize(32,32); - ui->pbOther1->setIcon(targetIcon); - ui->pbOther1->setIconSize(iconSize); - ui->pbOther1->setText(QString()); - - newTile.arrowSide = false; - newTile.symbolPath = Base::Tools::toStdString(iconPath); - newTile.leftText = Base::Tools::toStdString(ui->leLeftText->text()); - newTile.centerText = Base::Tools::toStdString(ui->leCenterText->text()); - newTile.rightText = Base::Tools::toStdString(ui->leRightText->text()); - newTile.row = -1; - newTile.col = 1; - m_tiles2Add.push_back(newTile); - m_otherCount++; + //int rc = + dlg->exec(); } +void TaskWeldingSymbol::onOtherSymbolClicked(bool b) +{ +// Base::Console().Message("TWS::OnOtherSymbolClicked()\n"); + Q_UNUSED(b); + + QString source = QString::fromUtf8("other"); + SymbolChooser* dlg = new SymbolChooser(this, m_currDir, source); + connect(dlg, SIGNAL(symbolSelected(QString, QString)), + this, SLOT(onSymbolSelected(QString, QString))); + dlg->setAttribute(Qt::WA_DeleteOnClose); + +// int rc = + dlg->exec(); +} + +void TaskWeldingSymbol::onOtherEraseClicked(bool b) +{ +// Base::Console().Message("TWS::onOtherEraseClicked()\n"); + Q_UNUSED(b); + m_otherOut.init(); + + ui->leOtherTextL->setText(QString()); + ui->leOtherTextC->setText(QString()); + ui->leOtherTextR->setText(QString()); + ui->pbOtherSymbol->setIcon(QIcon()); + ui->pbOtherSymbol->setText(QString::fromUtf8("Symbol")); + + if ( (!m_createMode) && + (m_otherIn != nullptr) ) { + m_toRemove.push_back(m_otherIn->getNameInDocument()); + } + m_otherIn = nullptr; +} + +void TaskWeldingSymbol::onArrowTextChanged(const QString& qs) +{ +// Base::Console().Message("TWS::onArrowTextChanged(%s)\n", qPrintable(qs)); + Q_UNUSED(qs); + m_arrowDirty = true; +} + +void TaskWeldingSymbol::onOtherTextChanged(const QString& qs) +{ +// Base::Console().Message("TWS::onOtherTextChanged(%s)\n", qPrintable(qs)); + Q_UNUSED(qs); + m_otherDirty = true; +} + + void TaskWeldingSymbol::onDirectorySelected(const QString& newDir) { // Base::Console().Message("TWS::onDirectorySelected(%s)\n", qPrintable(newDir)); m_currDir = newDir + QString::fromUtf8("/"); - loadSymbolNames(m_currDir); } -void TaskWeldingSymbol::removePendingTile(int row, int col) +void TaskWeldingSymbol::onSymbolSelected(QString symbolPath, + QString source) { -// Base::Console().Message("TWS::removePendingIcon(%d, %d) - tiles in: %d\n", -// row, col, m_tiles2Add.size()); - std::vector newList; - for (auto& t: m_tiles2Add) { - if ((t.row == row) && - (t.col == col) ) { - continue; - } else { - newList.push_back(t); - } +// Base::Console().Message("TWS::onSymbolSelected(%s) - source: %s\n", +// qPrintable(symbolPath), qPrintable(source)); + QIcon targetIcon(symbolPath); + QSize iconSize(32,32); + QString arrow = QString::fromUtf8("arrow"); + QString other = QString::fromUtf8("other"); + if (source == arrow) { + m_arrowDirty = true; + ui->pbArrowSymbol->setIcon(targetIcon); + ui->pbArrowSymbol->setIconSize(iconSize); + ui->pbArrowSymbol->setText(QString()); + m_arrowPath = symbolPath; + } else if (source == other) { + m_otherDirty = true; + ui->pbOtherSymbol->setIcon(targetIcon); + ui->pbOtherSymbol->setIconSize(iconSize); + ui->pbOtherSymbol->setText(QString()); + m_otherPath = symbolPath; } - m_tiles2Add = newList; } - void TaskWeldingSymbol::blockButtons(bool b) { Q_UNUSED(b); } -void TaskWeldingSymbol::loadSymbolNames(QString pathToSymbols) +void TaskWeldingSymbol::saveState(void) { - //fill selection list with names and icons - QDir symbolDir(pathToSymbols); - symbolDir.setFilter(QDir::Files); - QStringList fileNames = symbolDir.entryList(); - - for (auto& fn: fileNames) { - QListWidgetItem* item = new QListWidgetItem(fn, ui->lwSymbols); - QFileInfo fi(fn); - item->setText(fi.baseName()); - QIcon symbolIcon(pathToSymbols + fn); - item->setIcon(symbolIcon); - ui->lwSymbols->addItem(item); + std::vector tiles = m_weldFeat->getTiles(); + for (auto t: tiles) { + if (t->TileRow.getValue() == 0) { + m_arrowIn = t; + } else if (t->TileRow.getValue() == -1) { + m_otherIn = t; + } else { + Base::Console().Message("TWS::saveState - bad row: %d\n", t->TileRow.getValue()); + } } - ui->lwSymbols->setCurrentRow(0); - ui->lwSymbols->setAcceptDrops(false); //have to do this every time you update the items +} + +void TaskWeldingSymbol::collectArrowData(void) +{ +// Base::Console().Message("TWS::collectArrowData()\n"); + m_arrowOut.toBeSaved = true; + m_arrowOut.arrowSide = false; + m_arrowOut.row = 0; + m_arrowOut.col = 0; + m_arrowOut.leftText = Base::Tools::toStdString(ui->leArrowTextL->text()); + m_arrowOut.centerText = Base::Tools::toStdString(ui->leArrowTextC->text()); + m_arrowOut.rightText = Base::Tools::toStdString(ui->leArrowTextR->text()); + m_arrowOut.symbolPath= Base::Tools::toStdString(m_arrowPath); + m_arrowOut.tileName = ""; +} + +void TaskWeldingSymbol::collectOtherData(void) +{ +// Base::Console().Message("TWS::collectOtherData()\n"); + m_otherOut.toBeSaved = true; + m_otherOut.arrowSide = false; + m_otherOut.row = -1; + m_otherOut.col = 0; + m_otherOut.leftText = Base::Tools::toStdString(ui->leOtherTextL->text()); + m_otherOut.centerText = Base::Tools::toStdString(ui->leOtherTextC->text()); + m_otherOut.rightText = Base::Tools::toStdString(ui->leOtherTextR->text()); + m_otherOut.symbolPath= Base::Tools::toStdString(m_otherPath); + m_otherOut.tileName = ""; } //****************************************************************************** -App::DocumentObject* TaskWeldingSymbol::createWeldingSymbol(void) +TechDraw::DrawWeldSymbol* TaskWeldingSymbol::createWeldingSymbol(void) { // Base::Console().Message("TWS::createWeldingSymbol()\n"); Gui::Command::openCommand("Create WeldSymbol"); @@ -361,53 +432,85 @@ App::DocumentObject* TaskWeldingSymbol::createWeldingSymbol(void) Command::doCommand(Command::Doc,"App.activeDocument().%s.Leader = App.activeDocument().%s", symbolName.c_str(),m_leadFeat->getNameInDocument()); - bool allAround = ui->rbAllAround->isChecked(); + bool allAround = ui->cbAllAround->isChecked(); std::string allAroundText = allAround ? "True" : "False"; Command::doCommand(Command::Doc,"App.activeDocument().%s.AllAround = %s", symbolName.c_str(), allAroundText.c_str()); - bool fieldWeld = ui->rbFieldWeld->isChecked(); + bool fieldWeld = ui->cbFieldWeld->isChecked(); std::string fieldWeldText = fieldWeld ? "True" : "False"; Command::doCommand(Command::Doc,"App.activeDocument().%s.FieldWeld = %s", symbolName.c_str(), fieldWeldText.c_str()); + bool altWeld = ui->cbAltWeld->isChecked(); + std::string altWeldText = altWeld ? "True" : "False"; + Command::doCommand(Command::Doc,"App.activeDocument().%s.AlternatingWeld = %s", + symbolName.c_str(), altWeldText.c_str()); + std::string tailText = Base::Tools::toStdString(ui->leTailText->text()); Command::doCommand(Command::Doc,"App.activeDocument().%s.TailText = '%s'", symbolName.c_str(), tailText.c_str()); App::DocumentObject* newObj = m_leadFeat->getDocument()->getObject(symbolName.c_str()); - if (newObj == nullptr) { + TechDraw::DrawWeldSymbol* newSym = dynamic_cast(newObj); + if ( (newObj == nullptr) || + (newSym == nullptr) ) { throw Base::RuntimeError("TaskWeldingSymbol - new symbol object not found"); } - newObj->recomputeFeature(); + Gui::Command::updateActive(); Gui::Command::commitCommand(); - return newObj; + return newSym; +} + +void TaskWeldingSymbol::updateWeldingSymbol(void) +{ +// Base::Console().Message("TWS::updateWeldingSymbol()\n"); + std::string symbolName = m_weldFeat->getNameInDocument(); + + bool allAround = ui->cbAllAround->isChecked(); + std::string allAroundText = allAround ? "True" : "False"; + Command::doCommand(Command::Doc,"App.activeDocument().%s.AllAround = %s", + symbolName.c_str(), allAroundText.c_str()); + + bool fieldWeld = ui->cbFieldWeld->isChecked(); + std::string fieldWeldText = fieldWeld ? "True" : "False"; + Command::doCommand(Command::Doc,"App.activeDocument().%s.FieldWeld = %s", + symbolName.c_str(), fieldWeldText.c_str()); + + bool altWeld = ui->cbAltWeld->isChecked(); + std::string altWeldText = altWeld ? "True" : "False"; + Command::doCommand(Command::Doc,"App.activeDocument().%s.AlternatingWeld = %s", + symbolName.c_str(), altWeldText.c_str()); + + std::string tailText = Base::Tools::toStdString(ui->leTailText->text()); + Command::doCommand(Command::Doc,"App.activeDocument().%s.TailText = '%s'", + symbolName.c_str(), tailText.c_str()); } std::vector TaskWeldingSymbol::createTiles(void) { // Base::Console().Message("TWS::createTiles()\n"); - Gui::Command::openCommand("Create Welding Tiles"); std::vector tileFeats; std::string tileType("TechDraw::DrawTileWeld"); - for (auto& t: m_tiles2Add) { + + collectArrowData(); + if (m_arrowOut.toBeSaved) { std::string tileName = m_leadFeat->getDocument()->getUniqueObjectName("DrawTileWeld"); Command::doCommand(Command::Doc,"App.activeDocument().addObject('%s','%s')", tileType.c_str(),tileName.c_str()); Command::doCommand(Command::Doc,"App.activeDocument().%s.TileRow = %d", - tileName.c_str(), t.row); + tileName.c_str(), m_arrowOut.row); Command::doCommand(Command::Doc,"App.activeDocument().%s.TileColumn = %d", - tileName.c_str(), t.col); + tileName.c_str(), m_arrowOut.col); Command::doCommand(Command::Doc,"App.activeDocument().%s.SymbolFile = '%s'", - tileName.c_str(), t.symbolPath.c_str()); + tileName.c_str(), m_arrowOut.symbolPath.c_str()); Command::doCommand(Command::Doc,"App.activeDocument().%s.LeftText = '%s'", - tileName.c_str(), t.leftText.c_str()); + tileName.c_str(), m_arrowOut.leftText.c_str()); Command::doCommand(Command::Doc,"App.activeDocument().%s.RightText = '%s'", - tileName.c_str(), t.rightText.c_str()); + tileName.c_str(), m_arrowOut.rightText.c_str()); Command::doCommand(Command::Doc,"App.activeDocument().%s.CenterText = '%s'", - tileName.c_str(), t.centerText.c_str()); - + tileName.c_str(), m_arrowOut.centerText.c_str()); App::DocumentObject* newTile = m_leadFeat->getDocument()->getObject(tileName.c_str()); if (newTile == nullptr) { throw Base::RuntimeError("TaskWeldingSymbol - new tile object not found"); @@ -415,19 +518,132 @@ std::vector TaskWeldingSymbol::createTiles(void) tileFeats.push_back(newTile); } - Gui::Command::updateActive(); - Gui::Command::commitCommand(); + if (m_otherDirty) { + collectOtherData(); + if (m_otherOut.toBeSaved) { + std::string tileName = m_leadFeat->getDocument()->getUniqueObjectName("DrawTileWeld"); + Command::doCommand(Command::Doc,"App.activeDocument().addObject('%s','%s')", + tileType.c_str(),tileName.c_str()); + Command::doCommand(Command::Doc,"App.activeDocument().%s.TileRow = %d", + tileName.c_str(), m_otherOut.row); + Command::doCommand(Command::Doc,"App.activeDocument().%s.TileColumn = %d", + tileName.c_str(), m_otherOut.col); + + if (m_otherOut.symbolPath.empty()) { + Command::doCommand(Command::Doc,"App.activeDocument().%s.SymbolFile = ''", + tileName.c_str()); + } else { + Command::doCommand(Command::Doc,"App.activeDocument().%s.SymbolFile = '%s'", + tileName.c_str(), m_otherOut.symbolPath.c_str()); + } + + Command::doCommand(Command::Doc,"App.activeDocument().%s.LeftText = '%s'", + tileName.c_str(), m_otherOut.leftText.c_str()); + Command::doCommand(Command::Doc,"App.activeDocument().%s.RightText = '%s'", + tileName.c_str(), m_otherOut.rightText.c_str()); + Command::doCommand(Command::Doc,"App.activeDocument().%s.CenterText = '%s'", + tileName.c_str(), m_otherOut.centerText.c_str()); + App::DocumentObject* newTile = m_leadFeat->getDocument()->getObject(tileName.c_str()); + if (newTile == nullptr) { + throw Base::RuntimeError("TaskWeldingSymbol - new tile object not found"); + } + tileFeats.push_back(newTile); + } + } + return tileFeats; } -void TaskWeldingSymbol::updateWeldingSymbol(void) +std::vector TaskWeldingSymbol::updateTiles(void) { -// Base::Console().Message("TWS::updateWeldingSymbol()\n"); - Gui::Command::openCommand("Edit WeldingSymbol"); - m_weldFeat->requestPaint(); +// Base::Console().Message("TWS::updateTiles()\n"); + std::vector tileFeats; + std::string tileType("TechDraw::DrawTileWeld"); + std::string tileName; - Gui::Command::updateActive(); - Gui::Command::commitCommand(); + collectArrowData(); + + if (m_arrowIn != nullptr) { + tileName = m_arrowIn->getNameInDocument(); + } + if (m_arrowIn == nullptr) { + tileName = m_leadFeat->getDocument()->getUniqueObjectName("DrawTileWeld"); + Command::doCommand(Command::Doc,"App.activeDocument().addObject('%s','%s')", + tileType.c_str(),tileName.c_str()); + App::DocumentObject* newTile = m_leadFeat->getDocument()->getObject(tileName.c_str()); + if (newTile == nullptr) { + throw Base::RuntimeError("TaskWeldingSymbol - new tile object not found"); + } + tileFeats.push_back(newTile); + } + + if (m_arrowOut.toBeSaved) { + Command::doCommand(Command::Doc,"App.activeDocument().%s.TileRow = %d", + tileName.c_str(), m_arrowOut.row); + Command::doCommand(Command::Doc,"App.activeDocument().%s.TileColumn = %d", + tileName.c_str(), m_arrowOut.col); + + if (m_otherOut.symbolPath.empty()) { + Command::doCommand(Command::Doc,"App.activeDocument().%s.SymbolFile = ''", + tileName.c_str()); + } else { + Command::doCommand(Command::Doc,"App.activeDocument().%s.SymbolFile = '%s'", + tileName.c_str(), m_arrowOut.symbolPath.c_str()); + } + + Command::doCommand(Command::Doc,"App.activeDocument().%s.LeftText = '%s'", + tileName.c_str(), m_arrowOut.leftText.c_str()); + Command::doCommand(Command::Doc,"App.activeDocument().%s.RightText = '%s'", + tileName.c_str(), m_arrowOut.rightText.c_str()); + Command::doCommand(Command::Doc,"App.activeDocument().%s.CenterText = '%s'", + tileName.c_str(), m_arrowOut.centerText.c_str()); + } + + if (m_otherDirty) { + collectOtherData(); + + if (m_otherIn != nullptr) { + tileName = m_otherIn->getNameInDocument(); + } + + if ( (m_otherIn == nullptr) && + (m_otherOut.toBeSaved) ) { + tileName = m_leadFeat->getDocument()->getUniqueObjectName("DrawTileWeld"); + Command::doCommand(Command::Doc,"App.activeDocument().addObject('%s','%s')", + tileType.c_str(),tileName.c_str()); + App::DocumentObject* newTile = m_leadFeat->getDocument()->getObject(tileName.c_str()); + if (newTile == nullptr) { + throw Base::RuntimeError("TaskWeldingSymbol - new tile object not found"); + } + tileFeats.push_back(newTile); + } + + if (m_otherOut.toBeSaved) { + Command::doCommand(Command::Doc,"App.activeDocument().addObject('%s','%s')", + tileType.c_str(),tileName.c_str()); + Command::doCommand(Command::Doc,"App.activeDocument().%s.TileRow = %d", + tileName.c_str(), m_otherOut.row); + Command::doCommand(Command::Doc,"App.activeDocument().%s.TileColumn = %d", + tileName.c_str(), m_otherOut.col); + + if (m_otherOut.symbolPath.empty()) { + Command::doCommand(Command::Doc,"App.activeDocument().%s.SymbolFile = ''", + tileName.c_str()); + } else { + Command::doCommand(Command::Doc,"App.activeDocument().%s.SymbolFile = '%s'", + tileName.c_str(), m_otherOut.symbolPath.c_str()); + } + + Command::doCommand(Command::Doc,"App.activeDocument().%s.LeftText = '%s'", + tileName.c_str(), m_otherOut.leftText.c_str()); + Command::doCommand(Command::Doc,"App.activeDocument().%s.RightText = '%s'", + tileName.c_str(), m_otherOut.rightText.c_str()); + Command::doCommand(Command::Doc,"App.activeDocument().%s.CenterText = '%s'", + tileName.c_str(), m_otherOut.centerText.c_str()); + } + } + + return tileFeats; } void TaskWeldingSymbol::saveButtons(QPushButton* btnOK, @@ -458,15 +674,36 @@ std::string TaskWeldingSymbol::prefSymbolDir() bool TaskWeldingSymbol::accept() { // Base::Console().Message("TWS::accept()\n"); - std::vector tileFeats = createTiles(); - App::DocumentObject* weldFeat = createWeldingSymbol(); - for (auto& obj: tileFeats) { - TechDraw::DrawTileWeld* tile = dynamic_cast(obj); - tile->TileParent.setValue(weldFeat); + if (m_createMode) { + m_weldFeat = createWeldingSymbol(); + std::vector tileFeats = createTiles(); + for (auto& obj: tileFeats) { + TechDraw::DrawTileWeld* tile = dynamic_cast(obj); + tile->TileParent.setValue(m_weldFeat); + } + m_weldFeat->recomputeFeature(); + // m_weldFeat->requestPaint(); //not a dv! + } else { + try { + updateWeldingSymbol(); + std::vector tileFeats = updateTiles(); + for (auto& obj: tileFeats) { //new tiles only + TechDraw::DrawTileWeld* tile = dynamic_cast(obj); + tile->TileParent.setValue(m_weldFeat); + } + for (auto name: m_toRemove) { + Command::doCommand(Command::Doc, + "App.activeDocument().removeObject('%s')", name.c_str()); + } + } + + catch (...) { + Base::Console().Error("TWS::accept - failed to update symbol\n"); + } + + m_weldFeat->recomputeFeature(); + // m_weldFeat->requestPaint(); //not a dv! } - weldFeat->recomputeFeature(); -// weldFeat->requestPaint(); //not a dv! - Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); return true; @@ -493,6 +730,16 @@ TaskDlgWeldingSymbol::TaskDlgWeldingSymbol(TechDraw::DrawLeaderLine* leader) Content.push_back(taskbox); } +TaskDlgWeldingSymbol::TaskDlgWeldingSymbol(TechDraw::DrawWeldSymbol* weld) + : TaskDialog() +{ + widget = new TaskWeldingSymbol(weld); + taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/techdraw-weldsymbol"), + widget->windowTitle(), true, 0); + taskbox->groupLayout()->addWidget(widget); + Content.push_back(taskbox); +} + TaskDlgWeldingSymbol::~TaskDlgWeldingSymbol() { } diff --git a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.h b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.h index a935545f62..231cb3bdf9 100644 --- a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.h +++ b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.h @@ -32,7 +32,6 @@ #include - class Ui_TaskWeldingSymbol; class Ui_TaskCL2Lines; @@ -46,6 +45,8 @@ class DrawPage; class DrawView; class DrawLeaderLine; class DrawWeldSymbol; +class DrawTileWeld; +class DrawTile; } namespace TechDraw @@ -62,35 +63,55 @@ class QGIWeldSymbol; class MDIViewPage; //class ViewProviderWeld; -class Tile2Add +class TileImage { public: - Tile2Add() {}; - ~Tile2Add() = default; - bool arrowSide; // or is row enough? + TileImage() {}; + ~TileImage() = default; + bool toBeSaved; + bool arrowSide; int row; int col; std::string leftText; std::string centerText; std::string rightText; std::string symbolPath; + std::string tileName; + void init(void) { + toBeSaved = false; + arrowSide = true; + row = 0; + col = 0; + leftText = ""; + centerText = ""; + rightText = ""; + symbolPath= ""; + tileName = ""; + } + }; -class TaskWeldingSymbol : public QWidget +class TechDrawGuiExport TaskWeldingSymbol : public QWidget { Q_OBJECT public: TaskWeldingSymbol(TechDraw::DrawLeaderLine* baseFeat); + TaskWeldingSymbol(TechDraw::DrawWeldSymbol* weldFeat); ~TaskWeldingSymbol(); public Q_SLOTS: - void onArrow0Clicked(bool b); - void onArrow1Clicked(bool b); - void onOther0Clicked(bool b); - void onOther1Clicked(bool b); + void onArrowSymbolClicked(bool b); + + void onOtherSymbolClicked(bool b); + void onOtherEraseClicked(bool b); + + void onArrowTextChanged(const QString& qs); + void onOtherTextChanged(const QString& qs); + void onDirectorySelected(const QString& newDir); - + void onSymbolSelected(QString symbolPath, QString source); + public: virtual bool accept(); virtual bool reject(); @@ -98,7 +119,6 @@ public: void saveButtons(QPushButton* btnOK, QPushButton* btnCancel); void enableTaskButtons(bool b); - void setFlipped(bool b); protected Q_SLOTS: @@ -109,34 +129,43 @@ protected: void setUiPrimary(void); void setUiEdit(); - void turnOnArrow(); - void turnOnOther(); - void removePendingTile(int row, int col); - - - App::DocumentObject* createWeldingSymbol(void); + TechDraw::DrawWeldSymbol* createWeldingSymbol(void); void updateWeldingSymbol(void); - std::vector createTiles(void); - void loadSymbolNames(QString pathToSymbols); + std::vector createTiles(void); + std::vector updateTiles(void); + + void collectArrowData(void); + void collectOtherData(void); std::string prefSymbolDir(); + void saveState(void); + QString m_currDir; - private: - Ui_TaskWeldingSymbol * ui; + Ui_TaskWeldingSymbol* ui; TechDraw::DrawLeaderLine* m_leadFeat; TechDraw::DrawWeldSymbol* m_weldFeat; + TechDraw::DrawTileWeld* m_arrowIn; + TechDraw::DrawTileWeld* m_otherIn; - std::vector m_tiles2Add; + TileImage m_arrowOut; + TileImage m_otherOut; + + QString m_arrowPath; + QString m_otherPath; + + std::vector m_toRemove; QPushButton* m_btnOK; QPushButton* m_btnCancel; - int m_arrowCount; - int m_otherCount; + bool m_createMode; + + bool m_arrowDirty; + bool m_otherDirty; }; @@ -146,6 +175,7 @@ class TaskDlgWeldingSymbol : public Gui::TaskView::TaskDialog public: TaskDlgWeldingSymbol(TechDraw::DrawLeaderLine* leader); + TaskDlgWeldingSymbol(TechDraw::DrawWeldSymbol* weld); ~TaskDlgWeldingSymbol(); public: diff --git a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.ui b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.ui index a72b219b08..22e2949735 100644 --- a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.ui +++ b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.ui @@ -6,8 +6,8 @@ 0 0 - 409 - 578 + 423 + 374 @@ -50,63 +50,63 @@ - - - - 0 - 0 - - - - - 0 - 32 - - - - - 0 - 32 - - - - Add an Arrow Side Symbol - - - - - - Add - - - - - - - - 0 - 0 - - - - - 0 - 32 - - - - - 0 - 32 - - - - Add an Arrow Side Symbol - - - Add - - + + + + + Text before arrow side symbol + + + + + + + Text after arrow side symbol + + + + + + + + 0 + 0 + + + + + 0 + 32 + + + + + 0 + 32 + + + + Pick arrow side symbol + + + + + + Symbol + + + false + + + + + + + Text above arrow side symbol + + + + @@ -126,176 +126,69 @@ - - - - 0 - 0 - - - - - 0 - 32 - - - - - 0 - 32 - - - - Add an Other Side Symbol - - - Add - - - - - - - - 0 - 0 - - - - - 0 - 32 - - - - - 0 - 32 - - - - Add an Other Side Symbol - - - Add - - - - - - - - - - - - 0 - 0 - - - - - 0 - 128 - - - - - 16777215 - 256 - - - - - 0 - 64 - - - - - 0 - 128 - - - - Select a symbol - - - QListView::Static - - - QListView::LeftToRight - - - true - - - QListView::Adjust - - - - 64 - 64 - - - - QListView::IconMode - - - false - - - false - - - -1 - - - - - - - QFormLayout::AllNonFixedFieldsGrow - - - - - Left Text + + + + + Text after other side symbol - + - Text before symbol + Pick other side symbol + + + Symbol - - - - Center Text + + + + Text before other side symbol - + - Text above/below symbol + Text below other side symbol - - + + + + + 0 + 0 + + + + + 60 + 30 + + + + + 60 + 30 + + + + + 60 + 30 + + + + Remove other side symbol + - Right Text - - - - - - - Text after symbol + Delete @@ -313,72 +206,88 @@ - - - QFormLayout::AllNonFixedFieldsGrow - - - - - Symbol Directory - - + + + + + + + Field Weld + + + + + + + All Around + + + + + + + Alternating + + + + - - - - Pick a directory of welding symbols + + + + QFormLayout::AllNonFixedFieldsGrow - - Gui::FileChooser::Directory - - - *.svg - - - - - - - Process Text - - - - - - - Text at end of symbol - - - - - - - Show on site flag - - - Field Weld - - - false - - - - - - - show perimeter circle - - - All Around - - - false - - + + + + Tail Text + + + + + + + Text at end of symbol + + + + + + + Symbol Directory + + + + + + + Pick a directory of welding symbols + + + Gui::FileChooser::Directory + + + *.svg + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + diff --git a/src/Mod/TechDraw/Gui/ViewProviderWeld.cpp b/src/Mod/TechDraw/Gui/ViewProviderWeld.cpp index f74656befc..a7bb5226d2 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderWeld.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderWeld.cpp @@ -34,9 +34,17 @@ #include #include #include -#include + +#include +#include +#include +#include +#include +#include #include +#include "TaskWeldingSymbol.h" + #include "ViewProviderWeld.h" using namespace TechDrawGui; @@ -99,6 +107,42 @@ std::vector ViewProviderWeld::claimChildren(void) const } } +bool ViewProviderWeld::setEdit(int ModNum) +{ +// Base::Console().Message("VPW::setEdit(%d)\n",ModNum); + if (ModNum == ViewProvider::Default ) { + if (Gui::Control().activeDialog()) { //TaskPanel already open! + return false; + } + // clear the selection (convenience) + Gui::Selection().clearSelection(); + Gui::Control().showDialog(new TaskDlgWeldingSymbol(getFeature())); + return true; + } else { + return ViewProviderDrawingView::setEdit(ModNum); + } + return true; +} + +void ViewProviderWeld::unsetEdit(int ModNum) +{ + Q_UNUSED(ModNum); + if (ModNum == ViewProvider::Default) { + Gui::Control().closeDialog(); + } + else { + ViewProviderDrawingView::unsetEdit(ModNum); + } +} + +bool ViewProviderWeld::doubleClicked(void) +{ +// Base::Console().Message("VPW::doubleClicked()\n"); + setEdit(ViewProvider::Default); + return true; +} + + TechDraw::DrawWeldSymbol* ViewProviderWeld::getViewObject() const { return dynamic_cast(pcObject); diff --git a/src/Mod/TechDraw/Gui/ViewProviderWeld.h b/src/Mod/TechDraw/Gui/ViewProviderWeld.h index 49adea59f7..5ee63c520f 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderWeld.h +++ b/src/Mod/TechDraw/Gui/ViewProviderWeld.h @@ -52,6 +52,9 @@ public: virtual std::vector getDisplayModes(void) const; virtual void updateData(const App::Property*); virtual std::vector claimChildren(void) const; + virtual bool setEdit(int ModNum); + virtual void unsetEdit(int ModNum); + virtual bool doubleClicked(void); virtual TechDraw::DrawWeldSymbol* getViewObject() const; virtual TechDraw::DrawWeldSymbol* getFeature() const; From 5a3de6c3df9b4766b2eb244eba5ec55f25ae5a25 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Sun, 11 Aug 2019 13:55:50 -0400 Subject: [PATCH 12/19] [TD]Add welding symbol directory preference --- src/Mod/TechDraw/Gui/DlgPrefsTechDraw.ui | 53 +++++++++++++------ src/Mod/TechDraw/Gui/DlgPrefsTechDrawImp.cpp | 3 ++ src/Mod/TechDraw/Gui/SymbolChooser.cpp | 2 + .../Symbols/Welding/AWS/filletUpPlain.svg | 30 ----------- 4 files changed, 43 insertions(+), 45 deletions(-) delete mode 100644 src/Mod/TechDraw/Symbols/Welding/AWS/filletUpPlain.svg diff --git a/src/Mod/TechDraw/Gui/DlgPrefsTechDraw.ui b/src/Mod/TechDraw/Gui/DlgPrefsTechDraw.ui index 4626cf662f..7b75b8ed44 100644 --- a/src/Mod/TechDraw/Gui/DlgPrefsTechDraw.ui +++ b/src/Mod/TechDraw/Gui/DlgPrefsTechDraw.ui @@ -454,6 +454,23 @@ + + + + TemplateFile + + + /Mod/TechDraw/Files + + + + + + + Welding Directory + + + @@ -468,7 +485,7 @@ - + Gui::FileChooser::Directory @@ -495,17 +512,7 @@ - - - - TemplateFile - - - /Mod/TechDraw/Files - - - - + Location of default svg/png fill file @@ -518,14 +525,14 @@ - + PAT File - + Default location for PAT file @@ -538,7 +545,7 @@ - + Alternate Line Group file @@ -551,6 +558,22 @@ + + + + Default directory for welding symbols + + + Gui::FileChooser::Directory + + + WeldingDir + + + /Mod/TechDraw/Files + + + diff --git a/src/Mod/TechDraw/Gui/DlgPrefsTechDrawImp.cpp b/src/Mod/TechDraw/Gui/DlgPrefsTechDrawImp.cpp index 8e2e98c374..ff532ecc92 100644 --- a/src/Mod/TechDraw/Gui/DlgPrefsTechDrawImp.cpp +++ b/src/Mod/TechDraw/Gui/DlgPrefsTechDrawImp.cpp @@ -68,6 +68,8 @@ void DlgPrefsTechDrawImp::saveSettings() pfc_DefDir->onSave(); pfc_HatchFile->onSave(); pfc_LineGroup->onSave(); + pfc_Welding->onSave(); + pfc_FilePattern->onSave(); le_NamePattern->onSave(); } @@ -97,6 +99,7 @@ void DlgPrefsTechDrawImp::loadSettings() pfc_DefDir->onRestore(); pfc_HatchFile->onRestore(); pfc_LineGroup->onRestore(); + pfc_Welding->onRestore(); pfc_FilePattern->onRestore(); le_NamePattern->onRestore(); diff --git a/src/Mod/TechDraw/Gui/SymbolChooser.cpp b/src/Mod/TechDraw/Gui/SymbolChooser.cpp index 3ed8a9e809..936a97208f 100644 --- a/src/Mod/TechDraw/Gui/SymbolChooser.cpp +++ b/src/Mod/TechDraw/Gui/SymbolChooser.cpp @@ -69,6 +69,8 @@ void SymbolChooser::setUiPrimary() loadSymbolNames(m_symbolDir); } else { std::string resourceDir = App::Application::getResourceDir(); + std::string defPath = "Mod/TechDraw/Symbols/Welding/AWS/"; + resourceDir = resourceDir + defPath; QString defDir = QString::fromUtf8(resourceDir.c_str()); ui->fcSymbolDir->setFileName(defDir); loadSymbolNames(defDir); diff --git a/src/Mod/TechDraw/Symbols/Welding/AWS/filletUpPlain.svg b/src/Mod/TechDraw/Symbols/Welding/AWS/filletUpPlain.svg deleted file mode 100644 index 49de22b4eb..0000000000 --- a/src/Mod/TechDraw/Symbols/Welding/AWS/filletUpPlain.svg +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - image/svg+xml - - - - - - - From 178520fb4abd468a75afcd331d46251594e38b93 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Mon, 12 Aug 2019 15:03:37 -0400 Subject: [PATCH 13/19] [TD] fix stale pointer in scene --- src/Mod/TechDraw/App/DrawTile.cpp | 2 - src/Mod/TechDraw/App/DrawWeldSymbol.cpp | 2 +- src/Mod/TechDraw/Gui/MDIViewPage.cpp | 4 + src/Mod/TechDraw/Gui/QGITile.cpp | 93 ++++--- src/Mod/TechDraw/Gui/QGITile.h | 21 +- src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp | 290 ++++++++++----------- src/Mod/TechDraw/Gui/QGIWeldSymbol.h | 33 ++- src/Mod/TechDraw/Gui/QGVPage.cpp | 27 +- src/Mod/TechDraw/Gui/QGVPage.h | 6 +- src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp | 17 +- 10 files changed, 260 insertions(+), 235 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawTile.cpp b/src/Mod/TechDraw/App/DrawTile.cpp index 9965b97f7f..51af3ca07c 100644 --- a/src/Mod/TechDraw/App/DrawTile.cpp +++ b/src/Mod/TechDraw/App/DrawTile.cpp @@ -47,12 +47,10 @@ DrawTile::DrawTile(void) { static const char *group = "Tile"; -// Base::Vector3d defOrg(0.0, 0.0, 0.0); ADD_PROPERTY_TYPE(TileParent,(0),group,(App::PropertyType)(App::Prop_None), "Object to which this tile is attached"); ADD_PROPERTY_TYPE(TileRow, (0), group, App::Prop_None, "Row in parent"); ADD_PROPERTY_TYPE(TileColumn, (0), group, App::Prop_None, "Column in parent"); -// ADD_PROPERTY_TYPE(TileOrigin, (defOrg), group, App::Prop_None, "Width limit before auto wrap"); } DrawTile::~DrawTile() diff --git a/src/Mod/TechDraw/App/DrawWeldSymbol.cpp b/src/Mod/TechDraw/App/DrawWeldSymbol.cpp index c3ecb1e29b..d179718796 100644 --- a/src/Mod/TechDraw/App/DrawWeldSymbol.cpp +++ b/src/Mod/TechDraw/App/DrawWeldSymbol.cpp @@ -95,7 +95,7 @@ App::DocumentObjectExecReturn *DrawWeldSymbol::execute(void) std::vector DrawWeldSymbol::getTiles(void) const { // Base::Console().Message("DWS::getTiles()\n"); - std::vector temp; +// std::vector temp; std::vector result; std::vector tiles = getInList(); diff --git a/src/Mod/TechDraw/Gui/MDIViewPage.cpp b/src/Mod/TechDraw/Gui/MDIViewPage.cpp index a153cb62f1..9145b203db 100644 --- a/src/Mod/TechDraw/Gui/MDIViewPage.cpp +++ b/src/Mod/TechDraw/Gui/MDIViewPage.cpp @@ -85,6 +85,8 @@ #include #include #include +#include +#include #include "Rez.h" #include "QGIDrawingTemplate.h" @@ -101,6 +103,8 @@ #include "QGILeaderLine.h" #include "QGIRichAnno.h" #include "QGMText.h" +#include "QGIWeldSymbol.h" +#include "QGITile.h" using namespace TechDrawGui; diff --git a/src/Mod/TechDraw/Gui/QGITile.cpp b/src/Mod/TechDraw/Gui/QGITile.cpp index 0e00d33729..6d367d8ef4 100644 --- a/src/Mod/TechDraw/Gui/QGITile.cpp +++ b/src/Mod/TechDraw/Gui/QGITile.cpp @@ -42,33 +42,41 @@ #include "Rez.h" #include "DrawGuiUtil.h" #include "QGIView.h" +#include "QGIWeldSymbol.h" #include "QGITile.h" using namespace TechDrawGui; -QGITile::QGITile(TechDraw::DrawTileWeld* feat) : - m_tileFeat(feat), +QGITile::QGITile() : m_textL(QString()), m_textR(QString()), m_textC(QString()), - m_scale(1.0) + m_scale(1.0), + m_row(0), + m_col(0), + m_tailRight(true), + m_altWeld(false) { m_qgSvg = new QGCustomSvg(); - m_qgSvg->setParentItem(this); - m_effect = new QGraphicsColorizeEffect(); + addToGroup(m_qgSvg); + +// m_effect = new QGraphicsColorizeEffect(); + m_qgTextL = new QGCustomText(); - m_qgTextL->setParentItem(this); + addToGroup(m_qgTextL); + m_qgTextR = new QGCustomText(); - m_qgTextR->setParentItem(this); + addToGroup(m_qgTextR); + m_qgTextC = new QGCustomText(); - m_qgTextC->setParentItem(this); + addToGroup(m_qgTextC); m_wide = getSymbolWidth(); - m_high = getFontSize(); + m_high = prefFontSize(); m_textL = QString(); m_textR = QString(); m_textC = QString(); - m_fontName = getTextFont(); + m_fontName = prefTextFont(); m_font = QFont(m_fontName); #if PY_MAJOR_VERSION < 3 @@ -87,6 +95,11 @@ QGITile::QGITile(TechDraw::DrawTileWeld* feat) : m_colCurrent = m_colNormal; } +QGITile::~QGITile(void) +{ + +} + QVariant QGITile::itemChange(GraphicsItemChange change, const QVariant &value) { // Base::Console().Message("QGIT::itemChange(%d)\n", change); @@ -106,13 +119,11 @@ void QGITile::draw(void) double textWidthL = m_qgTextL->boundingRect().width(); double textWidthR = m_qgTextR->boundingRect().width(); double totalWidth = m_wide + textWidthL + textWidthR; - int row = m_tileFeat->TileRow.getValue(); - int col = m_tileFeat->TileColumn.getValue(); - if (row == 0) { //arrowSide + if (m_row == 0) { //arrowSide double x = m_origin.x(); double y = m_origin.y() - (m_high * 0.5); //inverted y!! setPos(x,y); - } else if (row == -1) { //otherSide + } else if (m_row == -1) { //otherSide if (getAltWeld()) { if (isTailRight()) { double x = m_origin.x() + (0.5 * totalWidth); //move to right 1/2 tile width @@ -129,8 +140,8 @@ void QGITile::draw(void) setPos(x,y); } } else { - double x = m_origin.x() + col * totalWidth; - double y = m_origin.y() - (row * m_high) - (m_high * 0.5); //inverted y!! + double x = m_origin.x() + m_col * totalWidth; + double y = m_origin.y() - (m_row * m_high) - (m_high * 0.5); //inverted y!! setPos(x,y); } } @@ -138,14 +149,14 @@ void QGITile::draw(void) void QGITile::makeSymbol(void) { // Base::Console().Message("QGIT::makeSymbol()\n"); - m_effect->setColor(m_colCurrent); +// m_effect->setColor(m_colCurrent); if (m_svgPath.isEmpty()) { Base::Console().Warning("QGIT::makeSymbol - no symbol file set\n"); return; } - m_qgSvg->setGraphicsEffect(m_effect); +// m_qgSvg->setGraphicsEffect(m_effect); QFileInfo fi(m_svgPath); if (fi.isReadable()) { @@ -166,18 +177,15 @@ void QGITile::makeSymbol(void) Base::Console().Error("QGIT::makeSymbol - file: **%s** is not readable\n",qPrintable(m_svgPath)); return; } - } void QGITile::makeText(void) { // Base::Console().Message("QGIT::makeText()\n"); prepareGeometryChange(); - m_font.setPixelSize(getFontSize()); + m_font.setPixelSize(prefFontSize()); double verticalFudge = 0.10; - int row = m_tileFeat->TileRow.getValue(); - //(0, 0) is 1/2 up (above line symbol)! m_qgTextL->setFont(m_font); m_qgTextL->setPlainText(m_textL); @@ -188,7 +196,7 @@ void QGITile::makeText(void) double textHeightL = m_qgTextL->boundingRect().height(); double vOffset = 0.0; - if (row < 0) { // below line + if (m_row < 0) { // below line vOffset = textHeightL * verticalFudge; } else { vOffset = 0.0; @@ -202,7 +210,7 @@ void QGITile::makeText(void) charWidth = textWidth / m_textR.size(); hMargin = (m_wide / 2.0) + (charWidth / 2.0); double textHeightR = m_qgTextR->boundingRect().height(); - if (row < 0) { // below line + if (m_row < 0) { // below line vOffset = textHeightR * verticalFudge; } else { vOffset = 0.0; @@ -214,7 +222,7 @@ void QGITile::makeText(void) m_qgTextC->setColor(m_colCurrent); double textHeightC = m_qgTextC->boundingRect().height(); textHeightC = textHeightC; - if (row < 0) { // below line + if (m_row < 0) { // below line vOffset = m_high * (1 + verticalFudge); } else { vOffset = -0.5 * (m_high + textHeightC); @@ -222,10 +230,11 @@ void QGITile::makeText(void) m_qgTextC->centerAt(0.0, vOffset); } -void QGITile::setTilePosition(QPointF org) - +void QGITile::setTilePosition(QPointF org, int r, int c) { m_origin = org; + m_row = r; + m_col = c; } void QGITile::setTileScale(double s) @@ -266,7 +275,7 @@ void QGITile::setSymbolFile(std::string s) void QGITile::setPrettyNormal() { m_colCurrent = m_colNormal; - m_effect->setColor(m_colNormal); +// m_effect->setColor(m_colNormal); m_qgTextL->setColor(m_colNormal); m_qgTextR->setColor(m_colNormal); m_qgTextC->setColor(m_colNormal); @@ -277,7 +286,7 @@ void QGITile::setPrettyNormal() { void QGITile::setPrettyPre() { m_colCurrent = prefPreColor(); - m_effect->setColor(m_colCurrent); +// m_effect->setColor(m_colCurrent); m_qgTextL->setColor(m_colCurrent); m_qgTextR->setColor(m_colCurrent); m_qgTextC->setColor(m_colCurrent); @@ -288,7 +297,7 @@ void QGITile::setPrettyPre() { void QGITile::setPrettySel() { m_colCurrent = prefSelectColor(); - m_effect->setColor(m_colCurrent); +// m_effect->setColor(m_colCurrent); m_qgTextL->setColor(m_colCurrent); m_qgTextR->setColor(m_colCurrent); m_qgTextC->setColor(m_colCurrent); @@ -298,26 +307,12 @@ void QGITile::setPrettySel() { bool QGITile::isTailRight(void) { - bool right = false; - App::DocumentObject* obj = m_tileFeat->TileParent.getValue(); - TechDraw::DrawWeldSymbol* realParent = dynamic_cast(obj); - if (realParent != nullptr) { - right = realParent->isTailRightSide(); - } - return right; + return m_tailRight; } bool QGITile::getAltWeld(void) { - bool alt = false; - App::DocumentObject* obj = m_tileFeat->TileParent.getValue(); - TechDraw::DrawWeldSymbol* realParent = dynamic_cast(obj); - if (realParent != nullptr) { - alt = realParent->AlternatingWeld.getValue(); - } else { - Base::Console().Message("QGIT::getAltWeld - real parent not found!\n"); - } - return alt; + return m_altWeld; } //TODO: this is Pen, not Brush. sb Brush to colour background @@ -362,7 +357,7 @@ double QGITile::getSymbolFactor(void) const return s; } -double QGITile::getFontSize(void) const +double QGITile::prefFontSize(void) const { Base::Reference hGrp = App::GetApplication().GetUserParameter(). GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions"); @@ -374,14 +369,14 @@ double QGITile::getFontSize(void) const //factor to scale symbol to match font size double QGITile::scaleToFont(void) const { - double fpx = getFontSize(); + double fpx = prefFontSize(); double spx = getSymbolHeight(); double factor = getSymbolFactor(); double sf = (fpx / spx) * factor; return sf; } -QString QGITile::getTextFont(void) const +QString QGITile::prefTextFont(void) const { Base::Reference hGrp = App::GetApplication().GetUserParameter(). GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Labels"); diff --git a/src/Mod/TechDraw/Gui/QGITile.h b/src/Mod/TechDraw/Gui/QGITile.h index 0a67d9247c..43887a918b 100644 --- a/src/Mod/TechDraw/Gui/QGITile.h +++ b/src/Mod/TechDraw/Gui/QGITile.h @@ -47,12 +47,13 @@ class DrawTileWeld; namespace TechDrawGui { +class QGIWeldSymbol; class TechDrawGuiExport QGITile : public QGIDecoration { public: - explicit QGITile(TechDraw::DrawTileWeld* tileFeat); - ~QGITile(void) {} + explicit QGITile(); + ~QGITile(void); enum {Type = QGraphicsItem::UserType + 325}; int type(void) const { return Type;} @@ -65,11 +66,12 @@ public: void setTileTextCenter(std::string s); void setFont(QFont f, double fsize); void setSymbolFile(std::string s); - void setTilePosition(QPointF org); + void setTilePosition(QPointF org, int r, int c); void setTileScale(double s); - virtual void draw(void); + void setTailRight(bool b) { m_tailRight = b; } + void setAltWeld(bool b) { m_altWeld = b; } bool isTailRight(void); - + virtual void draw(void); protected: virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); @@ -82,8 +84,8 @@ protected: double getSymbolWidth(void) const; double getSymbolHeight(void) const; double getSymbolFactor(void) const; - QString getTextFont(void) const; - double getFontSize(void) const; + QString prefTextFont(void) const; + double prefFontSize(void) const; double scaleToFont(void) const; void makeSymbol(void); void makeText(void); @@ -91,7 +93,6 @@ protected: bool getAltWeld(void); private: - TechDraw::DrawTileWeld* m_tileFeat; QGCustomText* m_qgTextL; QGCustomText* m_qgTextR; QGCustomText* m_qgTextC; @@ -107,6 +108,10 @@ private: double m_wide; double m_high; double m_scale; + int m_row; + int m_col; + bool m_tailRight; + bool m_altWeld; }; } diff --git a/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp b/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp index ea436f3151..ac40646062 100644 --- a/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp +++ b/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp @@ -74,13 +74,14 @@ using namespace TechDrawGui; //************************************************************** -QGIWeldSymbol::QGIWeldSymbol(QGILeaderLine* myParent, - TechDraw::DrawWeldSymbol* weld) : - m_weldFeat(weld), +QGIWeldSymbol::QGIWeldSymbol(QGILeaderLine* myParent) : + m_weldFeat(nullptr), + m_leadFeat(nullptr), + m_arrowFeat(nullptr), + m_otherFeat(nullptr), m_qgLead(myParent), m_blockDraw(false) { - #if PY_MAJOR_VERSION < 3 setHandlesChildEvents(true); //qt4 deprecated in qt5 #else @@ -91,7 +92,6 @@ QGIWeldSymbol::QGIWeldSymbol(QGILeaderLine* myParent, setCacheMode(QGraphicsItem::NoCache); setParentItem(m_qgLead); - setViewFeature(weld); m_leadFeat = m_qgLead->getFeature(); setZValue(ZVALUE::DIMENSION); @@ -101,11 +101,24 @@ QGIWeldSymbol::QGIWeldSymbol(QGILeaderLine* myParent, m_tailText->setPos(0.0, 0.0); //avoid bRect issues m_allAround = new QGIVertex(-1); - m_allAround->setParentItem(this); - m_fieldFlag = new QGIPrimPath(); - m_fieldFlag->setParentItem(this); + addToGroup(m_allAround); + m_allAround->setAcceptHoverEvents(false); + m_allAround->setFlag(QGraphicsItem::ItemIsSelectable, false); + m_allAround->setFlag(QGraphicsItem::ItemIsMovable, false); + m_allAround->setFlag(QGraphicsItem::ItemSendsScenePositionChanges, false); + m_allAround->setFlag(QGraphicsItem::ItemSendsGeometryChanges,true); + m_allAround->setFlag(QGraphicsItem::ItemStacksBehindParent, true); - m_colCurrent = getNormalColor(); //preference + m_fieldFlag = new QGIPrimPath(); + addToGroup(m_fieldFlag); + m_fieldFlag->setAcceptHoverEvents(false); + m_fieldFlag->setFlag(QGraphicsItem::ItemIsSelectable, false); + m_fieldFlag->setFlag(QGraphicsItem::ItemIsMovable, false); + m_fieldFlag->setFlag(QGraphicsItem::ItemSendsScenePositionChanges, false); + m_fieldFlag->setFlag(QGraphicsItem::ItemSendsGeometryChanges,true); + m_fieldFlag->setFlag(QGraphicsItem::ItemStacksBehindParent, true); + + m_colCurrent = prefNormalColor(); m_colSetting = m_colCurrent; } @@ -126,104 +139,90 @@ QVariant QGIWeldSymbol::itemChange(GraphicsItemChange change, const QVariant &va void QGIWeldSymbol::updateView(bool update) { -// Base::Console().Message("QGIWS::updateView() %s\n",m_weldFeat->getNameInDocument()); +// Base::Console().Message("QGIWS::updateView()\n"); Q_UNUSED(update); - if ( m_weldFeat == nullptr ) { + auto viewWeld( dynamic_cast(getViewObject()) ); + if( viewWeld == nullptr ) { + return; + } + + if ( getFeature() == nullptr ) { Base::Console().Warning("QGIWS::updateView - no feature!\n"); return; } + draw(); } void QGIWeldSymbol::draw() { -// Base::Console().Message("QGIWS::draw()- %s\n", m_weldFeat->getNameInDocument()); +// Base::Console().Message("QGIWS::draw()- %s\n", getFeature()->getNameInDocument()); if (!isVisible()) { return; } + getTileFeats(); - removeDecorations(); + removeQGITiles(); - std::vector tiles = m_weldFeat->getTiles(); - - TechDraw::DrawTileWeld* arrowTile = nullptr; - TechDraw::DrawTileWeld* otherTile = nullptr; - if (!tiles.empty()) { - TechDraw::DrawTileWeld* tempTile = tiles.at(0); - if (tempTile->TileRow.getValue() == 0) { - arrowTile = tempTile; - } else { - otherTile = tempTile; - } - } - if (tiles.size() > 1) { - TechDraw::DrawTileWeld* tempTile = tiles.at(1); - if (tempTile->TileRow.getValue() == 0) { - arrowTile = tempTile; - } else { - otherTile = tempTile; - } + if (m_arrowFeat != nullptr) { + drawTile(m_arrowFeat); } - if (arrowTile != nullptr) { - QGITile* qt = new QGITile(arrowTile); - m_arrowTile = qt; - qt->setParentItem(this); - drawTile(arrowTile, m_arrowTile); + if (m_otherFeat != nullptr) { + drawTile(m_otherFeat); } - if (otherTile != nullptr) { - QGITile* qt = new QGITile(otherTile); - m_otherTile = qt; - qt->setParentItem(this); - drawTile(otherTile, m_otherTile); - } + drawAllAround(); - if (m_weldFeat->AllAround.getValue()) { - drawAllAround(); - } - - if (m_weldFeat->FieldWeld.getValue()) { - drawFieldFlag(); - } + drawFieldFlag(); drawTailText(); } -void QGIWeldSymbol::drawTile(TechDraw::DrawTileWeld* dtw, - QGITile* tile) +void QGIWeldSymbol::drawTile(TechDraw::DrawTileWeld* tileFeat) { -// Base::Console().Message("QGIWS::drawTile()\n"); +// Base::Console().Message("QGIWS::drawTile() - tileFeat: %X\n", tileFeat); + if (tileFeat == nullptr) { + Base::Console().Message("QGIWS::drawTile - tile is null\n"); + return; + } + double featScale = m_leadFeat->getScale(); - std::string tileTextL = dtw->LeftText.getValue(); - std::string tileTextR = dtw->RightText.getValue(); - std::string tileTextC = dtw->CenterText.getValue(); - tile->setSymbolFile(dtw->SymbolFile.getValue()); - tile->setTileScale(featScale); - + std::string tileTextL = tileFeat->LeftText.getValue(); + std::string tileTextR = tileFeat->RightText.getValue(); + std::string tileTextC = tileFeat->CenterText.getValue(); + std::string symbolFile = tileFeat->SymbolFile.getValue(); + int row = tileFeat->TileRow.getValue(); + int col = tileFeat->TileColumn.getValue(); + + QGITile* tile = new QGITile(); + addToGroup(tile); + QPointF org = getTileOrigin(); - tile->setTilePosition(org); + tile->setTilePosition(org, row, col); tile->setColor(getCurrentColor()); tile->setTileTextLeft(tileTextL); tile->setTileTextRight(tileTextR); tile->setTileTextCenter(tileTextC); + tile->setSymbolFile(symbolFile); tile->setZValue(ZVALUE::DIMENSION); + tile->setTileScale(featScale); + tile->setTailRight(m_weldFeat->isTailRightSide()); + tile->setAltWeld(m_weldFeat->AlternatingWeld.getValue()); + tile->draw(); } void QGIWeldSymbol::drawAllAround(void) { // Base::Console().Message("QGIWS::drawAllAround()\n"); - m_allAround = new QGIVertex(-1); - m_allAround->setParentItem(this); - - m_allAround->setAcceptHoverEvents(false); - m_allAround->setFlag(QGraphicsItem::ItemIsSelectable, false); - m_allAround->setFlag(QGraphicsItem::ItemIsMovable, false); - m_allAround->setFlag(QGraphicsItem::ItemSendsScenePositionChanges, false); - m_allAround->setFlag(QGraphicsItem::ItemSendsGeometryChanges,true); - m_allAround->setFlag(QGraphicsItem::ItemStacksBehindParent, true); + if (getFeature()->AllAround.getValue()) { + m_allAround->show(); + } else { + m_allAround->hide(); + return; + } m_allAround->setNormalColor(getCurrentColor()); @@ -242,7 +241,7 @@ void QGIWeldSymbol::drawTailText(void) // Base::Console().Message("QGIWS::drawTailText()\n"); QPointF textPos = getTailPoint(); m_tailText->setPos(textPos); //avoid messing up brect with empty item at 0,0 - std::string tText = m_weldFeat->TailText.getValue(); + std::string tText = getFeature()->TailText.getValue(); if (tText.empty()) { m_tailText->hide(); return; @@ -261,7 +260,7 @@ void QGIWeldSymbol::drawTailText(void) double textWidth = m_tailText->boundingRect().width(); double charWidth = textWidth / tText.size(); - double hMargin = charWidth + getPrefArrowSize(); + double hMargin = charWidth + prefArrowSize(); if (getFeature()->isTailRightSide()) { m_tailText->justifyLeftAt(textPos.x() + hMargin, textPos.y(), true); @@ -273,6 +272,12 @@ void QGIWeldSymbol::drawTailText(void) void QGIWeldSymbol::drawFieldFlag() { // Base::Console().Message("QGIWS::drawFieldFlag()\n"); + if (getFeature()->FieldWeld.getValue()) { + m_fieldFlag->show(); + } else { + m_fieldFlag->hide(); + return; + } std::vector flagPoints = { QPointF(0.0, 0.0), QPointF(0.0, -3.0), QPointF(-2.0, -2.5), @@ -287,16 +292,6 @@ void QGIWeldSymbol::drawFieldFlag() path.lineTo(flagPoints.at(i) * scale); } - m_fieldFlag = new QGIPrimPath(); - m_fieldFlag->setParentItem(this); - - m_fieldFlag->setAcceptHoverEvents(false); - m_fieldFlag->setFlag(QGraphicsItem::ItemIsSelectable, false); - m_fieldFlag->setFlag(QGraphicsItem::ItemIsMovable, false); - m_fieldFlag->setFlag(QGraphicsItem::ItemSendsScenePositionChanges, false); - m_fieldFlag->setFlag(QGraphicsItem::ItemSendsGeometryChanges,true); - m_fieldFlag->setFlag(QGraphicsItem::ItemStacksBehindParent, true); - m_fieldFlag->setNormalColor(getCurrentColor()); //penColor double width = m_qgLead->getLineWidth(); @@ -312,26 +307,57 @@ void QGIWeldSymbol::drawFieldFlag() m_fieldFlag->setPos(fieldFlagPos); } -void QGIWeldSymbol::removeDecorations() +void QGIWeldSymbol::getTileFeats(void) { -// Base::Console().Message("QGIWS::removeDecorations()\n"); + std::vector tiles = getFeature()->getTiles(); + m_arrowFeat = nullptr; + m_otherFeat = nullptr; + + if (!tiles.empty()) { + TechDraw::DrawTileWeld* tempTile = tiles.at(0); + if (tempTile->TileRow.getValue() == 0) { + m_arrowFeat = tempTile; + } else { + m_otherFeat = tempTile; + } + } + if (tiles.size() > 1) { + TechDraw::DrawTileWeld* tempTile = tiles.at(1); + if (tempTile->TileRow.getValue() == 0) { + m_arrowFeat = tempTile; + } else { + m_otherFeat = tempTile; + } + } +} + +void QGIWeldSymbol::removeQGITiles(void) +{ + std::vector tiles = getQGITiles(); + for (auto t: tiles) { + QList tChildren = t->childItems(); + for (auto tc: tChildren) { + t->removeFromGroup(tc); + scene()->removeItem(tc); + //tc gets deleted when QGIWS gets deleted + } + removeFromGroup(t); + scene()->removeItem(t); + delete t; + } +} + +std::vector QGIWeldSymbol::getQGITiles(void) +{ + std::vector result; QList children = childItems(); for (auto& c:children) { QGITile* tile = dynamic_cast(c); - QGIPrimPath* prim = dynamic_cast(c); //allAround, fieldFlag if (tile) { - scene()->removeItem(tile); - delete tile; - } else if (prim) { - scene()->removeItem(prim); - delete tile; + result.push_back(tile); } - } - m_arrowTile = nullptr; - m_otherTile = nullptr; - -// std::vector noTiles; -// m_tiles = noTiles; + } + return result; } void QGIWeldSymbol::hoverEnterEvent(QGraphicsSceneHoverEvent *event) @@ -368,19 +394,11 @@ void QGIWeldSymbol::drawBorder() void QGIWeldSymbol::setPrettyNormal() { -// for (auto t: m_tiles) { -// t->setColor(m_colNormal); -// t->draw(); -// } - if (m_arrowTile != nullptr) { - m_arrowTile->setColor(m_colNormal); - m_arrowTile->draw(); + std::vector tiles = getQGITiles(); + for (auto t: tiles) { + t->setColor(m_colNormal); + t->draw(); } - if (m_otherTile != nullptr) { - m_otherTile->setColor(m_colNormal); - m_otherTile->draw(); - } - m_colCurrent = m_colNormal; m_fieldFlag->setNormalColor(m_colCurrent); m_fieldFlag->setFillColor(m_colCurrent); @@ -393,19 +411,12 @@ void QGIWeldSymbol::setPrettyNormal() void QGIWeldSymbol::setPrettyPre() { -// Base::Console().Message("QGIWS::setPrettyPre()\n"); -// for (auto t: m_tiles) { -// t->setColor(getPreColor()); -// t->draw(); -// } - if (m_arrowTile != nullptr) { - m_arrowTile->setColor(getPreColor()); - m_arrowTile->draw(); - } - if (m_otherTile != nullptr) { - m_otherTile->setColor(getPreColor()); - m_otherTile->draw(); + std::vector tiles = getQGITiles(); + for (auto t: tiles) { + t->setColor(getPreColor()); + t->draw(); } + m_colCurrent = getPreColor(); m_fieldFlag->setNormalColor(getPreColor()); m_fieldFlag->setFillColor(getPreColor()); @@ -418,19 +429,12 @@ void QGIWeldSymbol::setPrettyPre() void QGIWeldSymbol::setPrettySel() { -// Base::Console().Message("QGIWS::setPrettySel()\n"); -// for (auto t: m_tiles) { -// t->setColor(getSelectColor()); -// t->draw(); -// } - if (m_arrowTile != nullptr) { - m_arrowTile->setColor(getSelectColor()); - m_arrowTile->draw(); - } - if (m_otherTile != nullptr) { - m_otherTile->setColor(getSelectColor()); - m_otherTile->draw(); + std::vector tiles = getQGITiles(); + for (auto t: tiles) { + t->setColor(getSelectColor()); + t->draw(); } + m_colCurrent = getSelectColor(); m_fieldFlag->setNormalColor(getSelectColor()); m_fieldFlag->setFillColor(getSelectColor()); @@ -462,26 +466,20 @@ QPointF QGIWeldSymbol::getTailPoint(void) return result; } -//bool QGIWeldSymbol::isTailRightSide() -//{ -// bool result = true; -// Base::Vector3d tail = m_leadFeat->getTailPoint(); -// Base::Vector3d kink = m_leadFeat->getKinkPoint(); -// if (tail.x < kink.x) { //tail is to left -// result = false; -// } -// return result; -//} +void QGIWeldSymbol::setFeature(TechDraw::DrawWeldSymbol* feat) +{ +// Base::Console().Message("QGIWS::setFeature(%s)\n", feat->getNameInDocument()); + m_weldFeat = feat; + m_weldFeatName = feat->getNameInDocument(); +} TechDraw::DrawWeldSymbol* QGIWeldSymbol::getFeature(void) { - TechDraw::DrawWeldSymbol* result = - static_cast(getViewObject()); - return result; + return m_weldFeat; } //preference -QColor QGIWeldSymbol::getNormalColor() +QColor QGIWeldSymbol::prefNormalColor() { Base::Reference hGrp = App::GetApplication().GetUserParameter() .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/LeaderLines"); @@ -491,7 +489,7 @@ QColor QGIWeldSymbol::getNormalColor() return m_colNormal; } -double QGIWeldSymbol::getPrefArrowSize() +double QGIWeldSymbol::prefArrowSize() { Base::Reference hGrp = App::GetApplication().GetUserParameter(). GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Dimensions"); diff --git a/src/Mod/TechDraw/Gui/QGIWeldSymbol.h b/src/Mod/TechDraw/Gui/QGIWeldSymbol.h index 7b30becd6f..2b38a08404 100644 --- a/src/Mod/TechDraw/Gui/QGIWeldSymbol.h +++ b/src/Mod/TechDraw/Gui/QGIWeldSymbol.h @@ -36,9 +36,13 @@ #include #include "QGIView.h" +namespace App { +class Document; +} + namespace TechDraw { class DrawWeldSymbol; -class DrawWeldSymbol; +class DrawTileWeld; class DrawView; } @@ -48,6 +52,7 @@ class QGIPrimPath; class QGITile; class QGIVertex; class QGCustomText; +class QGILeaderLine; //******************************************************************* @@ -58,8 +63,7 @@ class TechDrawGuiExport QGIWeldSymbol : public QGIView public: enum {Type = QGraphicsItem::UserType + 340}; - explicit QGIWeldSymbol(QGILeaderLine* myParent = nullptr, - TechDraw::DrawWeldSymbol* lead = nullptr); + explicit QGIWeldSymbol(QGILeaderLine* myParent = nullptr); ~QGIWeldSymbol() = default; int type() const override { return Type;} @@ -74,6 +78,8 @@ public: virtual void updateView(bool update = false) override; virtual TechDraw::DrawWeldSymbol* getFeature(void); + virtual void setFeature(TechDraw::DrawWeldSymbol* feat); + QPointF getTileOrigin(void); QPointF getKinkPoint(void); QPointF getTailPoint(void); @@ -82,6 +88,8 @@ public: virtual void setPrettySel(); virtual void setPrettyPre(); + void getTileFeats(void); + protected: virtual QVariant itemChange( GraphicsItemChange change, const QVariant &value ) override; @@ -89,23 +97,26 @@ protected: virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override; virtual void draw() override; - void drawTile(TechDraw::DrawTileWeld* dtw, - QGITile* tile); + void drawTile(TechDraw::DrawTileWeld* tileFeat); void drawAllAround(void); void drawTailText(void); void drawFieldFlag(); - void removeDecorations(); protected: - virtual QColor getNormalColor() override; - double getPrefArrowSize(); + void removeQGITiles(void); + std::vector getQGITiles(void); + + virtual QColor prefNormalColor(); + double prefArrowSize(); TechDraw::DrawWeldSymbol* m_weldFeat; TechDraw::DrawLeaderLine* m_leadFeat; + TechDraw::DrawTileWeld* m_arrowFeat; + TechDraw::DrawTileWeld* m_otherFeat; + std::string m_arrowName; + std::string m_otherName; QGILeaderLine* m_qgLead; - QGITile* m_arrowTile; - QGITile* m_otherTile; QGCustomText* m_tailText; QGIPrimPath* m_fieldFlag; QGIVertex* m_allAround; @@ -113,6 +124,8 @@ protected: QFont m_font; bool m_blockDraw; //prevent redraws while updating. + + std::string m_weldFeatName; }; } diff --git a/src/Mod/TechDraw/Gui/QGVPage.cpp b/src/Mod/TechDraw/Gui/QGVPage.cpp index 3cabcef82d..e2c77e2043 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.cpp +++ b/src/Mod/TechDraw/Gui/QGVPage.cpp @@ -76,6 +76,8 @@ #include #include #include +#include +#include #include #include "Rez.h" @@ -98,6 +100,7 @@ #include "QGILeaderLine.h" #include "QGIRichAnno.h" #include "QGIWeldSymbol.h" +#include "QGITile.h" #include "ZVALUE.h" #include "ViewProviderPage.h" @@ -114,8 +117,6 @@ QGVPage::QGVPage(ViewProviderPage *vp, QGraphicsScene* s, QWidget *parent) m_renderer(Native), drawBkg(true), m_vpPage(0) -// , -// m_borderState(true) { assert(vp); m_vpPage = vp; @@ -557,19 +558,21 @@ QGIView * QGVPage::addWeldSymbol(TechDraw::DrawWeldSymbol* weld) if (parentObj != nullptr) { parentDV = dynamic_cast(parentObj); } else { - Base::Console().Message("QGVP::addWeldSymbol - no parent doc obj\n"); +// Base::Console().Message("QGVP::addWeldSymbol - no parent doc obj\n"); } if (parentDV != nullptr) { QGIView* parentQV = findQViewForDocObj(parentObj); QGILeaderLine* leadParent = dynamic_cast(parentQV); if (leadParent != nullptr) { - weldGroup = new QGIWeldSymbol(leadParent, weld); + weldGroup = new QGIWeldSymbol(leadParent); + weldGroup->setFeature(weld); //for QGIWS + weldGroup->setViewFeature(weld); //for QGIV weldGroup->updateView(true); } else { - Base::Console().Message("QGVP::addWeldSymbol - no parent QGILL\n"); + Base::Console().Error("QGVP::addWeldSymbol - no parent QGILL\n"); } } else { - Base::Console().Message("QGVP::addWeldSymbol - parent is not DV!\n"); + Base::Console().Error("QGVP::addWeldSymbol - parent is not DV!\n"); } return weldGroup; } @@ -735,8 +738,16 @@ void QGVPage::refreshViews(void) { // Base::Console().Message("QGVP::refreshViews()\n"); QList list = scene()->items(); - for (QList::iterator it = list.begin(); it != list.end(); ++it) { - QGIView *itemView = dynamic_cast(*it); + QList qgiv; + //find only QGIV's + for (auto q: list) { + QString tileFamily = QString::fromUtf8("QGIV"); + if (tileFamily == q->data(0).toString()) { + qgiv.push_back(q); + } + } + for (auto q: qgiv) { + QGIView *itemView = dynamic_cast(q); if(itemView) { itemView->updateView(true); } diff --git a/src/Mod/TechDraw/Gui/QGVPage.h b/src/Mod/TechDraw/Gui/QGVPage.h index 65f350730f..923abefcb0 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.h +++ b/src/Mod/TechDraw/Gui/QGVPage.h @@ -57,6 +57,7 @@ class ViewProviderPage; class QGIViewBalloon; class QGILeaderLine; class QGIRichAnno; +class QGITile; class TechDrawGuiExport QGVPage : public QGraphicsView { @@ -95,7 +96,6 @@ public: void addDimToParent(QGIViewDimension* dim, QGIView* parent); void addLeaderToParent(QGILeaderLine* lead, QGIView* parent); -// const std::vector & getViews() const { return views; } //only used in MDIVP std::vector getViews() const; int addQView(QGIView * view); @@ -103,7 +103,6 @@ public: int removeQViewByName(const char* name); void removeQViewFromScene(QGIView *view); - //void setViews(const std::vector &view) {views = view; } void setPageTemplate(TechDraw::DrawTemplate *pageTemplate); QGITemplate * getTemplate() const; @@ -119,8 +118,6 @@ public: void saveSvg(QString filename); void postProcessXml(QTemporaryFile& tempFile, QString filename, QString pagename); -/* int balloonIndex;*/ - public Q_SLOTS: void setHighQualityAntialiasing(bool highQualityAntialiasing); @@ -156,7 +153,6 @@ private: double m_zoomIncrement; int m_reversePan; int m_reverseScroll; -/* bool m_borderState;*/ QLabel *balloonCursor; QPoint balloonCursorPos; void cancelBalloonPlacing(void); diff --git a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp index 369098f957..7ac76ce6af 100644 --- a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp +++ b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp @@ -417,7 +417,6 @@ void TaskWeldingSymbol::collectOtherData(void) TechDraw::DrawWeldSymbol* TaskWeldingSymbol::createWeldingSymbol(void) { // Base::Console().Message("TWS::createWeldingSymbol()\n"); - Gui::Command::openCommand("Create WeldSymbol"); std::string symbolName = m_leadFeat->getDocument()->getUniqueObjectName("DrawWeldSymbol"); std::string symbolType = "TechDraw::DrawWeldSymbol"; @@ -458,8 +457,6 @@ TechDraw::DrawWeldSymbol* TaskWeldingSymbol::createWeldingSymbol(void) throw Base::RuntimeError("TaskWeldingSymbol - new symbol object not found"); } - Gui::Command::updateActive(); - Gui::Command::commitCommand(); return newSym; } @@ -556,7 +553,7 @@ std::vector TaskWeldingSymbol::createTiles(void) std::vector TaskWeldingSymbol::updateTiles(void) { -// Base::Console().Message("TWS::updateTiles()\n"); + Base::Console().Message("TWS::updateTiles()\n"); std::vector tileFeats; std::string tileType("TechDraw::DrawTileWeld"); std::string tileName; @@ -566,7 +563,7 @@ std::vector TaskWeldingSymbol::updateTiles(void) if (m_arrowIn != nullptr) { tileName = m_arrowIn->getNameInDocument(); } - if (m_arrowIn == nullptr) { + if (m_arrowIn == nullptr) { // this should never happen on an update! tileName = m_leadFeat->getDocument()->getUniqueObjectName("DrawTileWeld"); Command::doCommand(Command::Doc,"App.activeDocument().addObject('%s','%s')", tileType.c_str(),tileName.c_str()); @@ -606,7 +603,7 @@ std::vector TaskWeldingSymbol::updateTiles(void) tileName = m_otherIn->getNameInDocument(); } - if ( (m_otherIn == nullptr) && + if ( (m_otherIn == nullptr) && //m_otherIn can be nullptr if otherside added in edit session. (m_otherOut.toBeSaved) ) { tileName = m_leadFeat->getDocument()->getUniqueObjectName("DrawTileWeld"); Command::doCommand(Command::Doc,"App.activeDocument().addObject('%s','%s')", @@ -675,15 +672,19 @@ bool TaskWeldingSymbol::accept() { // Base::Console().Message("TWS::accept()\n"); if (m_createMode) { + Gui::Command::openCommand("Create WeldSymbol"); m_weldFeat = createWeldingSymbol(); std::vector tileFeats = createTiles(); for (auto& obj: tileFeats) { TechDraw::DrawTileWeld* tile = dynamic_cast(obj); tile->TileParent.setValue(m_weldFeat); } + Gui::Command::updateActive(); + Gui::Command::commitCommand(); m_weldFeat->recomputeFeature(); // m_weldFeat->requestPaint(); //not a dv! } else { + Gui::Command::openCommand("Edit WeldSymbol"); try { updateWeldingSymbol(); std::vector tileFeats = updateTiles(); @@ -691,7 +692,9 @@ bool TaskWeldingSymbol::accept() TechDraw::DrawTileWeld* tile = dynamic_cast(obj); tile->TileParent.setValue(m_weldFeat); } + for (auto name: m_toRemove) { + //QGIV is removed from scene by MDIVP/QGVP on objectDelete Command::doCommand(Command::Doc, "App.activeDocument().removeObject('%s')", name.c_str()); } @@ -701,6 +704,8 @@ bool TaskWeldingSymbol::accept() Base::Console().Error("TWS::accept - failed to update symbol\n"); } + Gui::Command::updateActive(); + Gui::Command::commitCommand(); m_weldFeat->recomputeFeature(); // m_weldFeat->requestPaint(); //not a dv! } From 3c4700d05b4299cc670dfd7a7580d5318b905f29 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Tue, 13 Aug 2019 15:55:57 -0400 Subject: [PATCH 14/19] [TD]fix BRect on empty text items --- src/Mod/TechDraw/Gui/QGCustomSvg.cpp | 3 ++- src/Mod/TechDraw/Gui/QGILeaderLine.cpp | 4 +++- src/Mod/TechDraw/Gui/QGITile.cpp | 18 +++++++++++++----- src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp | 7 ++++++- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/Mod/TechDraw/Gui/QGCustomSvg.cpp b/src/Mod/TechDraw/Gui/QGCustomSvg.cpp index bb9e299f80..46754565d3 100644 --- a/src/Mod/TechDraw/Gui/QGCustomSvg.cpp +++ b/src/Mod/TechDraw/Gui/QGCustomSvg.cpp @@ -76,7 +76,8 @@ void QGCustomSvg::paint ( QPainter * painter, const QStyleOptionGraphicsItem * o QStyleOptionGraphicsItem myOption(*option); myOption.state &= ~QStyle::State_Selected; - //painter->drawRect(boundingRect()); //good for debugging +// painter->setPen(Qt::yellow); +// painter->drawRect(boundingRect()); //good for debugging QGraphicsSvgItem::paint (painter, &myOption, widget); } diff --git a/src/Mod/TechDraw/Gui/QGILeaderLine.cpp b/src/Mod/TechDraw/Gui/QGILeaderLine.cpp index a6589a3f4d..2470dd0b72 100644 --- a/src/Mod/TechDraw/Gui/QGILeaderLine.cpp +++ b/src/Mod/TechDraw/Gui/QGILeaderLine.cpp @@ -95,6 +95,7 @@ QGILeaderLine::QGILeaderLine(QGraphicsItem* myParent, // m_line->setPrettyNormal(); addToGroup(m_line); + m_line->setPos(0.0, 0.0); m_line->setFlag(QGraphicsItem::ItemIsSelectable, false); m_line->setFlag(QGraphicsItem::ItemIsMovable, false); setFlag(QGraphicsItem::ItemSendsScenePositionChanges, false); @@ -102,9 +103,11 @@ QGILeaderLine::QGILeaderLine(QGraphicsItem* myParent, m_arrow1 = new QGIArrow(); addToGroup(m_arrow1); + m_arrow1->setPos(0.0,0.0); m_arrow1->hide(); m_arrow2 = new QGIArrow(); addToGroup(m_arrow2); + m_arrow2->setPos(0.0, 0.0); m_arrow2->hide(); setParentItem(m_parentItem); @@ -128,7 +131,6 @@ QGILeaderLine::QGILeaderLine(QGraphicsItem* myParent, QObject::connect( m_line, SIGNAL(hover(bool)), this , SLOT (hover(bool))); - } QVariant QGILeaderLine::itemChange(GraphicsItemChange change, const QVariant &value) diff --git a/src/Mod/TechDraw/Gui/QGITile.cpp b/src/Mod/TechDraw/Gui/QGITile.cpp index 6d367d8ef4..08727d00f9 100644 --- a/src/Mod/TechDraw/Gui/QGITile.cpp +++ b/src/Mod/TechDraw/Gui/QGITile.cpp @@ -23,6 +23,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ #include +#include #include #include #include @@ -48,9 +49,9 @@ using namespace TechDrawGui; QGITile::QGITile() : - m_textL(QString()), - m_textR(QString()), - m_textC(QString()), + m_textL(QString::fromUtf8(" ")), + m_textR(QString::fromUtf8(" ")), + m_textC(QString::fromUtf8(" ")), m_scale(1.0), m_row(0), m_col(0), @@ -109,6 +110,7 @@ QVariant QGITile::itemChange(GraphicsItemChange change, const QVariant &value) void QGITile::draw(void) { // Base::Console().Message("QGIT::draw()\n"); + prepareGeometryChange(); m_wide = getSymbolWidth(); m_high = getSymbolHeight() * scaleToFont(); @@ -192,7 +194,10 @@ void QGITile::makeText(void) m_qgTextL->setColor(m_colCurrent); double textWidth = m_qgTextL->boundingRect().width(); double charWidth = textWidth / m_textL.size(); //not good for non-ASCII chars - double hMargin = (m_wide / 2.0) + (charWidth / 2.0); + double hMargin = 1; + if (!m_textL.isEmpty()) { + hMargin = (m_wide / 2.0) + (charWidth / 2.0); + } double textHeightL = m_qgTextL->boundingRect().height(); double vOffset = 0.0; @@ -208,7 +213,10 @@ void QGITile::makeText(void) m_qgTextR->setColor(m_colCurrent); textWidth = m_qgTextR->boundingRect().width(); charWidth = textWidth / m_textR.size(); - hMargin = (m_wide / 2.0) + (charWidth / 2.0); + hMargin = 1; + if (!m_textR.isEmpty()) { + hMargin = (m_wide / 2.0) + (charWidth / 2.0); + } double textHeightR = m_qgTextR->boundingRect().height(); if (m_row < 0) { // below line vOffset = textHeightR * verticalFudge; diff --git a/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp b/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp index ac40646062..c915cf7e83 100644 --- a/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp +++ b/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp @@ -96,12 +96,15 @@ QGIWeldSymbol::QGIWeldSymbol(QGILeaderLine* myParent) : setZValue(ZVALUE::DIMENSION); m_tailText = new QGCustomText(); + m_tailText->setPlainText( + QString::fromUtf8(" ")); addToGroup(m_tailText); m_tailText->hide(); m_tailText->setPos(0.0, 0.0); //avoid bRect issues m_allAround = new QGIVertex(-1); addToGroup(m_allAround); + m_allAround->setPos(0.0, 0.0); m_allAround->setAcceptHoverEvents(false); m_allAround->setFlag(QGraphicsItem::ItemIsSelectable, false); m_allAround->setFlag(QGraphicsItem::ItemIsMovable, false); @@ -111,6 +114,7 @@ QGIWeldSymbol::QGIWeldSymbol(QGILeaderLine* myParent) : m_fieldFlag = new QGIPrimPath(); addToGroup(m_fieldFlag); + m_fieldFlag->setPos(0.0, 0.0); m_fieldFlag->setAcceptHoverEvents(false); m_fieldFlag->setFlag(QGraphicsItem::ItemIsSelectable, false); m_fieldFlag->setFlag(QGraphicsItem::ItemIsMovable, false); @@ -157,6 +161,7 @@ void QGIWeldSymbol::updateView(bool update) void QGIWeldSymbol::draw() { // Base::Console().Message("QGIWS::draw()- %s\n", getFeature()->getNameInDocument()); + if (!isVisible()) { return; } @@ -500,7 +505,7 @@ double QGIWeldSymbol::prefArrowSize() QRectF QGIWeldSymbol::boundingRect() const { - return customChildrenBoundingRect(); + return childrenBoundingRect(); } QPainterPath QGIWeldSymbol::shape() const From 5806fc64b966a547f01708aa3532223df5ccf34c Mon Sep 17 00:00:00 2001 From: wandererfan Date: Tue, 13 Aug 2019 16:12:17 -0400 Subject: [PATCH 15/19] [TD]Restore context menu after leader edit --- src/Mod/TechDraw/Gui/TaskLeaderLine.cpp | 12 ++++++++---- src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Mod/TechDraw/Gui/TaskLeaderLine.cpp b/src/Mod/TechDraw/Gui/TaskLeaderLine.cpp index 021592aa86..2f450a2796 100644 --- a/src/Mod/TechDraw/Gui/TaskLeaderLine.cpp +++ b/src/Mod/TechDraw/Gui/TaskLeaderLine.cpp @@ -123,6 +123,7 @@ TaskLeaderLine::TaskLeaderLine(TechDrawGui::ViewProviderLeader* leadVP) : saveState(); m_trackerMode = QGTracker::TrackerMode::Line; + m_saveContextPolicy = m_mdi->contextMenuPolicy(); } //ctor for creation @@ -165,6 +166,8 @@ TaskLeaderLine::TaskLeaderLine(TechDraw::DrawView* baseFeat, ui->pbCancelEdit->setEnabled(false); m_trackerMode = QGTracker::TrackerMode::Line; + m_saveContextPolicy = m_mdi->contextMenuPolicy(); + } TaskLeaderLine::~TaskLeaderLine() @@ -648,12 +651,12 @@ bool TaskLeaderLine::accept() // removeTracker(); createLeaderFeature(m_trackerPoints); } - m_mdi->setContextMenuPolicy(m_saveContextPolicy); m_trackerMode = QGTracker::TrackerMode::None; removeTracker(); Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); + m_mdi->setContextMenuPolicy(m_saveContextPolicy); return true; } @@ -670,9 +673,6 @@ bool TaskLeaderLine::reject() Gui::Document* doc = Gui::Application::Instance->getDocument(m_basePage->getDocument()); if (!doc) return false; - if (m_mdi != nullptr) { - m_mdi->setContextMenuPolicy(m_saveContextPolicy); - } if (getCreateMode() && (m_lineFeat != nullptr) ) { removeFeature(); @@ -690,6 +690,10 @@ bool TaskLeaderLine::reject() Gui::Command::doCommand(Gui::Command::Gui,"App.activeDocument().recompute()"); Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); + if (m_mdi != nullptr) { + m_mdi->setContextMenuPolicy(m_saveContextPolicy); + } + return false; } diff --git a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp index 7ac76ce6af..6bd525f305 100644 --- a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp +++ b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp @@ -553,7 +553,7 @@ std::vector TaskWeldingSymbol::createTiles(void) std::vector TaskWeldingSymbol::updateTiles(void) { - Base::Console().Message("TWS::updateTiles()\n"); +// Base::Console().Message("TWS::updateTiles()\n"); std::vector tileFeats; std::string tileType("TechDraw::DrawTileWeld"); std::string tileName; From d6fdaefb6840a9653dca19fea90cbdff4c7812e3 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Thu, 22 Aug 2019 18:52:44 -0300 Subject: [PATCH 16/19] Arch: Fixed windows symbol position --- src/Mod/Arch/ArchWindow.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Mod/Arch/ArchWindow.py b/src/Mod/Arch/ArchWindow.py index 883d8ed14e..81c2f8cfd8 100644 --- a/src/Mod/Arch/ArchWindow.py +++ b/src/Mod/Arch/ArchWindow.py @@ -1085,11 +1085,10 @@ class _Window(ArchComponent.Component): e = obj.Base.Shape.Edges[hinge] ev1 = e.Vertexes[0].Point ev2 = e.Vertexes[-1].Point - if (ev2.z - ev1.z) < 0.1**Draft.precision(): - if ev2.y < ev1.y: - ev1,ev2 = ev2,ev1 - elif ev2.z < ev1.z: + # choose the one with lowest z to draw the symbol + if ev2.z < ev1.z: ev1,ev2 = ev2,ev1 + # find the point most distant from the hinge p = None d = 0 for v in shape.Vertexes: @@ -1098,13 +1097,16 @@ class _Window(ArchComponent.Component): d = dist p = v.Point if p: + # bring that point to the level of ev1 if needed chord = p.sub(ev1) enorm = ev2.sub(ev1) proj = DraftVecUtils.project(chord,enorm) v1 = ev1 if proj.Length > 0: - chord = p.sub(ev1.add(proj)) - p = v1.add(chord) + #chord = p.sub(ev1.add(proj)) + #p = v1.add(chord) + p = p.add(proj.negative()) + # calculate symbols v4 = p.add(DraftVecUtils.scale(enorm,0.5)) if omode == 1: # Arc 90 v2 = v1.add(DraftVecUtils.rotate(chord,math.pi/4,enorm)) From 4683c267b8e2c30f0c16f1a981908eeec7110f3f Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 23 Aug 2019 12:51:26 +0200 Subject: [PATCH 17/19] Remove CMakeLists.txt.user from repo --- CMakeLists.txt.user | 827 -------------------------------------------- 1 file changed, 827 deletions(-) delete mode 100644 CMakeLists.txt.user diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user deleted file mode 100644 index 6df35fe60d..0000000000 --- a/CMakeLists.txt.user +++ /dev/null @@ -1,827 +0,0 @@ - - - - - - EnvironmentId - {2bb8d980-59c2-4103-9ad9-f84df3b67da6} - - - ProjectExplorer.Project.ActiveTarget - 1 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - true - false - 0 - true - true - 0 - 8 - true - 1 - true - true - true - false - - - - ProjectExplorer.Project.PluginSettings - - - - ProjectExplorer.Project.Target.0 - - Desktop - Desktop - {6576b0bd-ff13-47bd-97c2-c8159848c669} - 0 - 0 - 0 - - - /home/huxster/Target/freecad-qtcdb-build - - - - - all - - true - CMake Build - - CMakeProjectManager.MakeStep - - 1 - Build - - ProjectExplorer.BuildSteps.Build - - - - - - all - - true - CMake Build - - CMakeProjectManager.MakeStep - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Default - Default - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=Debug - - /home/huxster/Source/build-FreeCAD-src-Desktop-Debug - - - - - all - - true - CMake Build - - CMakeProjectManager.MakeStep - - 1 - Build - - ProjectExplorer.BuildSteps.Build - - - - - - all - - true - CMake Build - - CMakeProjectManager.MakeStep - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - Debug - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=Release - - /home/huxster/Source/build-FreeCAD-src-Desktop-Release - - - - - all - - true - CMake Build - - CMakeProjectManager.MakeStep - - 1 - Build - - ProjectExplorer.BuildSteps.Build - - - - - - all - - true - CMake Build - - CMakeProjectManager.MakeStep - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - Release - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=RelWithDebInfo - - /home/huxster/Source/build-FreeCAD-src-Desktop-Release with Debug Information - - - - - all - - true - CMake Build - - CMakeProjectManager.MakeStep - - 1 - Build - - ProjectExplorer.BuildSteps.Build - - - - - - all - - true - CMake Build - - CMakeProjectManager.MakeStep - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release with Debug Information - Release with Debug Information - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=MinSizeRel - - /home/huxster/Source/build-FreeCAD-src-Desktop-Minimum Size Release - - - - - all - - true - CMake Build - - CMakeProjectManager.MakeStep - - 1 - Build - - ProjectExplorer.BuildSteps.Build - - - - - - all - - true - CMake Build - - CMakeProjectManager.MakeStep - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Minimum Size Release - Minimum Size Release - CMakeProjectManager.CMakeBuildConfiguration - - 5 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy locally - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - FreeCADMainCmd - - - /home/huxster/Target/freecad-qtcdb-build/bin - 2 - - FreeCADMainCmd - - CMakeProjectManager.CMakeRunConfiguration.FreeCADMainCmd - 3768 - false - true - false - false - true - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - FreeCADMain - - - /home/huxster/Target/freecad-qtcdb-build/bin - -1 - - FreeCADMain - - CMakeProjectManager.CMakeRunConfiguration.FreeCADMain - 3768 - false - true - false - false - true - - 2 - - - - ProjectExplorer.Project.Target.1 - - FCPy3 - FCPy3 - {e6789b53-bada-4b34-95c2-99709681bbbb} - 1 - 0 - 1 - - - /home/huxster/Target/freecad-qtc-build - - - - - all - - true - CMake Build - - CMakeProjectManager.MakeStep - - 1 - Build - - ProjectExplorer.BuildSteps.Build - - - - - - all - - true - CMake Build - - CMakeProjectManager.MakeStep - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Default - Default - CMakeProjectManager.CMakeBuildConfiguration - - - - BUILD_ADDONMGR:INTERNAL=ON - BUILD_ARCH:INTERNAL=ON - BUILD_ASSEMBLY:INTERNAL=OFF - BUILD_COMPLETE:INTERNAL=OFF - BUILD_DRAFT:INTERNAL=ON - BUILD_DRAWING:INTERNAL=ON - BUILD_FEM:INTERNAL=OFF - BUILD_FLAT_MESH:INTERNAL=OFF - BUILD_IDF:INTERNAL=OFF - BUILD_IMAGE:INTERNAL=OFF - BUILD_IMPORT:INTERNAL=ON - BUILD_INSPECTION:INTERNAL=OFF - BUILD_JTREADER:INTERNAL=OFF - BUILD_MATERIAL:INTERNAL=ON - BUILD_MESH:INTERNAL=ON - BUILD_MESH_PART:INTERNAL=ON - BUILD_OPENSCAD:INTERNAL=OFF - BUILD_PART:INTERNAL=ON - BUILD_PART_DESIGN:INTERNAL=ON - BUILD_PATH:INTERNAL=OFF - BUILD_PLOT:INTERNAL=OFF - BUILD_POINTS:INTERNAL=OFF - BUILD_QT5:INTERNAL=ON - BUILD_RAYTRACING:INTERNAL=OFF - BUILD_REVERSEENGINEERING:INTERNAL=OFF - BUILD_ROBOT:INTERNAL=OFF - BUILD_SANDBOX:INTERNAL=OFF - BUILD_SHIP:INTERNAL=OFF - BUILD_SHOW:INTERNAL=ON - BUILD_SKETCHER:INTERNAL=ON - BUILD_SPREADSHEET:INTERNAL=ON - BUILD_START:INTERNAL=OFF - BUILD_SURFACE:INTERNAL=OFF - BUILD_TECHDRAW:INTERNAL=ON - BUILD_TEMPLATE:INTERNAL=OFF - BUILD_TEST:INTERNAL=ON - BUILD_TUX:INTERNAL=ON - BUILD_VR:INTERNAL=OFF - BUILD_WEB:INTERNAL=OFF - CMAKE_BUILD_TYPE:STRING=Debug - FREECAD_USE_OCC_VARIANT:INTERNAL="Official Version" - OpenCASCADE_DIR:PATH=/usr/local/lib/cmake/opencascade72obs - PYTHON_EXECUTABLE:INTERNAL=/usr/bin/python3 - - /home/huxster/Target/freecad-qtcdb-build - - - - - all - - true - CMake Build - - CMakeProjectManager.MakeStep - - 1 - Build - - ProjectExplorer.BuildSteps.Build - - - - - - all - - true - CMake Build - - CMakeProjectManager.MakeStep - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - Debug - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=Release - - /home/huxster/Source/build-FreeCAD-src-FCPy3-Release - - - - - all - - true - CMake Build - - CMakeProjectManager.MakeStep - - 1 - Build - - ProjectExplorer.BuildSteps.Build - - - - - - all - - true - CMake Build - - CMakeProjectManager.MakeStep - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - Release - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=RelWithDebInfo - - /home/huxster/Source/build-FreeCAD-src-FCPy3-Release with Debug Information - - - - - all - - true - CMake Build - - CMakeProjectManager.MakeStep - - 1 - Build - - ProjectExplorer.BuildSteps.Build - - - - - - all - - true - CMake Build - - CMakeProjectManager.MakeStep - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release with Debug Information - Release with Debug Information - CMakeProjectManager.CMakeBuildConfiguration - - - - CMAKE_BUILD_TYPE:STRING=MinSizeRel - - /home/huxster/Source/build-FreeCAD-src-FCPy3-Minimum Size Release - - - - - all - - true - CMake Build - - CMakeProjectManager.MakeStep - - 1 - Build - - ProjectExplorer.BuildSteps.Build - - - - - - all - - true - CMake Build - - CMakeProjectManager.MakeStep - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Minimum Size Release - Minimum Size Release - CMakeProjectManager.CMakeBuildConfiguration - - 5 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy locally - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - FreeCADMainCmd - - - /home/huxster/Target/freecad-qtcdb-build/bin - 2 - - FreeCADMainCmd - - CMakeProjectManager.CMakeRunConfiguration.FreeCADMainCmd - 3768 - false - true - false - false - true - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - FreeCADMain - -l - - /home/huxster/Target/freecad-qtcdb-build/bin - 2 - - FreeCADMain - - CMakeProjectManager.CMakeRunConfiguration.FreeCADMain - 3768 - false - true - false - false - true - - 2 - - - - ProjectExplorer.Project.TargetCount - 2 - - - ProjectExplorer.Project.Updater.FileVersion - 18 - - - Version - 18 - - From 1d7d3436b44b641d4720d7b7987505dbff84a385 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 23 Aug 2019 12:53:03 +0200 Subject: [PATCH 18/19] improve error search when parameter group or name of a PrefWidget is not set --- src/Gui/PrefWidgets.cpp | 60 ++++++++++++++++++++++++++--------------- src/Gui/PrefWidgets.h | 6 +++++ 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/src/Gui/PrefWidgets.cpp b/src/Gui/PrefWidgets.cpp index f4b431e2e7..4d16c1ec01 100644 --- a/src/Gui/PrefWidgets.cpp +++ b/src/Gui/PrefWidgets.cpp @@ -135,6 +135,22 @@ void PrefWidget::onRestore() restorePreferences(); } +void PrefWidget::failedToSave(const QString& name) const +{ + QByteArray objname = name.toLatin1(); + if (objname.isEmpty()) + objname = "Undefined"; + Console().Warning("Cannot save %s (%s)\n", typeid(*this).name(), objname.constData()); +} + +void PrefWidget::failedToRestore(const QString& name) const +{ + QByteArray objname = name.toLatin1(); + if (objname.isEmpty()) + objname = "Undefined"; + Console().Warning("Cannot restore %s (%s)\n", typeid(*this).name(), objname.constData()); +} + // -------------------------------------------------------------------- PrefSpinBox::PrefSpinBox ( QWidget * parent ) @@ -150,7 +166,7 @@ void PrefSpinBox::restorePreferences() { if ( getWindowParameter().isNull() ) { - Console().Warning("Cannot restore!\n"); + failedToRestore(objectName()); return; } @@ -162,7 +178,7 @@ void PrefSpinBox::savePreferences() { if (getWindowParameter().isNull()) { - Console().Warning("Cannot save!\n"); + failedToSave(objectName()); return; } @@ -184,7 +200,7 @@ void PrefDoubleSpinBox::restorePreferences() { if ( getWindowParameter().isNull() ) { - Console().Warning("Cannot restore!\n"); + failedToRestore(objectName()); return; } @@ -196,7 +212,7 @@ void PrefDoubleSpinBox::savePreferences() { if (getWindowParameter().isNull()) { - Console().Warning("Cannot save!\n"); + failedToSave(objectName()); return; } @@ -218,7 +234,7 @@ void PrefLineEdit::restorePreferences() { if (getWindowParameter().isNull()) { - Console().Warning("Cannot restore!\n"); + failedToRestore(objectName()); return; } @@ -231,7 +247,7 @@ void PrefLineEdit::savePreferences() { if (getWindowParameter().isNull()) { - Console().Warning("Cannot save!\n"); + failedToSave(objectName()); return; } @@ -253,7 +269,7 @@ void PrefFileChooser::restorePreferences() { if (getWindowParameter().isNull()) { - Console().Warning("Cannot restore!\n"); + failedToRestore(objectName()); return; } @@ -265,7 +281,7 @@ void PrefFileChooser::savePreferences() { if (getWindowParameter().isNull()) { - Console().Warning("Cannot save!\n"); + failedToSave(objectName()); return; } @@ -287,7 +303,7 @@ void PrefComboBox::restorePreferences() { if (getWindowParameter().isNull()) { - Console().Warning("Cannot restore!\n"); + failedToRestore(objectName()); return; } @@ -299,7 +315,7 @@ void PrefComboBox::savePreferences() { if (getWindowParameter().isNull()) { - Console().Warning("Cannot save!\n"); + failedToSave(objectName()); return; } @@ -321,7 +337,7 @@ void PrefCheckBox::restorePreferences() { if (getWindowParameter().isNull()) { - Console().Warning("Cannot restore!\n"); + failedToRestore(objectName()); return; } @@ -333,7 +349,7 @@ void PrefCheckBox::savePreferences() { if (getWindowParameter().isNull()) { - Console().Warning("Cannot save!\n"); + failedToSave(objectName()); return; } @@ -355,7 +371,7 @@ void PrefRadioButton::restorePreferences() { if (getWindowParameter().isNull()) { - Console().Warning("Cannot restore!\n"); + failedToRestore(objectName()); return; } @@ -367,7 +383,7 @@ void PrefRadioButton::savePreferences() { if (getWindowParameter().isNull()) { - Console().Warning("Cannot save!\n"); + failedToSave(objectName()); return; } @@ -389,7 +405,7 @@ void PrefSlider::restorePreferences() { if ( getWindowParameter().isNull() ) { - Console().Warning("Cannot restore!\n"); + failedToRestore(objectName()); return; } @@ -401,7 +417,7 @@ void PrefSlider::savePreferences() { if (getWindowParameter().isNull()) { - Console().Warning("Cannot save!\n"); + failedToSave(objectName()); return; } @@ -423,7 +439,7 @@ void PrefColorButton::restorePreferences() { if (getWindowParameter().isNull()) { - Console().Warning("Cannot restore!\n"); + failedToRestore(objectName()); return; } @@ -445,7 +461,7 @@ void PrefColorButton::savePreferences() { if (getWindowParameter().isNull()) { - Console().Warning("Cannot save!\n"); + failedToSave(objectName()); return; } @@ -470,7 +486,7 @@ PrefUnitSpinBox::~PrefUnitSpinBox() void PrefUnitSpinBox::restorePreferences() { if (getWindowParameter().isNull()) { - Console().Warning("Cannot restore!\n"); + failedToRestore(objectName()); return; } @@ -481,7 +497,7 @@ void PrefUnitSpinBox::restorePreferences() void PrefUnitSpinBox::savePreferences() { if (getWindowParameter().isNull()) { - Console().Warning("Cannot save!\n"); + failedToSave(objectName()); return; } @@ -689,7 +705,7 @@ void PrefFontBox::restorePreferences() { if ( getWindowParameter().isNull() ) { - Console().Warning("Cannot restore!\n"); + failedToRestore(objectName()); return; } @@ -706,7 +722,7 @@ void PrefFontBox::savePreferences() { if (getWindowParameter().isNull()) { - Console().Warning("Cannot save!\n"); + failedToSave(objectName()); return; } diff --git a/src/Gui/PrefWidgets.h b/src/Gui/PrefWidgets.h index 4bcf497cfe..cbad7282e6 100644 --- a/src/Gui/PrefWidgets.h +++ b/src/Gui/PrefWidgets.h @@ -76,6 +76,12 @@ protected: * Must be reimplemented in any subclasses. */ virtual void savePreferences() = 0; + /** Print warning that saving failed. + */ + void failedToSave(const QString&) const; + /** Print warning that restoring failed. + */ + void failedToRestore(const QString&) const; PrefWidget(); virtual ~PrefWidget(); From 6dae8f371735dd54630e6bfb07824c7796509824 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 23 Aug 2019 13:02:53 +0200 Subject: [PATCH 19/19] add missing parameter group and name for 'UseMaterialColor' check box --- src/Mod/Arch/Resources/ui/preferences-arch.ui | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Mod/Arch/Resources/ui/preferences-arch.ui b/src/Mod/Arch/Resources/ui/preferences-arch.ui index 59c8603a90..5ab01921bc 100644 --- a/src/Mod/Arch/Resources/ui/preferences-arch.ui +++ b/src/Mod/Arch/Resources/ui/preferences-arch.ui @@ -228,6 +228,12 @@ true + + UseMaterialColor + + + Mod/Arch +