Example #1
0
    def __resize_fired(self, sender, args):
        ''' This method is called whenever this panel is resized. '''

        # adjust the size of our PictureBox as needed to fulfill our contract
        panel_bds = self.Bounds
        a = Rectangle(panel_bds.X, panel_bds.Y,\
           self.Size.Width, self.Size.Width / self._ratio)
        b = Rectangle(panel_bds.X, panel_bds.Y,\
           self.Size.Height * self._ratio, self.Size.Height)

        if panel_bds.Contains(a):
            self._picbox.Size = a.Size
            self._picbox.Location = Point(0, (self.Size.Height - a.Height) / 2)
        else:
            self._picbox.Size = b.Size
            self._picbox.Location = Point((self.Size.Width - b.Width) / 2, 0)
Example #2
0
 def __install_persistent_bounds(self, a, b):
    """
    Called when this Form is just about to be displayed.  This method tries to
    restore the previously used location/size settings, and it also checks
    them to make sure that they are still valid on the current monitor 
    configuration (and fixes them if they are not!)
    """
    
    self.__load_bounds()
    
    # compute the center of our current bounding rectangle
    b = self.Bounds
    center = Point(b.X+b.Width/2, b.Y+b.Height/2)
    
    # if the center of this window is not onscreen, make it so that it is
    screens = Screen.AllScreens
    screen_bounds = screens[0].Bounds
    for screen in screens:
       screen_bounds = Rectangle.Union(screen_bounds, screen.Bounds)
    if not screen_bounds.Contains(center):
       log.debug("WARNING: form's location was offscreen; adjusted it")
       self.CenterToScreen()
       self.__bounds_changed = True
    else:
       self.__bounds_changed = False
Example #3
0
    def average_hash_and_sizes(self):
        height = 0
        width = 0
        if isJython():
            image = ImageIO.read(File(self.image_path))
            height = image.getHeight()
            width = image.getWidth()
            newImage = BufferedImage(self.hash_size, self.hash_size,
                                     BufferedImage.TYPE_INT_ARGB)
            g = newImage.createGraphics()
            g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                               RenderingHints.VALUE_INTERPOLATION_BICUBIC)
            g.setRenderingHint(RenderingHints.KEY_RENDERING,
                               RenderingHints.VALUE_RENDER_QUALITY)
            g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                               RenderingHints.VALUE_ANTIALIAS_ON)
            g.drawImage(image, 0, 0, self.hash_size, self.hash_size, None)
            g.dispose()
            allchannelpixels = [[], [], [], []]
            for i in range(self.hash_size):
                for j in range(self.hash_size):
                    pixel = int(newImage.getRGB(i, j))
                    allchannelpixels[0].append((pixel >> 16) & 0xFF)
                    allchannelpixels[1].append((pixel >> 8) & 0xFF)
                    allchannelpixels[2].append((pixel) & 0xFF)
                    allchannelpixels[3].append((pixel >> 24) & 0xFF)
        elif isIronPython():
            srcImage = Bitmap(self.image_path)
            height = srcImage.Height
            width = srcImage.Width
            newImage = Bitmap(self.hash_size, self.hash_size)
            gr = Graphics.FromImage(newImage)
            gr.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
            gr.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
            gr.PixelOffsetMode = Drawing2D.PixelOffsetMode.HighQuality
            gr.DrawImage(srcImage,
                         Rectangle(0, 0, self.hash_size, self.hash_size))
            allchannelpixels = [[], [], [], []]
            for i in range(self.hash_size):
                for j in range(self.hash_size):
                    pixel = newImage.GetPixel(i, j)
                    allchannelpixels[0].append(int(pixel.R))
                    allchannelpixels[1].append(int(pixel.G))
                    allchannelpixels[2].append(int(pixel.B))
                    allchannelpixels[3].append(int(pixel.A))
        else:
            self.image = Image.open(self.image_path)
            width, height = self.image.size
            image = self.image.resize((self.hash_size, self.hash_size),
                                      Image.ANTIALIAS)
            # image.show()
            allchannelpixels = [
                list(channel.getdata()) for channel in image.split()
            ]

        bits = []
        for pixels in allchannelpixels:
            bits.append(self.getBitString(pixels))
        return bits, width, height
