예제 #1
0
        public static void UpdateExistingEntries(string path)
        {
            List <string>   filenames = Directory.EnumerateFiles(path, "*.geomData").ToList();
            ParallelOptions po        = new ParallelOptions();

            Parallel.ForEach(filenames, po, (filename) =>
            {
                try
                {
                    var db = new PraxisContext();
                    Log.WriteLog("Loading " + filename);
                    var entries = GeometrySupport.ReadStoredElementsFileToMemory(filename); //tagsData file loaded automatically here.
                    Log.WriteLog(entries.Count() + " entries to update in database for " + filename);
                    db.UpdateExistingEntries(entries);
                    File.Move(filename, filename + "Done");
                    Log.WriteLog(filename + " completed at " + DateTime.Now);
                }
                catch (Exception ex)
                {
                    Log.WriteLog("Error multithreading: " + ex.Message + ex.StackTrace, Log.VerbosityLevels.Errors);
                }
            });
        }
예제 #2
0
        static public TrussInfo BuildTrussAtRidge(XYZ currentPointOnRidge, EdgeInfo currentEdgeInfo, IList <XYZ> currentSupportPoints)
        {
            TrussInfo trussInfo = null;

            XYZ currentTopPoint = currentEdgeInfo.GetTrussTopPoint(currentPointOnRidge);

            //If we cant get the point that means that the projection failed
            if (currentTopPoint == null)
            {
                return(trussInfo);
            }

            if (currentSupportPoints == null || currentSupportPoints.Count == 0)
            {
                currentSupportPoints = currentEdgeInfo.ProjectSupportPointsOnRoof(currentPointOnRidge);
            }

            if (currentSupportPoints.Count == 0)
            {
                if (currentEdgeInfo.RoofLineType != RoofLineType.Ridge)
                {
                    return(trussInfo);
                }

                IList <EdgeInfo> endConditionList = currentEdgeInfo.GetEndConditions(1);

                if (endConditionList.Count != 2)
                {
                    return(trussInfo);
                }

                EdgeInfo edge0 = endConditionList[0];
                EdgeInfo edge1 = endConditionList[1];

                if ((edge0.RoofLineType != RoofLineType.Valley && edge0.RoofLineType != RoofLineType.Gable) ||
                    edge1.RoofLineType != RoofLineType.Valley && edge1.RoofLineType != RoofLineType.Gable)
                {
                    return(trussInfo);
                }

                Line line0 = edge0.Curve as Line;
                Line line1 = edge1.Curve as Line;

                if (line0 == null || line1 == null)
                {
                    return(trussInfo);
                }

                double height = currentEdgeInfo.GetCurrentRoofHeight();

                Line currentRigeLine  = currentEdgeInfo.Curve as Line;
                XYZ  rigePointFlatten = new XYZ(currentTopPoint.X, currentTopPoint.Y, height);
                XYZ  intersectingPointValleyOrGable0 = GeometrySupport.GetRoofIntersectionFlattenLines(currentRigeLine, currentTopPoint, line0, height);
                XYZ  intersectingPointValleyOrGable1 = GeometrySupport.GetRoofIntersectionFlattenLines(currentRigeLine, currentTopPoint, line1, height);

                if (intersectingPointValleyOrGable0 == null || intersectingPointValleyOrGable1 == null)
                {
                    return(trussInfo);
                }

                //TODO Change this to the double of max distance between Trusses
                double maxDistance   = 20;
                XYZ    supportPoint0 = currentEdgeInfo.GetSupportPoint(intersectingPointValleyOrGable0, currentRigeLine.Direction, maxDistance);
                XYZ    supportPoint1 = currentEdgeInfo.GetSupportPoint(intersectingPointValleyOrGable1, currentRigeLine.Direction, maxDistance);

                if (supportPoint0 == null || supportPoint1 == null)
                {
                    return(trussInfo);
                }

                currentTopPoint = GeometrySupport.AdjustTopPointToRoofAngle(currentTopPoint, new List <XYZ> {
                    supportPoint0, supportPoint1
                }, currentEdgeInfo);
                trussInfo = GeometrySupport.GetTrussInfo(currentTopPoint, supportPoint0, supportPoint1);

                if (trussInfo == null)
                {
                    return(trussInfo);
                }

                return(trussInfo);
            }
            else if (currentSupportPoints.Count == 1)
            {
                if (currentEdgeInfo.RoofLineType != RoofLineType.RidgeSinglePanel)
                {
                    return(trussInfo);
                }

                XYZ projectedPointOnEave  = currentSupportPoints[0];
                XYZ projectedPointOnRidge = new XYZ(currentTopPoint.X, currentTopPoint.Y, projectedPointOnEave.Z);

                currentTopPoint = GeometrySupport.AdjustTopPointToRoofAngle(currentTopPoint, new List <XYZ> {
                    projectedPointOnEave
                }, currentEdgeInfo);
                double height = currentTopPoint.DistanceTo(projectedPointOnRidge);

                trussInfo = new TrussInfo(projectedPointOnEave, projectedPointOnRidge, height);
                trussInfo.TopChords.Append(Line.CreateBound(currentTopPoint, projectedPointOnEave));
                trussInfo.BottomChords.Append(Line.CreateBound(projectedPointOnRidge, projectedPointOnEave));
                //Document doc = CurrentRoof.Document;
                //FamilySymbol fs = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericModel).WhereElementIsElementType().Where(type => type.Name.Contains("DebugPoint2")).FirstOrDefault() as FamilySymbol;
                //doc.Create.NewFamilyInstance(projectedPointOnEave, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
                //doc.Create.NewFamilyInstance(projectedPointOnRidge, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
                //doc.Create.NewFamilyInstance(currentTopPoint, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);

                return(trussInfo);
            }
            else if (currentSupportPoints.Count == 2)
            {
                if (currentEdgeInfo.RoofLineType != RoofLineType.Ridge)
                {
                    return(trussInfo);
                }

                XYZ firstPointOnEave  = currentSupportPoints[0];
                XYZ secondPointOnEave = currentSupportPoints[1];

                if (firstPointOnEave == null || secondPointOnEave == null)
                {
                    return(trussInfo);
                }

                currentTopPoint = GeometrySupport.AdjustTopPointToRoofAngle(currentTopPoint, new List <XYZ> {
                    firstPointOnEave, secondPointOnEave
                }, currentEdgeInfo);
                trussInfo = GeometrySupport.GetTrussInfo(currentTopPoint, firstPointOnEave, secondPointOnEave);

                if (trussInfo == null)
                {
                    return(trussInfo);
                }
                //Document doc = CurrentRoof.Document;
                //FamilySymbol fs = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericModel).WhereElementIsElementType().Where(type => type.Name.Contains("DebugPoint2")).FirstOrDefault() as FamilySymbol;
                //doc.Create.NewFamilyInstance(firstPointOnEave, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
                //doc.Create.NewFamilyInstance(secondPointOnEave, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
                //doc.Create.NewFamilyInstance(currentTopPoint, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);

                return(trussInfo);
            }

            return(trussInfo);
        }
