AutoCAD .NET: Filling a Region with a grid / custom hatch - c#

I want to fill a selected region with a custom hatch that looks like a grid (like a chess table). I tried to use the ANSI37 pattern but its lines are too dense and I could not modify anything visually except the angle of the hatch. Also, I tried the custom hatch pattern creation of autocad but loading the file in autocad or creating a hatch from it in my code always results in error.This is my question: Is there anyway I can create a custom hatch pattern (grid like) that I can control the distance of lines of the grid? Is it possible for me to retrieve the custom hatch object later then query info of its lines? (how many lines, start points and end points, distance between them...)
? Thank you in advance.

About customize the predefined hatch pattern: It is possible to do that, however the properties of the hatch must be defined in a certain order to have actual effect, or else it will be ignored and use the default value instead.
for example: in my case, I defined the value of HatchStyle before PatternScale and PatternSpace while it should be the other way around. Thus, I receive the result from the default values.
About the custom grid lines drawing and querying: I got some ideas from these:
http://adndevblog.typepad.com/autocad/2013/07/create-hatch-objects-using-trace-boundaries-using-net.html
using the Editor.TraceBoudary() method, I can retrieve the loops I needed with the outer most loop will be the last entry in the return DBObjectCollection (a Polyline object to be precise). Then, create the region that needed to be hatched and access its RegionAreaProperty.Extends to get the bottom-left and top-right point of the rectangle that contains my newly created region. After that
, I can implement my logic to draw the lines of the grid.
Note that this method only works on 2d loops ( regions, closed polylines, lines, curves... on Oxy plane). I haven't find a way for the Editor.TraceBoundary() to work with 3d loops yet.
Still open for advices and suggestion for 3d loops and creating custom hatch from a given HatchPattern object.

Related

Tangram puzzle application

