/// <summary> /// Drawing method used to draw factory content /// </summary> /// <param name="graphics">Graphic environment parameters</param> public void Draw(PicGraphics graphics, PicFilter filter) { graphics.Initialize(); // bounding box if (!graphics.DrawingBox.IsValid) { // compute bounding box using (PicVisitorBoundingBox visitor = new PicVisitorBoundingBox()) { ProcessVisitor(visitor); Box2D box = visitor.Box; box.AddMarginRatio(0.01); // set as drawing box graphics.DrawingBox = box; } } // first, draw cotation foreach (PicEntity entity in _entities) { try { // cotation PicCotation cotation = entity as PicCotation; if (cotation != null && !cotation.Deleted && filter.Accept(entity)) { cotation.Draw(graphics); } } catch (Exception ex) { _log.Error(ex.Message); } } // then other entities foreach (Object o in _entities) { try { // drawable entities PicDrawable drawable = o as PicDrawable; if (drawable != null && !drawable.Deleted && !(drawable is PicCotation) && filter.Accept(drawable)) { drawable.Draw(graphics); } } catch (Exception ex) { _log.Error(ex.Message); } } // cardboard format if (null != _cardboardFormat) { _cardboardFormat.Draw(graphics); } graphics.Finish(); }
public static void Generate(string pluginPath, out Image bmp, Size size, PicFilter filter) { // instantiate factory PicFactory factory = new PicFactory(); factory.Clear(); // instantiate plugin Pic.Plugin.PluginServices pluginHost = new Pic.Plugin.PluginServices(pluginPath); IPlugin plugin = pluginHost.GetFirstPlugin(); // generate entities ParameterStack stack = plugin.Parameters; plugin.CreateFactoryEntities(factory, stack); // get bounding box PicVisitorBoundingBox visitor = new PicVisitorBoundingBox(); factory.ProcessVisitor(visitor); // draw image PicGraphicsImage picImage = new PicGraphicsImage(); picImage.ImageSize = size; PicBox2D box = visitor.Box; box.AddMarginRatio(0.05); picImage.DrawingBox = box; factory.Draw(picImage, filter); bmp = picImage.Bitmap; }
public static Box2D BoundingBox(PicFactory factory, PicFilter filter, double marginRatio = 0.0) { var visitor = new PicVisitorBoundingBox() { TakePicBlocksIntoAccount = true }; factory.ProcessVisitor(visitor, filter); Box2D box = visitor.Box; if (box.IsValid && marginRatio > 0.0) { box.AddMarginRatio(marginRatio); } return(box); }
/// <summary> /// Removes entities that match a specific criterion (filter) /// </summary> /// <param name="filter">Filter upon which entities are tested</param> public void Remove(PicFilter filter) { // build list of entities to remove List <PicEntity> entitiesToRemove = new List <PicEntity>(); foreach (PicEntity entity in _entities) { if (filter.Accept(entity)) { entitiesToRemove.Add(entity); } } // removes entities foreach (PicEntity entity in entitiesToRemove) { _entities.Remove(entity); } }
public void ProcessVisitor(PicFactoryVisitor visitor, PicFilter filter) { visitor.Initialize(this); foreach (PicEntity entity in _entities) { try { if (entity != null && !entity.Deleted && filter.Accept(entity)) { visitor.ProcessEntity(entity); } } catch (Exception ex) { _log.Error(ex.Message); } } visitor.Finish(); }
public PicFilterAnd(PicFilter filter1, PicFilter filter2) { _filter1 = filter1; _filter2 = filter2; }
public PicFilterNot(PicFilter filter) { _filter = filter; }
public PicFilterOr(PicFilter filter1, PicFilter filter2) { _filter1 = filter1; _filter2 = filter2; }
/// <summary> /// Drawing method used to draw factory content /// </summary> /// <param name="graphics">Graphic environment parameters</param> public void Draw(PicGraphics graphics, PicFilter filter) { graphics.Initialize(); // bounding box if (!graphics.DrawingBox.IsValid) { try { // compute bounding box graphics.DrawingBox = Tools.BoundingBox(this, filter, 0.025); } catch (Exception /*ex*/) { return; } } // first, draw cotation foreach (PicEntity entity in _entities) { try { // cotation if (entity is PicCotation cotation && !cotation.Deleted && filter.Accept(entity)) { cotation.Draw(graphics); } } catch (Exception ex) { _log.Error(ex.Message); } } // then other entities foreach (object o in _entities) { try { // drawable entities if (o is PicDrawable drawable && !drawable.Deleted && !(drawable is PicCotation) && filter.Accept(drawable)) { drawable.Draw(graphics); } } catch (Exception ex) { _log.Error(ex.Message); } } // cardboard format if (null != _cardboardFormat) { _cardboardFormat.Draw(graphics); } graphics.Finish(); }