Is there an alternative to View.GetOutline() which DOES include Temporary Axes? - vba

Note: This is not answered by the suggested question - it is practically the opposite of it. Besides, it is me who asked that question too and I also linked to it below.
I am fixing someone else's VBA code for SolidWorks which places drawing views next to each other based on their size.
Size of a view is taken from bounding box returned by View.GetOutline() and view's position is set by changing View.Position property.
The code processes multibody parts, creating one drawing sheet per body.
The problem is that View.Position property corresponds to center of bounding box that includes Temporary Axes while View.GetOutline() does not include them - it returns a bit more than the selection outline shown by SolidWorks GUI.
This is the multibody part and one of the offending drawing views with temporary axes turned on in the SW GUI:
In the drawing you can see:
selection outline shown by SW GUI (light blue dotted rectangle)
diagonal of the outline returned by View.GetOutline() (red line)
center of the view as in View.Position property (red X)
temporary axes (blue crosses and lines)
Is there a way to get drawing view's real size, the one that correspond to the bounding box whose center is the View.Position property?
Apparently, the drawing view includes temporary axes from other bodies in this multibody part.
That points to the alternative question: Is there a way to prevent temporary axes from other bodies in a multibody part from being included in drawing view of a single body?
For reference, the problem is the same no matter which method is used to create the view (e.g. CreateDrawViewFromModelView3(), CreateUnfoldedViewAt3(), CreateRelativeView(), etc.).
Note: I asked another question that stems from this same problem which I changed because I wrongly assumed that View.GetOutline() does not include Temporary Axes.

I found an easy way to do that.
Yesterday I had the same problem and I've fixed the issue.
As you correctly have stated there is an offset between the Bouding Box center on the drawing and the View center (whose coordinate are given by the View.Position property in VBA).
Actually you want to place the your view according the Bounding Box (BB) center (let's call this position DesiredBBPos)...but we have to set the position through View.Position property.
So what you have to do is just to get this offset before moving the view.
The offset is the difference between the View center point (View.Position(0) ; View.Position(1)) and the BB center ((Xmax+Xmin)/2 ; (Ymax+Ymin)/2 )
I have defined an array Offset(1) in which I've put the Horizontal Offset and Vertical Offset (as above)
Now you can set the view position by a formula that will look like:
View.Position (0) = DesiredBBPos(0) + Offset(0)
View.Position (1) = DesiredBBPos(1) + Offset(1)
It works ;)
Aldo

Related

NSStackView / NSScrollView - bisected NSStackview subview?

this is going to be hard to explain.
I am modifying the InfoBarStackView sample code from Apple.
The problem that I am encountering, is that it looks as if one of the subviews is being divided in two, by NSStackview and rendered separately.
In my sample, I am adding 4 subviews to my stack view, each exactly the same size (and same code). This is then placed into an NSScrollView. (The layout is vertical.)
When the application is run, I see the very first two subviews. When I scroll downward, the weirdness begins. The subsequent view is rendered, where the bottom portion is rendered, then the top is rendered. If the vertical size is 272 pixels, the bottom is rendered as 256 pixels and the top is the remainder (16). Scrolling down to the last view causes the same problem.
Attached are some screen grabs to illustrate:
I have a sample project for Xcode 8. I have posted the Xcode 8 project here, if someone would like to take a look. I can't seem to figure this one out.
Are you referring to the extra bounding boxes that intersect the "Label" and "Show" buttons?
If you use Xcode's View Debugger to look at the decomposition of the view hierarchy and the drawn contents of each view, you'll see that the extra bounding boxes are drawn by the GT_BorderedViews — that is, the bottom GT_BorderedViews are each drawing two bounding boxes.
GT_BorderedView's implementation of -drawRect: calculates and draws the bounding boxes based on the dirtyRect that is passed in. However, as the documentation states, the dirty rect is «a rectangle defining the portion of the view that requires redrawing», not necessarily the entire bounds of the view. Changing the implementation to calculate and draw the border based on [self bounds] instead of the dirty rect results in the expected appearance.
Taylor nailed it. I didn't realize that drawRect didn't render the whole view. Using [self bounds] rather than dirtyRect ensures the draw happens properly.

Psychtoolbox scale slider