Example #4
0
 def OnMouseMove(self, sender, e):
     if self.mouse_down and self.snip_enabled:
         x1 = Math.Min(e.X, self.mouse_down.X)
         y1 = Math.Min(e.Y, self.mouse_down.Y)
         x2 = Math.Max(e.X, self.mouse_down.X)
         y2 = Math.Max(e.Y, self.mouse_down.Y)
         self.snip_rectangle = Rectangle(x1, y1, x2 - x1, y2 - y1)
         self.Invalidate()
 def on_mouse_move(self, sender, e):
     if self.mouse_down and self.snip_enabled:
         x1 = int(min(e.X, self.mouse_down.X))
         y1 = int(min(e.Y, self.mouse_down.Y))
         x2 = int(max(e.X, self.mouse_down.X))
         y2 = int(max(e.Y, self.mouse_down.Y))
         self.snip_rectangle = Rectangle(x1, y1, x2 - x1, y2 - y1)
         self.Invalidate()
Example #6
0
    def on_paint(self, sender, e):
        if self.snip_enabled and self.snip_rectangle is not None:
            br = SolidBrush(Color.FromArgb(120, Color.White))
            rc = self.snip_rectangle
            pen = Pen(Color.Red, 3.0)

            x1 = rc.X
            x2 = rc.X + rc.Width
            y1 = rc.Y
            y2 = rc.Y + rc.Height

            e.Graphics.FillRectangle(br, Rectangle(0, 0, x1, self.Height))
            e.Graphics.FillRectangle(
                br, Rectangle(x2, 0, self.Width - x2, self.Height))
            e.Graphics.FillRectangle(br, Rectangle(x1, 0, x2 - x1, y1))
            e.Graphics.FillRectangle(
                br, Rectangle(x1, y2, x2 - x1, self.Height - y2))
            e.Graphics.DrawRectangle(pen, rc)
    def pick(snip=False):
        snipper = PickSnipTool(PickSnipTool.take_screenshot(), snip=snip)

        while True:
            result = snipper.ShowDialog()
            if result in [DialogResult.OK, DialogResult.Cancel]:
                break
            if snipper.mouse_down_seconds == 1:
                Mouse.Instance.Click(snipper.mouse_down)
                time.sleep(0.5)
            snipper.BackgroundImage = PickSnipTool.take_screenshot()

        if result == DialogResult.OK and snip:
            if snipper.snip_rectangle.Width and snipper.snip_rectangle.Height:
                img = Bitmap(
                    snipper.snip_rectangle.Width,
                    snipper.snip_rectangle.Height,
                )
                gr = Graphics.FromImage(img)
                gr.DrawImage(
                    snipper.BackgroundImage,
                    Rectangle(0, 0, img.Width, img.Height),
                    snipper.snip_rectangle,
                    GraphicsUnit.Pixel,
                )
                fp = MemoryStream()
                img.Save(fp, ImageFormat.Png)
                return {
                    'bytes': bytes(bytearray(fp.ToArray())),
                }
            return {}

        elif result == DialogResult.OK:
            if (snipper.mouse_down_seconds
                    and snipper.mouse_down_seconds <= snipper.click_timeout):
                Mouse.Instance.Click(snipper.mouse_down)
                time.sleep(0.5)
            el = AutomationElement.FromPoint(snipper.mouse_up)
            result = {
                prop.ProgrammaticName.split('.', 1)[-1]:
                el.GetCurrentPropertyValue(prop)
                for prop in el.GetSupportedProperties()
            }
            result.update({
                'NameProperty':
                el.GetCurrentPropertyValue(el.NameProperty),
                'ControlTypeProperty':
                el.GetCurrentPropertyValue(
                    el.ControlTypeProperty, ).ProgrammaticName.split('.',
                                                                     1)[-1],
                'AutomationIdProperty':
                el.GetCurrentPropertyValue(el.AutomationIdProperty, ),
            })
            return result
        else:
            return {}