예제 #3
0
        static public TrussInfo BuildTrussAtHip(XYZ currentPointOnHip, EdgeInfo currentEdgeInfo, Element firstSupport, Element secondSupport)
        {
            TrussInfo trussInfoToReturn = null;

            if (!(firstSupport.Location is LocationCurve) || !(secondSupport.Location is LocationCurve))
            {
                return(trussInfoToReturn);
            }

            Line hipLine = currentEdgeInfo.Curve as Line;
            Line firstSupportLocationLine  = (firstSupport.Location as LocationCurve).Curve as Line;
            Line secondSupportLocationLine = (secondSupport.Location as LocationCurve).Curve as Line;

            if (firstSupportLocationLine == null || secondSupportLocationLine == null || hipLine == null)
            {
                return(trussInfoToReturn);
            }


            //Relocate the placement of the truss to the center of the Hip subtracting the intersection of the supports
            XYZ intersectiongOfSupports = firstSupportLocationLine.GetFlattenIntersection(secondSupportLocationLine);

            if (intersectiongOfSupports == null)
            {
                return(trussInfoToReturn);
            }

            XYZ higherHipPoint = currentEdgeInfo.Curve.GetEndPoint(0);
            XYZ lowerHipPoint  = currentEdgeInfo.Curve.GetEndPoint(1);

            if (higherHipPoint.Z < lowerHipPoint.Z)
            {
                higherHipPoint = lowerHipPoint;
            }

            Line newHipLine = Line.CreateBound(higherHipPoint, intersectiongOfSupports).Flatten();

            //TODO get this offset by the UI, if no offset is applied, the trusses from two hips will collide
            double TRUSS_HIP_OFFSET     = Utils.Utils.ConvertM.cmToFeet(15);
            double centerParameter      = newHipLine.ComputeRawParameter(0.5);
            XYZ    newLineTrussPosition = newHipLine.Evaluate(centerParameter + TRUSS_HIP_OFFSET, false);

            //DEBUG.CreateDebugPoint(currentEdgeInfo.CurrentRoof.Document, newLineTrussPosition);

            IntersectionResultArray iResultArr = null;

            currentEdgeInfo.Curve.Intersect(Line.CreateUnbound(newLineTrussPosition, XYZ.BasisZ), out iResultArr);

            if (iResultArr == null || iResultArr.Size < 1)
            {
                return(trussInfoToReturn);
            }

            currentPointOnHip = iResultArr.get_Item(0).XYZPoint;
            //DEBUG.CreateDebugPoint(currentEdgeInfo.CurrentRoof.Document, currentPointOnHip);
            ///////////////////////


            Line currentPointCrossLine = Line.CreateBound(currentPointOnHip, currentPointOnHip.Add(hipLine.Flatten().Direction.CrossProduct(XYZ.BasisZ)));

            //DEBUG.CreateDebugFlattenLine(currentEdgeInfo.CurrentRoof.Document, currentPointCrossLine);
            //DEBUG.CreateDebugFlattenLine(currentEdgeInfo.CurrentRoof.Document, firstSupportLocationLine);
            //DEBUG.CreateDebugFlattenLine(currentEdgeInfo.CurrentRoof.Document, secondSupportLocationLine);

            XYZ firstSupportPoint  = currentPointCrossLine.GetFlattenIntersection(firstSupportLocationLine, true, false);
            XYZ secondSupportPoint = currentPointCrossLine.GetFlattenIntersection(secondSupportLocationLine, true, false);

            if (firstSupportPoint == null || secondSupportPoint == null)
            {
                return(trussInfoToReturn);
            }

            double roofHeight = currentEdgeInfo.GetCurrentRoofHeight();

            firstSupportPoint  = new XYZ(firstSupportPoint.X, firstSupportPoint.Y, roofHeight);
            secondSupportPoint = new XYZ(secondSupportPoint.X, secondSupportPoint.Y, roofHeight);
            //DEBUG.CreateDebugPoint(currentEdgeInfo.CurrentRoof.Document, firstSupportPoint);
            //DEBUG.CreateDebugPoint(currentEdgeInfo.CurrentRoof.Document, secondSupportPoint);
            if (currentEdgeInfo.RoofLineType != RoofLineType.Hip)
            {
                return(trussInfoToReturn);
            }

            // currentTopPoint = GeometrySupport.AdjustTopPointToRoofAngle(currentTopPoint, new List<XYZ> { firstPointOnEave, secondPointOnEave }, currentEdgeInfo);
            trussInfoToReturn = GeometrySupport.GetTrussInfo(currentPointOnHip, firstSupportPoint, secondSupportPoint);

            return(trussInfoToReturn);
        }
