# Path: drawingDimensioning/linearDimension.py
# def linearDimension_parallels_hide_non_parallel(elementParms, elementViewObject):
#     x1,y1,x2,y2 = [ elementParms[k] for k in [ 'x1', 'y1', 'x2', 'y2' ] ]
#     d = numpy.array([ x2 - x1, y2 - y1] )
#     d_ref = d / numpy.linalg.norm(d)
#     p = numpy.array([ x1, y1] )
#     def hideFun( gi ):
#         if isinstance(gi,selectionOverlay.LineSelectionGraphicsItem):
#             if gi.elementParms != elementParms:
#                 x1,y1,x2,y2 = [ gi.elementParms[k] for k in [ 'x1', 'y1', 'x2', 'y2' ] ]
#                 d = numpy.array([ x2 - x1, y2 - y1] )
#                 d = d / numpy.linalg.norm(d)
#                 if abs(numpy.dot(d_ref,d)) > 1.0 - 10**-9: #then parallel
#                     d_rotated = rotate2D(d, numpy.pi/2)
#                     offset =  numpy.array([ x1, y1] ) - p
#                     if abs(numpy.dot(d_rotated, offset)) > 10**-6: #then not colinear
#                         return False
#         elif isinstance(gi,selectionOverlay.PointSelectionGraphicsItem):
#             return False
#         return True 
#     selectionOverlay.hideSelectionGraphicsItems(hideFun)


from drawingDimensioning.command import *
from .linearDimension import linearDimension_parallels_hide_non_parallel
    return _centerLinesSVG( center, topLeft, bottomRight, viewScale, centerLine_len_dot, centerLine_len_dash, centerLine_len_gap, centerLine_width, centerLine_color, v, not v )


d.registerPreference( 'centerLine_len_dot', 3 , label='dot length', increment=0.5)
d.registerPreference( 'centerLine_len_dash', 6 , label='dash length', increment=0.5)
d.registerPreference( 'centerLine_len_gap', 2 , label='gap length', increment=0.5)
d.registerPreference( 'centerLine_width', 0.32 , label='line width', increment=0.05)
d.registerPreference( 'centerLine_color', 255 << 8, kind='color' )
d.max_selections = 3

def centerLine_preview(mouseX, mouseY):
    selections = d.selections + [ PlacementClick( mouseX, mouseY, condensed_args=True) ] if len(d.selections) < d.max_selections else d.selections
    return d.SVGFun( *selections_to_svg_fun_args(selections), viewScale = d.viewScale, **d.dimensionConstructorKWs )

def centerLine_clickHandler( x, y ):
    d.selections.append( PlacementClick( x, y, condensed_args=True) )
    if len(d.selections) == d.max_selections:
        return 'createDimension:%s' % findUnusedObjectName('centerLines')

def selectFun(  event, referer, elementXML, elementParms, elementViewObject ):
    viewInfo = selectionOverlay.DrawingsViews_info[elementViewObject.Name]
    d.viewScale = elementXML.rootNode().scaling()
    # center line
    if isinstance(referer,selectionOverlay.PointSelectionGraphicsItem):
        d.selections = [ PointSelection( elementParms, elementXML, viewInfo, condensed_args=True ) ]
        selectionOverlay.hideSelectionGraphicsItems()
        previewDimension.initializePreview( d, centerLine_preview , centerLine_clickHandler)
    elif isinstance(referer,selectionOverlay.LineSelectionGraphicsItem):
        if len(d.selections) == 0:
            d.selections = [ TwoLineSelection() ]

# Path: drawingDimensioning/linearDimension.py
# def linearDimension_parallels_hide_non_parallel(elementParms, elementViewObject):
#     x1,y1,x2,y2 = [ elementParms[k] for k in [ 'x1', 'y1', 'x2', 'y2' ] ]
#     d = numpy.array([ x2 - x1, y2 - y1] )
#     d_ref = d / numpy.linalg.norm(d)
#     p = numpy.array([ x1, y1] )
#     def hideFun( gi ):
#         if isinstance(gi,selectionOverlay.LineSelectionGraphicsItem):
#             if gi.elementParms != elementParms:
#                 x1,y1,x2,y2 = [ gi.elementParms[k] for k in [ 'x1', 'y1', 'x2', 'y2' ] ]
#                 d = numpy.array([ x2 - x1, y2 - y1] )
#                 d = d / numpy.linalg.norm(d)
#                 if abs(numpy.dot(d_ref,d)) > 1.0 - 10**-9: #then parallel
#                     d_rotated = rotate2D(d, numpy.pi/2)
#                     offset =  numpy.array([ x1, y1] ) - p
#                     if abs(numpy.dot(d_rotated, offset)) > 10**-6: #then not colinear
#                         return False
#         elif isinstance(gi,selectionOverlay.PointSelectionGraphicsItem):
#             return False
#         return True 
#     selectionOverlay.hideSelectionGraphicsItems(hideFun)


# Path: drawingDimensioning/centerLines.py
from drawingDimensioning.command import *
from .linearDimension import linearDimension_parallels_hide_non_parallel

    return _centerLinesSVG( center, topLeft, bottomRight, viewScale, centerLine_len_dot, centerLine_len_dash, centerLine_len_gap, centerLine_width, centerLine_color, v, not v )


d.registerPreference( 'centerLine_len_dot', 3 , label='dot length', increment=0.5)
d.registerPreference( 'centerLine_len_dash', 6 , label='dash length', increment=0.5)
d.registerPreference( 'centerLine_len_gap', 2 , label='gap length', increment=0.5)
d.registerPreference( 'centerLine_width', 0.32 , label='line width', increment=0.05)
d.registerPreference( 'centerLine_color', 255 << 8, kind='color' )
d.max_selections = 3

def centerLine_preview(mouseX, mouseY):
    selections = d.selections + [ PlacementClick( mouseX, mouseY, condensed_args=True) ] if len(d.selections) < d.max_selections else d.selections
    return d.SVGFun( *selections_to_svg_fun_args(selections), viewScale = d.viewScale, **d.dimensionConstructorKWs )

def centerLine_clickHandler( x, y ):
    d.selections.append( PlacementClick( x, y, condensed_args=True) )
    if len(d.selections) == d.max_selections:
        return 'createDimension:%s' % findUnusedObjectName('centerLines')

def selectFun(  event, referer, elementXML, elementParms, elementViewObject ):
    viewInfo = selectionOverlay.DrawingsViews_info[elementViewObject.Name]
    d.viewScale = elementXML.rootNode().scaling()
    # center line
    if isinstance(referer,selectionOverlay.PointSelectionGraphicsItem):
        d.selections = [ PointSelection( elementParms, elementXML, viewInfo, condensed_args=True ) ]
        selectionOverlay.hideSelectionGraphicsItems()
        previewDimension.initializePreview( d, centerLine_preview , centerLine_clickHandler)
    elif isinstance(referer,selectionOverlay.LineSelectionGraphicsItem):
        if len(d.selections) == 0:
            d.selections = [ TwoLineSelection() ]

            linearDimension_parallels_hide_non_parallel( elementParms, elementViewObject)