Example #8
0
 def OnMouseDown(self, sender, e):
     self.mouse_down = Point(e.Location.X, e.Location.Y)
     self.mouse_down_button = e.Button
     self.mouse_down_seconds = 0
     if not self.snip_enabled:
         self.mouse_down_timer = Timer()
         self.mouse_down_timer.Interval = 1000
         self.mouse_down_timer.Tick += self.OnTimerTick
         self.mouse_down_timer.Start()
     self.snip_rectangle = Rectangle(e.Location, Size(0, 0))
 def __drawFolderThumbnail(self, parent):
     size = ThumbnailSize
     # create new image
     newImage = Bitmap(size, size)
     g = Graphics.FromImage(newImage)
     g.InterpolationMode = InterpolationMode.HighQualityBicubic
     # draw background
     if parent: bc = ParentFolderColor
     else: bc = ChildFolderColor
     b = LinearGradientBrush(Point(0, 0), Point(size, size), bc,
                             Color.GhostWhite)
     g.FillRectangle(b, 0, 0, size, size)
     b.Dispose()
     g.DrawRectangle(Pens.LightGray, 0, 0, size - 1, size - 1)
     # draw up to 4 subitems
     folderItems = self.GetFirstFolderItems(4)
     delta = 10
     side = (size - 3 * delta) / 2 - 1
     rects = (Rectangle(delta + 3, delta + 12, side, side),
              Rectangle(size / 2 + delta / 2 - 3, delta + 12, side, side),
              Rectangle(delta + 3, size / 2 + delta / 2 + 6, side, side),
              Rectangle(size / 2 + delta / 2 - 3, size / 2 + delta / 2 + 6,
                        side, side))
     for rect, item in zip(rects, folderItems):
         subImage = Bitmap.FromStream(MemoryStream(item.thumbnail()), False)
         g.DrawImage(subImage, rect)
         subImage.Dispose()
     for rect in rects:
         g.DrawRectangle(Pens.LightGray, rect)
     # draw folder name
     if parent: name = '[..]'
     else: name = Path.GetFileName(self.path)
     f = Font('Arial', 10)
     g.DrawString(name, f, Brushes.Black,
                  RectangleF(2, 2, size - 2, size - 2))
     f.Dispose()
     # get the bytes of the image
     imageBytes = BitmapToBytes(newImage)
     # cleanup
     g.Dispose()
     newImage.Dispose()
     return imageBytes
Example #10
0
 def __copy_transparent(self, image):
    ''' Creates a semi-transparent copy of the given image ''' 
    
    b = Bitmap( image.Width, image.Height )
    g = Graphics.FromImage(b)
    cm = ColorMatrix()
    cm.Matrix33 = 0.3
    ia = ImageAttributes()
    ia.SetColorMatrix(cm)
    g.DrawImage(image, Rectangle(0,0, image.Width, image.Height), 0,0,\
       image.Width, image.Height, GraphicsUnit.Pixel, ia)
    return b
Example #11
0
def draw2d(game, time, batch):
    animator_fireball.Draw(time, batch)
    if walking:
        animator_character_walk.Draw(time, batch)
    else:
        batch.Draw(
            animator_character_walk.Sheet.Texture,
            Rectangle(animator_character_walk.Sheet[0].X,
                      animator_character_walk.Sheet[0].Y,
                      animator_character_walk.Sheet[0].Width,
                      animator_character_walk.Sheet[0].Height),
            animator_character_walk.Position, Color4.White)
Example #12
0
 def crop(self, left=0, top=0, right=0, bottom=0):
     width = self._bitmap.Width - right
     height = self._bitmap.Height - bottom
     r = Rectangle(left, top, width, height)
     try:
         cropImage = self._bitmap.Clone(r, self._bitmap.PixelFormat)
     except:
         print "retrying  rectangle=%s" % str(r)
         self.resize(self._bitmap.Width + 10, self._bitmap.Height + 10)
         try:
             cropImage = self._bitmap.Clone(r, self._bitmap.PixelFormat)
         except Exception, e:
             print "Error in crop: %s" % str(e)
             return