예제 #4
0
        private static void loadProcessedData()
        {
            Log.WriteLog("Starting load from processed files at " + DateTime.Now);
            System.Diagnostics.Stopwatch fullProcess = new System.Diagnostics.Stopwatch();
            fullProcess.Start();
            PraxisContext db = new PraxisContext();

            db.Database.SetCommandTimeout(Int32.MaxValue);
            db.ChangeTracker.AutoDetectChangesEnabled = false;

            List <string> geomFilenames = Directory.EnumerateFiles(config["OutputDataFolder"], "*.geomData").ToList();
            List <string> tagsFilenames = Directory.EnumerateFiles(config["OutputDataFolder"], "*.tagsData").ToList();

            if (config["KeepElementsInMemory"] == "True") //ignore DB, doing some one-off operation.
            {
                //Skip database work. Use an in-memory list for a temporary operation.
                foreach (var fileName in geomFilenames)
                {
                    System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
                    Log.WriteLog("Loading " + fileName + " to memory at " + DateTime.Now);
                    var entries = File.ReadAllLines(fileName);
                    foreach (var entry in entries)
                    {
                        DbTables.Place stored = GeometrySupport.ConvertSingleTsvPlace(entry);
                        memorySource.Add(stored);
                    }

                    Log.WriteLog("File loaded to memory in " + sw.Elapsed);
                    sw.Stop();
                }
                foreach (var fileName in tagsFilenames)
                {
                    System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
                    Log.WriteLog("Loading " + fileName + " to memory at " + DateTime.Now);
                    var entries = File.ReadAllLines(fileName);
                    foreach (var entry in entries)
                    {
                        PlaceTags stored    = GeometrySupport.ConvertSingleTsvTag(entry);
                        var       taggedGeo = memorySource.First(m => m.SourceItemType == stored.SourceItemType && m.SourceItemID == stored.SourceItemId);
                        //MemorySource will need to be a more efficient collection for searching if this is to be a major feature, but this functions.
                        taggedGeo.Tags.Add(stored);
                    }

                    Log.WriteLog("File applied to memory in " + sw.Elapsed);
                    sw.Stop();
                }
                return;
            }
            else if (config["UseMariaDBInFile"] == "True") //Use the LOAD DATA INFILE command to skip the EF for loading.
            {
                foreach (var fileName in geomFilenames)
                {
                    System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
                    sw.Start();
                    var mariaPath = fileName.Replace("\\", "\\\\");
                    db.Database.ExecuteSqlRaw("LOAD DATA INFILE '" + mariaPath + "' IGNORE INTO TABLE Places fields terminated by '\t' lines terminated by '\r\n' (sourceItemID, sourceItemType, @elementGeometry, AreaSize, privacyId) SET elementGeometry = ST_GeomFromText(@elementGeometry) ");
                    sw.Stop();
                    Log.WriteLog("Geometry loaded from " + fileName + " in " + sw.Elapsed);
                    File.Move(fileName, fileName + "done");
                }

                foreach (var fileName in tagsFilenames)
                {
                    System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
                    sw.Start();
                    var mariaPath = fileName.Replace("\\", "\\\\");
                    db.Database.ExecuteSqlRaw("LOAD DATA INFILE '" + mariaPath + "' IGNORE INTO TABLE PlaceTags fields terminated by '\t' lines terminated by '\r\n' (SourceItemId, SourceItemType, `key`, `value`)");
                    sw.Stop();
                    Log.WriteLog("Tags loaded from " + fileName + " in " + sw.Elapsed);
                    File.Move(fileName, fileName + "done");
                }
            }
            else //Main path.
            {
                Parallel.ForEach(geomFilenames, fileName =>
                {
                    System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
                    sw.Start();
                    var db = new PraxisContext();
                    db.Database.SetCommandTimeout(Int32.MaxValue);
                    db.ChangeTracker.AutoDetectChangesEnabled = false;
                    var lines = File.ReadAllLines(fileName); //Might be faster to use streams and dodge the memory allocation?
                    foreach (var line in lines)
                    {
                        db.Places.Add(GeometrySupport.ConvertSingleTsvPlace(line));
                    }
                    db.SaveChanges();
                    sw.Stop();
                    Log.WriteLog("Geometry loaded from " + fileName + " in " + sw.Elapsed);
                    File.Move(fileName, fileName + "done");
                });
                Parallel.ForEach(tagsFilenames, fileName =>
                {
                    System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
                    sw.Start();
                    var db = new PraxisContext();
                    db.Database.SetCommandTimeout(Int32.MaxValue);
                    db.ChangeTracker.AutoDetectChangesEnabled = false;
                    var lines = File.ReadAllLines(fileName);
                    foreach (var line in lines)
                    {
                        db.PlaceTags.Add(GeometrySupport.ConvertSingleTsvTag(line));
                    }
                    db.SaveChanges();
                    sw.Stop();
                    Log.WriteLog("Tags loaded from " + fileName + " in " + sw.Elapsed);
                    File.Move(fileName, fileName + "done");
                });
            }

            fullProcess.Stop();
            Log.WriteLog("Files processed in " + fullProcess.Elapsed);
            fullProcess.Restart();
            db.RecreateIndexes();
            fullProcess.Stop();
            Log.WriteLog("Indexes generated in " + fullProcess.Elapsed);
        }