I'm trying to make a slider for a simple scale where the user can see mouse movement ONLY in the horizontal axis (fixed y location on the horizontal scale).
In more detail: When the scale appears, I want the cursor to appear as a short vertical line (aka slider) in the center of the horizontal scale.
When the user moves the mouse, the slider should move accordingly on the horizontal axis (without reflecting any changes in the vertical axis, i.e. it should stay on the scale)
I'm stuck on both changing the appearance of the cursor to a vertical line slider and on limiting the cursor's movement to the horizontal axis.
Here's what I've tried:
I can successfully place the cursor with SetMouse.
I tried ShowCursor to change the appearance of the cursor, but this only has a few named options and the numbered ones are not portable across OSs ("mapping of numbers to shapes is operating system dependent"), which I need. Any other ideas on how to change the cursor to a vertical line slider?
As for limiting the movement to horizontal, I couldn't find any PTB functions that seem to do this. I did find some workarounds in Matlab to make user GUIs, but it seems these can't be used with PTB's screen. Any ideas would be great!
I'm a still very new to PTB so thank you so much for your help!
I wrote a function for exactly that called slideScale. If you want to see how it works see the test script.
The crucial thing for you is to create a loop, which runs until a click has been made and record the position of the cursor for instance with the function GetMouse(), which gives you the x- and y-coordinates of the cursor. Then, the only thing you basically need is to update the position of your vertical line using the x-coordinate you recorded with GetMouse() without changing the y-coordinates, for which you can just use a fixed value.

Change size of window in Cocoa?

I have a window whose size I need to change when the user clicks on it. I am using [self setFrame:windowFrame display:YES animate:YES] to accomplish this.
Even though the window successfully changes size (I increase its height), it moves the contents of the window up with it. How do I prevent this from happening? I want the contents to remain in place.
I am on OSX Mountain Lion developing an app for OSX using Objective-C and Cocoa.
EDIT: Constraints and/or Springs and Struts will not work as I need to move the contents around after the window is resized.
Constraints and/or Springs and Struts will not work as I need to move the contents around after the window is resized.
In that case, you should use NSViewAnimation.
A single view animation can actually perform multiple animations to multiple views, and you can even do one to a window, despite the class's name and the fact that windows aren't views in Cocoa.
You create a view animation with initWithViewAnimations:, which takes an array of dictionaries. Each dictionary identifies the target (NSViewAnimationTargetKey) and what to do to it: Either change the target's frame (NSViewAnimationStartFrameKey and NSViewAnimationEndFrameKey) or fade the target in or out (NSViewAnimationEffectKey). For your case, you'll be changing the targets' frames.
When the user does the thing that causes the resize of the window, you'll need to compute the desired overall size of the window (taking care to adjust its frame's position so it doesn't grow off the screen), as well as the new frames—both positions and sizes—of your views. Everything that will move and/or change size, create a dictionary for it and throw it into the array. Then create the view animation.
An NSViewAnimation is a kind of NSAnimation, which provides all the methods for starting and stopping the animation, monitoring its progress, hooking into it, and chaining multiple NSAnimations together. If nothing else, you'll need to start the animation.
If you are using the Interface Builder to build these views, then I believe one approach is to set the "struts and springs." These are available under the "size inspector" and are the red arrows and bars above the "autosizing" label. Play around with these to get the effect that you want, but the general idea is that the arrows control how the size of the view adjusts to changes in the size of the parent view, and the bars control the relationship of the edges of the view to the edges of the parent view as the size changes.
In constraint-based layout, set the views around the edge of your window to be a fixed distance from their superview's edge.
Xcode will infer a lot of resizability from that; if anything still isn't resizing properly, adjust its constraints so that its width and/or height is no longer constant.
The easiest way is to move your views until blue lines show up in the editor. Each blue line corresponds to a rule in the HIG about how things should be lain out, and if you drop the view there, Xcode will create constraints matching those guidelines. For example, if you set a view 20 points from the right edge of its superview, you'll get a blue line for that, and if you drop the view there, you'll create a constraint that the view must remain that distance from that edge.
The superview isn't the only view with which you can create HIG-based constraints. You can also create guideline constraints between sibling views. For example, if you put a button next to another button at the appropriate distance, you'll get a blue line across that distance, and if you drop it, you'll create a constraint that those two buttons must remain that distance from each other.
If you want to do something really custom, the three buttons in the lower-right corner of the nib editor will let you create any constraint you want. What you have selected determines what constraints you can create; the nib editor's outline view will help you make sure you have the selection you want.
You are going to have to iterate through all of your subviews and change their frame positions based on the delta of your window frame.
so if you expand your window frame by 20 in all directions, all your subviews are going to have to increase their frame positions by (20,20) to offset the windows movement.