def __perceptual_hash(image):
    '''  Returns a 'perceptual' image hash for the given Image. '''

    if image is not None:

        SIZE = 8

        # create ImageAttributes for converting image to greyscale
        # see: http://tech.pro/tutorial/660/
        #              csharp-tutorial-convert-a-color-image-to-grayscale
        attr = ImageAttributes()
        attr.SetColorMatrix(
           ColorMatrix(Array[Array[Single]](( \
              (0.3, 0.3, 0.3, 0.0, 0.0),
              (.59, .59, .59, 0.0, 0.0),
              (.11, .11, .11, 0.0, 0.0),
              (0.0, 0.0, 0.0, 1.0, 0.0),
              (0.0, 0.0, 0.0, 0.0, 1.0)
           )))
        )

        with Bitmap(SIZE, SIZE, PixelFormat.Format64bppArgb) as small_image:
            with Graphics.FromImage(small_image) as g:

                # draw image in greyscale in a tiny square
                # see: https://www.memonic.com/user/aengus/folder/coding/id/1qVeq
                g.CompositingQuality = CompositingQuality.HighQuality
                g.SmoothingMode = SmoothingMode.HighQuality
                g.InterpolationMode = InterpolationMode.HighQualityBicubic
                g.DrawImage(image, Rectangle(0, 0, SIZE,
                                             SIZE), 0, 0, image.Width,
                            image.Height, GraphicsUnit.Pixel, attr)

                # convert image pixels into bits, where 1 means pixel is greater
                # than image average, and 0 means pixel is less than average.
                # return bits as a single long value
                pixels = [
                    small_image.GetPixel(x, y).R for x in range(SIZE)
                    for y in range(SIZE)
                ]
                average = reduce(lambda x, y: x + y, pixels) / float(
                    len(pixels))
                bits = map(lambda x: 1 if x > average else 0, pixels)
                return reduce(lambda x, (i, val): x | (val << i),
                              enumerate(bits), 0)

    else:
        return long(0)
 def updateThumb(self):
     hwnd = None
     if self.locked:
         hwnd = MaxPlus.ViewportManager.GetViewportByID(
             self.locked_id).GetHWnd()
     else:
         hwnd = MaxPlus.ViewportManager.GetActiveViewport().GetHWnd()
     r = Win32.GetWindowsRectangle(hwnd)
     r2 = Win32.GetWindowsRectangle(MaxPlus.Core.GetWindowHandle())
     r.X = r.X - r2.X
     r.Y = r.Y - r2.Y
     r.Width = r.Width - r2.X
     r.Height = r.Height - r2.Y
     self.thumb.SetDestinationRectangle(
         Rectangle(0, 0, self.Width - 15, self.Height - 20))
     self.thumb.SetSourceRectangle(r)
Example #15
0
def test_system_drawing():
    clr.AddReferenceByPartialName("System.Drawing")
    from System.Drawing import Rectangle
    r = Rectangle(0, 0, 3, 7)
    s = Rectangle(3, 0, 8, 14)

    # calling the static method
    i = Rectangle.Intersect(r, s)
    AreEqual(i, Rectangle(3, 0, 0, 7))
    AreEqual(r, Rectangle(0, 0, 3, 7))
    AreEqual(s, Rectangle(3, 0, 8, 14))

    # calling the instance
    i = r.Intersect(s)
    AreEqual(i, None)
    AreEqual(r, Rectangle(3, 0, 0, 7))
    AreEqual(s, Rectangle(3, 0, 8, 14))

    # calling instance w/ StrongBox
    r = Rectangle(0, 0, 3, 7)
    box = clr.StrongBox[Rectangle](r)
    i = box.Intersect(s)
    AreEqual(i, None)
    AreEqual(box.Value, Rectangle(3, 0, 0, 7))
    AreEqual(s, Rectangle(3, 0, 8, 14))

    # should be able to access properties through the box
    AreEqual(box.X, 3)

    # multiple sites should produce the same function
    i = box.Intersect
    j = box.Intersect