예제 #5
0
        internal XYZ GetTrussTopPoint(XYZ currentPointOnRidge)
        {
            if (RoofLineType == RoofLineType.Ridge)
            {
                return(currentPointOnRidge);
            }

            //If the is not a Ridge this MUST be a SinglePanelRidge
            if (RoofLineType == RoofLineType.RidgeSinglePanel)
            {
                return(currentPointOnRidge);
            }

            Line currentRidgeLine = Curve.Clone() as Line;

            if (currentRidgeLine == null)
            {
                throw new Exception("The ridge is not a straight line!");
            }

            ModelCurveArrArray sketchModels = CurrentRoof.GetProfiles();
            double             minDist      = double.MaxValue;
            ModelCurve         targetEave   = null;
            XYZ projectedPoint = null;

            double currentRoofTotalHeight = GetCurrentRoofHeight();

            foreach (ModelCurveArray currentCurveArr in sketchModels)
            {
                foreach (ModelCurve currentCurve in currentCurveArr)
                {
                    Curve targetGeoCurve = currentCurve.GeometryCurve;
                    Line  targetGeoLine  = targetGeoCurve as Line;

                    if (targetGeoLine == null)
                    {
                        throw new Exception("Eave is not a straight line");
                    }

                    targetGeoLine = targetGeoLine.Flatten(currentRoofTotalHeight);

                    double currentDist = targetGeoLine.Project(currentPointOnRidge).Distance;
                    if (currentDist < minDist)
                    {
                        minDist        = currentDist;
                        targetEave     = currentCurve;
                        projectedPoint = targetGeoLine.Project(currentPointOnRidge).XYZPoint;
                    }
                }
            }

            double overHang = 0;

            try { overHang = CurrentRoof.get_Overhang(targetEave); }
            catch { }

            XYZ ridgePointFlatten = new XYZ(currentPointOnRidge.X, currentPointOnRidge.Y, currentRoofTotalHeight);

            //We just need to get the side that the eave is to move the point to that direction
            //so we dont need to get a specific eave, lets just project the first one with infinite bounds to get the direction
            if (RelatedRidgeEaves == null || RelatedRidgeEaves.Count == 0)
            {
                RelatedRidgeEaves = GetRelatedEaves();
            }

            if (RelatedRidgeEaves == null || RelatedRidgeEaves.Count == 0)
            {
                throw new Exception("Related eave or eaves to current singleRidge was not found");
            }


            Curve eaveCurve = RelatedRidgeEaves[0].AsCurve();

            if (eaveCurve as Line == null)
            {
                throw new Exception("Related eave is not a straight line!");
            }

            Line eaveLine = eaveCurve as Line;

            XYZ lineIntersectionPoint = GeometrySupport.GetRoofIntersectionFlattenLines(currentRidgeLine, ridgePointFlatten, eaveLine, currentRoofTotalHeight);

            if (lineIntersectionPoint == null)
            {
                throw new Exception("No Intersection between eave could be estabilished!");
            }

            XYZ overHangdirection = Line.CreateBound(projectedPoint, lineIntersectionPoint).Direction.Normalize();
            XYZ pointOnOverhang   = projectedPoint.Add(overHangdirection.Multiply(overHang));

            //We will get the point on the overhang because if we are working with a single panel ridge it may have overhangs
            XYZ pointOnSupport = GetSupportPoint(pointOnOverhang, currentRidgeLine.Direction.Normalize());

            //Now we will shoot the point up on the Roof
            XYZ startingPoint = new XYZ(pointOnSupport.X, pointOnSupport.Y, pointOnSupport.Z - 1);
            ReferenceIntersector currentRefIntersect = new ReferenceIntersector(CurrentRoof.Id, FindReferenceTarget.Element, CurrentRoof.Document.ActiveView as View3D);
            ReferenceWithContext currenRefContext    = currentRefIntersect.FindNearest(startingPoint, XYZ.BasisZ);

            if (currenRefContext == null)
            {
                return(null);
            }

            XYZ projectedPointOnRoof = currenRefContext.GetReference().GlobalPoint;

            return(projectedPointOnRoof);
        }
예제 #6
0
        private byte[] FinishSlippyMapTile(ImageStats info, List <CompletePaintOp> paintOps, string tileKey, string styleSet)
        {
            byte[] results = null;
            results = MapTiles.DrawAreaAtSize(info, paintOps);

            if (!SaveMapTiles())
            {
                var db = new PraxisContext();
                var existingResults = db.SlippyMapTiles.FirstOrDefault(mt => mt.Values == tileKey && mt.StyleSet == styleSet);
                if (existingResults == null)
                {
                    existingResults = new SlippyMapTile()
                    {
                        Values = tileKey, StyleSet = styleSet, AreaCovered = Converters.GeoAreaToPolygon(GeometrySupport.MakeBufferedGeoArea(info.area))
                    };
                    db.SlippyMapTiles.Add(existingResults);
                }

                existingResults.ExpireOn = DateTime.Now.AddYears(10);
                existingResults.TileData = results;
                existingResults.GenerationID++;
                db.SaveChanges();
            }

            return(results);
        }