Search Icon

Creating a real report

A report was requested that would show all of the applied loads (source loads) applied to a pole. This excludes reactions to the loads so applied by guying are excluded as are the loads generated by the pole itself (wind load, self weight, load from tilt, etc.).

The following video shows in real-time the creation of this report and describes the processes and concepts involved.

Here is the complete source code of the report for those interested in examining it further.

  1. using System ;
  2. using System.Drawing ;
  3. using System.Collections.Generic ;
  4. using System.Collections ;
  5. using System.Collections.Specialized ;
  6. using System.Data ;
  7. using System.Data.SqlClient ;
  8. using System.Data.Common ;
  9. using System.Linq.Expressions ;
  10. using System.Linq ;
  11. using System.Text ;
  12. using System.Threading.Tasks ;
  13. using System.Windows.Forms ;
  14. using System.IO ;
  15. using System.Xml ;
  16. using WeifenLuo.WinFormsUI.Docking ;
  17. using PPL_Lib ;
  18. using MigraDoc ;
  19. using MD = MigraDoc . DocumentObjectModel ;
  20. using MDT = MigraDoc . DocumentObjectModel . Tables ;
  21.  
  22. namespace OCalcProReporting
  23. {
  24.  
  25.     public static class ReportFont
  26.     {
  27.         public static double cPageWidth = 6.25 ;
  28.         public static string cFontName = "Arial" ;
  29.         public static MD . Unit cFontSizeLarge = MD . Unit . FromPoint ( 9.75 ) ;
  30.         public static MD . Unit cFontSizeSmall = MD . Unit . FromPoint ( 7.85 ) ;
  31.     }
  32.  
  33.     public partial class Report : PPL_Lib . ReportTemplate
  34.     {
  35.  
  36.         //globally defined colors and fonts
  37.         MD . Color Yellow = MD . Colors . LightYellow ;
  38.         MD . Color White = MD . Colors . White ;
  39.         MD . ParagraphAlignment JustifyRight = MD . ParagraphAlignment . Right ;
  40.         MD . ParagraphAlignment JustifyLeft = MD . ParagraphAlignment . Left ;
  41.         MD . ParagraphAlignment JustifyCenter = MD . ParagraphAlignment . Center ;
  42.         MD . Font SmallFont = new MD . Font (ReportFont . cFontName, ReportFont . cFontSizeSmall ) ;
  43.         MD . Font StandardFont = new MD . Font (ReportFont . cFontName, ReportFont . cFontSizeLarge ) ;
  44.         FontModifier Bold = new FontModifier ( true, false, false ) ;
  45.  
  46.  
  47.         //implement more than one additional report subtype (total will be this number plus the master)
  48.         public override int SubtypesCount { get { return 0 ; } }
  49.  
  50.         public override REPORT_TYPE Type { get { return REPORT_TYPE . INTEGRATED ; } }
  51.         public override String Name { get { return "Applied Loads Summary" ; } }
  52.         public override String Description { get { return Name ; } }
  53.  
  54.         //make sure to implement ToString to show report name
  55.         public override String ToString ( ) { return Name ; }
  56.  
  57.         //determine if this report is applicable for a structure
  58.         public override bool IsApplicable (PPLMain pPPLMain, PPLPole pPole )
  59.         {
  60.             if (Filtered ) return false ;
  61.             return true ;
  62.         }
  63.         public override bool IsApplicableForType (PPLMain . POLE_TYPE pType )
  64.         {
  65.             if (Filtered ) return false ;
  66.             return true ;
  67.         }
  68.  
  69.         MigraDoc . DocumentObjectModel . Document cDocument = null ;
  70.         PPLMain cPPLMain = null ;
  71.         MDT . Table cCurrentTable = null ;
  72.         MDT . Row cCurrentRow = null ;
  73.         MD . Unit cMaxRowHeight = 0 ;
  74.  
  75.         //methods to create integrated report
  76.         public override void CreateReport (PPLMain pPPLMain, List <FileInfo > pSelectedFiles )
  77.         {
  78.             cPPLMain = pPPLMain ;
  79.             cDocument = new MigraDoc . DocumentObjectModel . Document ( ) ;
  80.             MD . Section section = cPPLMain . BuildStandardReportHeader (cDocument, Name, true ) ;
  81.             cDocument . DefaultPageSetup . Orientation = MD . Orientation . Portrait ;
  82.             cDocument . LastSection . PageSetup . Orientation = MigraDoc . DocumentObjectModel . Orientation . Portrait ;
  83.             MigraDoc . DocumentObjectModel . Paragraph paragraph = null ;
  84.             paragraph = section . AddParagraph ( "\n" ) ;
  85.             paragraph . Format . Borders . Top . Color = MigraDoc . DocumentObjectModel . Colors . Blue ;
  86.             paragraph . Format . Borders . Top . Width = new MigraDoc . DocumentObjectModel . Unit ( 0.025, MigraDoc . DocumentObjectModel . UnitType . Inch ) ;
  87.         }
  88.  
  89.         public override void AddPole (PPLPole pPole, String pPoleName )
  90.         {
  91.  
  92.  
  93.             PoleLoadInfo poleInfoMaster = cPPLMain . CurrentPoleLoadInfo ;
  94.  
  95.             CreateTable (ReportFont . cPageWidth, 4 ) ;
  96.             cCurrentTable . Format . Font = SmallFont . Clone ( ) ;
  97.             cCurrentTable . Borders . Visible = true ;
  98.  
  99.             PPLPole pole = cPPLMain . GetPole ( ) ;
  100.  
  101.             List <ForceSummary > loads = new List <ForceSummary > ( ) ;
  102.  
  103.             foreach (PPLElement elem in pole . Children )
  104.             {
  105.                 ForceSummary fs = elem . BuildForceSummaryIncludingChildren (poleInfoMaster . cLAC, PPLElement . FORCE_SUMMARY_MODE . MAX_PRECISION ) ;
  106.                 if (fs . ForceAxisA == 0 && fs . ForceAxisB == 0 ) continue ;
  107.                 loads . Add (fs ) ;
  108.             }
  109.  
  110.             loads . Sort ( delegate (ForceSummary f1, ForceSummary f2 )
  111.             {
  112.                 return f2 . cHeightOfForceApplicationAboveGLinInches . CompareTo (f1 . cHeightOfForceApplicationAboveGLinInches ) ;
  113.             } ) ;
  114.  
  115.  
  116.             if (PPLGridModel . Attribute . UnitsConvention == PPLGridModel . Attribute . UNITS_CONVENTION . METRIC )
  117.             {
  118.                 AddRow (Cell ( "Height (M)" ), Cell ( "Force A (N)" ), Cell ( "Force B (N)" ), Cell ( "Force V (N)" ) ) ;
  119.                 foreach (ForceSummary fs in loads )
  120.                 {
  121.                     AddRow (
  122.                         Cell (PPLGridModel . Attribute . InchesToMeters (fs . cHeightOfForceApplicationAboveGLinInches ) . ToString ( "0.##" ) ),
  123.                         Cell (PPLGridModel . Attribute . PoundsToNewtons (fs . ForceAxisA ) . ToString ( "0.##" ) ),
  124.                         Cell (PPLGridModel . Attribute . PoundsToNewtons (fs . ForceAxisB ) . ToString ( "0.##" ) ),
  125.                         Cell (PPLGridModel . Attribute . PoundsToNewtons (fs . ForceVertical ) . ToString ( "0.##" ) ) ) ;
  126.                 }
  127.             }
  128.             else
  129.             {
  130.                 AddRow (Cell ( "Height (ft)" ), Cell ( "Force A (lbs)" ), Cell ( "Force B (lbs)" ), Cell ( "Force V (lbs)" ) ) ;
  131.                 foreach (ForceSummary fs in loads )
  132.                 {
  133.                     AddRow (
  134.                         Cell (PPLGridModel . Attribute . InchesToFeet (fs . cHeightOfForceApplicationAboveGLinInches ) . ToString ( "0.##" ) ),
  135.                         Cell (fs . ForceAxisA . ToString ( "0.##" ) ),
  136.                         Cell (fs . ForceAxisB . ToString ( "0.##" ) ),
  137.                         Cell (fs . ForceVertical . ToString ( "0.##" ) ) ) ;
  138.                 }
  139.             }
  140.  
  141.             cCurrentTable . BottomPadding = MD . Unit . FromInch ( 0.03 ) ;
  142.             cCurrentTable . TopPadding = MD . Unit . FromInch ( 0.03 ) ;
  143.  
  144.             FinalizeTable ( ) ;
  145.             cDocument . LastSection . AddParagraph ( "\n" ) ;
  146.  
  147.         }
  148.  
  149.         public override MigraDoc . DocumentObjectModel . Document GetReport ( )
  150.         {
  151.             System.Diagnostics . Debug . Assert (Type == REPORT_TYPE . INTEGRATED || Type == REPORT_TYPE . BULK_SUMMARY ) ;
  152.             return cDocument ;
  153.         }
  154.  
  155.         //display standalone report
  156.         public override void ShowReport (PPLMain pPPLMain, PPLPole pPole )
  157.         {
  158.             System.Diagnostics . Debug . Assert (Type == REPORT_TYPE . STANDALONE ) ;
  159.             throw new NotImplementedException ( "Report is not REPORT_TYPE.STANDALONE" ) ;
  160.         }
  161.  
  162.         //housekeeping
  163.         public override void Reset ( )
  164.         {
  165.             cPPLMain = null ;
  166.             cDocument = null ;
  167.         }
  168.  
  169.  
  170.  
  171.         private int cIndentStore = 0 ;
  172.         private int cIndent
  173.         {
  174.             set
  175.             {
  176.                 cIndentStore = Math . Max ( 0, value ) ;
  177.             }
  178.             get
  179.             {
  180.                 return cIndentStore ;
  181.             }
  182.         }
  183.  
  184.         private String Indent ( )
  185.         {
  186.             return new String ( '\xA0', cIndentStore * 3 ) ;
  187.         }
  188.  
  189.     }
  190. }

Contact your local Osmose professional.