Example #16
0
    def test_sys_drawing(self):
        from IronPythonTest import DaysInt, DaysShort, DaysLong, DaysSByte, DaysByte, DaysUShort, DaysUInt, DaysULong
        from System.Drawing import Point, Size, PointF, SizeF, Rectangle, RectangleF
        x = Point()
        self.assertTrue(x == Point(0, 0))
        x = Size()
        self.assertTrue(x == Size(0, 0))
        x = PointF()
        self.assertTrue(x == PointF(0, 0))
        x = SizeF()
        self.assertTrue(x == SizeF(0, 0))
        x = Rectangle()
        self.assertTrue(x == Rectangle(0, 0, 0, 0))
        x = RectangleF()
        self.assertTrue(x == RectangleF(0, 0, 0, 0))

        p = Point(3, 4)
        s = Size(2, 9)

        q = p + s
        self.assertTrue(q == Point(5, 13))
        self.assertTrue(q != Point(13, 5))
        q = p - s
        self.assertTrue(q == Point(1, -5))
        self.assertTrue(q != Point(0, 4))
        q += s
        self.assertTrue(q == Point(3, 4))
        self.assertTrue(q != Point(2, 4))
        q -= Size(1, 2)
        self.assertTrue(q == Point(2, 2))
        self.assertTrue(q != Point(1))

        t = s
        self.assertTrue(t == s)
        self.assertTrue(t != s - Size(1, 0))
        t += Size(3, 1)
        self.assertTrue(t == Size(5, 10))
        self.assertTrue(t != Size(5, 0))
        t -= Size(2, 8)
        self.assertTrue(t == Size(3, 2))
        self.assertTrue(t != Size(0, 2))
        t = s + Size(-1, -2)
        self.assertTrue(t == Size(1, 7))
        self.assertTrue(t != Size(1, 5))
        t = s - Size(1, 2)
        self.assertTrue(t == Size(1, 7))
        self.assertTrue(t != Size(1, 3))

        def weekdays(enum):
            return enum.Mon | enum.Tue | enum.Wed | enum.Thu | enum.Fri

        def weekend(enum):
            return enum.Sat | enum.Sun

        def enum_helper(enum):
            days = [
                enum.Mon, enum.Tue, enum.Wed, enum.Thu, enum.Fri, enum.Sat,
                enum.Sun
            ]
            x = enum.Mon | enum.Tue | enum.Wed | enum.Thu | enum.Fri | enum.Sat | enum.Sun
            y = enum.Mon
            for day in days:
                y |= day
            self.assertTrue(x == y)
            self.assertFalse(x != y)
            if x == y:  # EqualRetBool
                b = True
            else:
                b = False
            self.assertTrue(b)

            self.assertTrue(x == weekdays(enum) | weekend(enum))
            self.assertTrue(x == (weekdays(enum) ^ weekend(enum)))
            self.assertTrue((weekdays(enum) & weekend(enum)) == enum["None"])
            self.assertTrue(weekdays(enum) == enum.Weekdays)
            self.assertTrue(weekend(enum) == enum.Weekend)
            self.assertTrue(weekdays(enum) != enum.Weekend)
            self.assertTrue(weekdays(enum) != weekend(enum))

        for e in [
                DaysInt, DaysShort, DaysLong, DaysSByte, DaysByte, DaysUShort,
                DaysUInt, DaysULong
        ]:
            enum_helper(e)

        for e in [DaysInt, DaysShort, DaysLong, DaysSByte]:
            z = operator.inv(e.Mon)
            self.assertEqual(type(z), e)
            self.assertEqual(z.ToString(), "-2")

        for (e, v) in [(DaysByte, 254), (DaysUShort, 65534),
                       (DaysUInt, 4294967294),
                       (DaysULong, 18446744073709551614)]:
            z = operator.inv(e.Mon)
            self.assertEqual(type(z), e)
            self.assertEqual(z.ToString(), str(v))

        self.assertRaises(ValueError, lambda: DaysInt.Mon & DaysShort.Mon)
        self.assertRaises(ValueError, lambda: DaysInt.Mon | DaysShort.Mon)
        self.assertRaises(ValueError, lambda: DaysInt.Mon ^ DaysShort.Mon)
        self.assertRaises(ValueError, lambda: DaysInt.Mon & 1)
        self.assertRaises(ValueError, lambda: DaysInt.Mon | 1)
        self.assertRaises(ValueError, lambda: DaysInt.Mon ^ 1)

        def f():
            if DaysInt.Mon == DaysShort.Mon: return True
            return False

        self.assertEqual(f(), False)

        self.assertTrue(not DaysInt.Mon == None)
        self.assertTrue(DaysInt.Mon != None)