I am trying to create a WPF application using C# to run on Pixelsense that is basic version of the tangram puzzle. I am able to draw my 7 shapes and translate and rotate them all around the screen.
Could anyone give me advise regarding how I should go about saving the pattern (with shapes in specific positions and orientations) so that when a user creates the pattern next time, the application can match it to the saved one and tell the user if it's correct.
It's a pattern matching and recognition problem that I am trying to solve.
I have been stuck on this for a while now :(
Define the solution as a collection of objects with shapeType, position, and orientation properties. Have the solution include one shape at position 0, 0 and an orientation of 0. Now loop over all the shapes the user has actually placed to find the ones with a shapeType that matches the shape your solution has at 0,0,0. Calculate the position and orientation of every other shape relative to where the user put this one. Compare those values to the rest of your solution. You'll need to experiment with how much tolerance to allow because this stuff is not precise - to make the game fun, err on the side of having high tolerances. If needed, you can follow this up with some performance optimizations to only re-evaluate pieces that moved.
Hopefully you are using physical shape prices with tags on them instead of this purely a virtual game. I always wanted to build this when I was on the Surface team but it never happened. One challenge you will run into is defining how the tag's position/orientation relates to the actual shape. If you'll be putting tag stickers on multiple tangram sets, you almost certainly won't get the on precisely the same each time so you may need to add a "calibration" mode to your app (have the user place each piece in a specific spot and then push a button so you can record where the tag is relative to those spots). The TagVisualizer WPF control should help a lot for building your UI - definitely look into using it (this scenario was top of mind when we designed that API). The default behavior of that control (if you tell it the ID of a tag to look for but not how to visualize it) is a "crosshair" that can help you find tune your offset values.
Good luck! If you wouldn't mind recording a YouTube video when you are done and posting a comment here linking to it, I'd really appreciate that
You can use ObservableCollection or List of a custom class. That class can consist of various values such as position, orientation etc as properties.
When a new pattern is drawn or when the pattern change its position you can update that particular object stored in the collection. As you have all the details of the pattern(positions and orientation) you can iterate the for loop and check the position of the new pattern when added.

ZedGraph - How to fill the area between two curves?

I've two curves. One of them is above the another. I've also set the IsSmooth to true (the lines are bent at the corners).
I want to fill the area between the top and bottom curveā€¦
What's the best method to do so?
I think using PolyObj is not a good idea because I have to store the points separately, and the final filled area is not smooth like the lines.
Here is a sample:

Drawing a map based on an array, and applying run time changes

I am writing a program to control a mobile robot. One of the things it has to do is to draw a map of the "world" as the robot senses it and apply changes in the map as it senses them.
It also has to highlight in some way the location of the robot and (ideally) the direction it points to.
I currently have an auto-updating array (100 x150) representing the map, using the following representations: 0 represents a clear path, 1 represents an obstacle.
I also have a variable containing the robot's location and next location.
What I need is to visualize it. I thought about using labels, but it is way too tedious using them, and the end result is not so pretty. My other possibility is to write all that data into an Excel spreadsheet, but then I will be back to square one: visualizing the data in an attractive way. Is there a drawing package of some sort that can do the job?
To sum it up:
Using:
- int[] MapArray //100 x 150 array representing the robot's world, and the data there is changing.
- Point[] Locations //Locations[0] is the current location, Locations[1] is the next step.
And I want to draw a map on a Windows Forms application that updates itself in a nice visual manner.
I hope my question is clear enough, don't hesitate to contact me if not!
Try Code: Drawing a Filled Rectangle on a Form (Visual C#) or something similar.
Graphics Programming Example Topics
Just write a couple of cycles which accesses every cell of an array and draws a rectangle on a form according to coords - that's the simplest way.
for(int i=0; i<100; i++)
{
for(int j=0;j<150;j++)
{
<access[i,j] and draw a rectangle with color accordingly to your contents.>
}
}
The same for the drawing location.
If you don't find any nice controls, you can always use a DataGridView with the column width = row height so that it always displays square cells. After that, just change the background color of the obstacles.
You could also look into observable collections for the map array so that the grid updates based on events rather than on timers. Make sure that you overwrite the observable collection to send the CollectionChanged event even when a cell changes its value, not only when adding/removing cells.

C#: Drawing only a portion of a path

I have a series of points in a GraphicsPath; for our purpose lets assume its the outline of an uppercase B. I want to be able to be able to draw only the bottom portion that would resemble an uppercase L.
I'd like to be able to select a window of points from the GraphicsPath. Is there a handy way to do this without doing point interpolation; ie have to write code to calculate slope math and possibly derivatives?
I don't believe that there's a way to actually tell the Graphics class to "stop" halfway through a path, or somehow create a new path that intersects with a bounding box (without implementing the method yourself), but if you're just doing this so you can draw a certain part of the path, then you should be able to achieve what you want by setting the clipping region.
See the Graphics.ClipBounds property, which takes a RectangleF, or Graphics.Clip, which is a Region (the former is generally easier to use, unless you already have a Region instance).
If you need to use the partial path for something else then I'm not aware of any built-in way to do it.

Implementing MS Access style 'relationships' GUI

I have no idea what the correct name for this UI style is. In MS Access the 'relationships' tool shows the db tables as little movable boxes that can be linked with lines. It's the same with Visio and a few audio apps - boxes that are movable, containing lines of text that can be joined together in a meaningful way.
How could I create a similar thing in .NET using Visual Studio 2008 and C#? I've never created my own controls before.
Here's an image of the sort of thing I mean: Click for example
You'll need two main custom controls: the main view and the table control.
The table control is responsible for drawing itself with all of its columns and ensuring that the item can scroll if need be. It is also responsible for providing an x/y co-ordinate for a specified row header. This is so that the relationship lines can match up to the correct row.
The main view is responsible for accepting a list of table objects (stored in a custom table object), creating the same number of table controls and arranging them in a specified order. It is also responsible for drawing the lines between the table controls.
All in all, this is not trivial. You'll want to override the OnPaint() method of both these controls to do all this custom drawing. Do some research on the GDI+ graphics routines to find out what methods you can use to draw this. You'll probably be using these objects/methods most often:
Pen
SolidBrush
LinearGradientBrush
DrawRectangle()
FillRectangle()
DrawString()
DrawImage()
DrawLine()
DrawPath()
You'll also need to trap all kinds of mouse events to enable moving the controls around. This can be done by overriding methods such as OnMouseDown or OnMouseMove.
Good luck.
The diagram you are trying to draw is an ERD or Database design. What you might also be looking for is a Class Diagram.
What you are trying to do is pretty complex.
Here are some links that might help. These are all open source type UML tools that do diagraming.
http://imar.spaanjaars.com/501/automatically-generating-class-diagrams-from-a-type-using-reflection
http://www.codebydesign.com/
http://sourceforge.net/projects/use-case-maker/
http://projects.gnome.org/dia/
http://www.monouml.org/doku.php?id=documentation

Categories

Resources