Rectangles & Parsing in vb.net

This is kinda....a two part question. The first one is much more important than the second one, both of these are in the same project, and in vb.net.
How can I constrain the bounds of a rectangle object, which is controlled by a mouse, so it cannot be drawn outside a PictureBox? It is kindof a standard lasso control, the user can click and drag and it will draw a box from the initial click point to the mouse's current location. The starting point is at (rectX,rectY), and the box is drawn to the bottom right using rectDimX and rectDimY (to set the width and height) to see how much of a change has occurred with the mouse. Basically, its what you get with a click and drag on a Windows desktop. The issue here is that the rectangle is able to be drawn outside the PictureBox it is being drawn on, and the next part of the code attempts to reference this location, and then fails with an OutOfMemory exception. This leads me to my second question:
How can I make the rectangle draw in more than the fourth quadrant, which is only positive numbers? If it goes anywhere else, it does not show the rectangle, though it does still have the correct values. I know i could code this four times based on starting location and mouse location, but that would be a huge hassle and a rewrite of the whole rectangle code.
Is there an easy solution for either of these? The first one is a much bigger hassle, as it will be very time consuming if there is no easy way.
Thanks for the help!
For the first part of your question, even if the user drags the mouse beyond the edge of your picture box, you don't have to use those coordinates for your drawing routine. Simply do something like
If (DrawingPoint.X > PictureBox.Right)
DrawingPoint.X = PictureBox.Right // Right-hand limit of picture box
End If
And similar for the Y direction.
As for the negative numbers while drawing, you want to translate screen coordinates to client area coordinates. Have a look at ScreenToClient and ClientToScreen.

Draw Lines on gtk.TextView

I'm trying to show the "selection" of a certain sub-string in a
gtk.TextView by drawing a border around the word. The only way to mark
text in a TextView that I've found so far is by placing TextTags with
modified properties. This does not seem to offer a way to draw a border,
though, DOES GTK SUPPORT THIS OR IS THIS A PROBLEM WITH ONLT PYGTK
I figured out how to draw on a text view !!!
To begin with lets assume the reference to your gtk.TextView is in a variable called viewer, Inside one of ur classes
Also the draw function has to be called with an event called expose-event else the drawings will be refreshed and will not stay on the screen
The next part is the gtk.TextView consists of 7 types of gtk.gdk.windows on which u can draw
gtk.TEXT_WINDOW_WIDGET
gtk.TEXT_WINDOW_TEXT
gtk.TEXT_WINDOW_LEFT - not displayed by default
gtk.TEXT_WINDOW_RIGHT - not displayed by default
gtk.TEXT_WINDOW_TOP - not displayed by default
gtk.TEXT_WINDOW_BOTTOM
gtk.TEXT_WINDOW_PRIVATE
For the drawing to appear on gtk.TextView We have to draw on gtk.TEXT_WINDOW_TEXT
An Example Code is as shown Below
if(viewer!=None):
viewer.connect("expose-event", expose_view)
self.drawable=viewer.get_window(gtk.TEXT_WINDOW_TEXT)
def expose_view(self,window,event):
if(self.drawable!=None):
self.drawable.draw_line(self.drawable.new_gc(),1,1,30,30)
# (1,1) and (30,30) are the coordinates and u can give the values accordingly
In a gtk.TextBuffer tags are used to set one or more pre-defined text attributes. Without subclassing, this is limited to the properties of a gtk.TextTag, and doesn't include anything akin to a border or outline property. There is no difference between PyGTK and plain GTK+ in this regard.
While somewhat hacky, the easiest way to do what you want to do is to connect to the expose-event of your gtk.TextView, get the coordinates of your string and draw on event.window, which is the gdk.Window of the event provided in the expose callback.
(Note that you don't have to get and store the gtk.TEXT_WINDOW_TEXT window, you just need to check what window the expose event is for in the callback, probably ignoring the expose if it's not for the text window.)
Instead, you could presumably subclass one or more of TextBuffer/TextView/TextTag to add a border tag, but whether it's reasonable to do so is another question.