Example #17
0
    def __pbox_painted(self, picbox, args):
        ''' Called after the picturebox paints itself. '''

        # this method adds two arrows (left and right) to the PictureBox,
        # painted on top of it's regular graphcis.

        left_arrow = self.__left_arrow
        full_left_arrow = self.__full_left_arrow
        right_arrow = self.__right_arrow
        full_right_arrow = self.__full_right_arrow

        if left_arrow.Width != right_arrow.Width or \
              full_left_arrow.Width != right_arrow.Width or \
              full_right_arrow.Width != right_arrow.Width or \
              left_arrow.Height != right_arrow.Height or \
              full_left_arrow.Height != right_arrow.Height or \
              full_right_arrow.Height != right_arrow.Height:
            raise Exception("arrows must be identical dimensions")

        # 1. compute scaled widths and heights for the arrow images
        old_width = float(right_arrow.Width)
        scaled_width = min(picbox.Width * 0.15, old_width)
        old_height = float(right_arrow.Height)
        scaled_height = old_height * scaled_width / old_width

        # 2. compute the proper location for the full arrow images
        y = picbox.Height / 2 - scaled_height / 2
        xoffset = picbox.Width * 0.01
        f_leftx = xoffset
        f_rightx = picbox.Width - xoffset - scaled_width

        # 3. compute the proper location for the arrow images
        leftx = f_leftx + scaled_width
        rightx = f_rightx - scaled_width

        # 4. keep track of the right edges of the left and right clickable
        #    column, so we'll be able to tell which icon the user clicks on.
        self.__left_bound = leftx
        self.__right_bound = f_rightx

        if self.Parent != None:

            # 5. paint each arrow if it is possible to "turn the page" in that
            #    direction.   alpha-blend the inactive arrow (the one on the half
            #    of the pbox that the mouse ISN'T hovering over.)
            g = args.Graphics
            mouse_hovered = self.__mouse_hovered_state
            can_go_left = self.Parent._can_change_page(False)
            can_go_right = self.Parent._can_change_page(True)

            # 5a. draw the full left and left arrows if they are active
            if mouse_hovered and can_go_left:
                image_atts = self.__hovered_image_atts if mouse_hovered == 'FL' \
                   else self.__normal_image_atts
                dest_rect = Rectangle(f_leftx, y, scaled_width, scaled_height)
                g.DrawImage(full_left_arrow, dest_rect, 0, 0, old_width,
                            old_height, GraphicsUnit.Pixel, image_atts)

                image_atts = self.__hovered_image_atts if mouse_hovered == 'L' \
                   else self.__normal_image_atts
                dest_rect = Rectangle(leftx, y, scaled_width, scaled_height)
                g.DrawImage(left_arrow, dest_rect, 0, 0, old_width, old_height,
                            GraphicsUnit.Pixel, image_atts)

            # 5b. draw the right and full right arrows if they are active
            if mouse_hovered and can_go_right:
                image_atts = self.__hovered_image_atts if mouse_hovered == 'R' \
                   else self.__normal_image_atts
                dest_rect = Rectangle(rightx, y, scaled_width, scaled_height)
                g.DrawImage(right_arrow, dest_rect, 0, 0, old_width,
                            old_height, GraphicsUnit.Pixel, image_atts)

                image_atts = self.__hovered_image_atts if mouse_hovered == 'FR' \
                   else self.__normal_image_atts
                dest_rect = Rectangle(f_rightx, y, scaled_width, scaled_height)
                g.DrawImage(full_right_arrow, dest_rect, 0, 0, old_width,
                            old_height, GraphicsUnit.Pixel, image_atts)
Example #18
0
obj = rs.GetObject("Select object for prediction")
orbitRes = rs.GetReal("Number of images per revolution", number=10)
vertRes = rs.GetReal("Number of revolutions", number=5)
distMult = rs.GetReal("Distance from object", number=5)

sc.doc.Objects.Select(obj)
rs.Command("_Invert")
rs.Command("_Hide")

w = 64
h = 64

rView = Rhino.RhinoDoc.ActiveDoc.Views.Add(
    "view", Rhino.Display.DefinedViewportProjection.Perspective,
    Rectangle(Point(100, 100), Size(w, h)), True)

# http://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_Display_RhinoViewport.htm
rView.TitleVisible = False
rView.MainViewport.ConstructionGridVisible = False
rView.MainViewport.ConstructionAxesVisible = False
rView.MainViewport.WorldAxesVisible = False

Rhino.ApplicationSettings.AppearanceSettings.ViewportBackgroundColor = Color.White
shaded = Rhino.Display.DisplayModeDescription.FindByName("Shaded")
rView.ActiveViewport.DisplayMode = shaded

tar = rs.SurfaceVolumeCentroid(obj)[0]

#http://4.rhino3d.com/5/rhinoscript/geometry_methods/boundingbox.htm
bb = rs.BoundingBox(obj)
Example #19
0
    # Relative Origin for Cropping
    crop_pt_x_ft = up_left_crop_pt.X
    crop_pt_y_ft = img_height - up_left_crop_pt.Y

    # Multiplier to convert from Ft Coordinate to Pixel
    x_ft_to_px_scale = img_width_px / img_width
    y_ft_to_px_scale = img_height_px / img_height

    # Convert ft space to pixel space
    crop_pt_x_px = crop_pt_x_ft * x_ft_to_px_scale
    crop_pt_y_px = crop_pt_y_ft * y_ft_to_px_scale
    cropbox_width_px = cropbox_width_ft * x_ft_to_px_scale
    cropbox_height_px = cropbox_height_ft * y_ft_to_px_scale

    rectangle_crop = Rectangle(crop_pt_x_px, crop_pt_y_px, cropbox_width_px,
                               cropbox_height_px)
    new_img_path = crop_image(img_path, rectangle_crop)

    # New Image Options
    import_options = ImageImportOptions()
    import_options.Placement = BoxPlacement.Center
    import_options.RefPoint = get_bbox_center_pt(fregion_bbox)
    import_options.Resolution = img_resolution

    # Create New Image in Revit
    t = Transaction(doc, 'Crop Image')
    t.Start()
    new_img_element = StrongBox[Element]()
    doc.Import(new_img_path, import_options, doc.ActiveView, new_img_element)
    new_img_width = new_img_element.get_Parameter(bip_width_ft)
    new_img_width.Set(cropbox_width_ft)
 def LocateRect(self):
     x = (self.ClientSize.Width - RECT_WIDTH) / 2
     y = (self.ClientSize.Height - RECT_HEIGHT) / 2
     self.r = Rectangle(x, y, RECT_WIDTH, RECT_HEIGHT)
Example #21
0
        found = True
        break
    else:
        continue

#Create Window sizing and positioning based on display selected
width = int(displayBounds.Width / 2) + COMPENSATION_WIDTH
height = displayBounds.Height + COMPENSATION_HEIGHT
y = displayBounds.Y + COMPENSATION_Y
xleft = displayBounds.X + COMPENSATION_X_LEFT
xright = displayBounds.X + width + COMPENSATION_X_RIGHT

#Create the new Rhino views and capture their RhinoView instances
leftEye_View = scriptcontext.doc.Views.Add(
    "LeftEye", DefinedViewportProjection.Perspective,
    Rectangle(xleft, y, width, height), True)
rightEye_View = scriptcontext.doc.Views.Add(
    "RightEye", DefinedViewportProjection.Perspective,
    Rectangle(xright, y, width, height), True)
leftEye = leftEye_View.ActiveViewport
rightEye = rightEye_View.ActiveViewport

leftEye.SetCameraLocation(
    leftEye.CameraLocation - leftEye.CameraX * INTEROCULAR_DISTANCE / 2.0,
    False)
rightEye.SetCameraLocation(
    rightEye.CameraLocation - rightEye.CameraX * INTEROCULAR_DISTANCE / 2.0,
    False)

#Get Position and look at vector from external
#Expected response like: {"pos":[3,2,1], "lookAt":[1,2,3]}