Ejemplo n.º 1
0
        } //end of method InterpretePartFeature

        private void InterpreteSketch(Sketch actualSketch)
        {
            List <SketchEntity> sketchEntities = MasterM.GetSketchParts(actualSketch);

            foreach (SketchEntity sketchEntity in sketchEntities)
            {
                InterpreteSketchEntity(sketchEntity);
            }

            //interprete sketchLine list of one sketch
            if (_needToInterpreteSketchLine)
            {
                listOfCodeLines.Add(Exporter.ExportPolygon(listOfSketchLines, NumberOfSketchEntities));
                _needToInterpreteSketchLine = false;
                listOfSketchLines.Clear();
            }

            // for text
            foreach (TextBox tbox in actualSketch.TextBoxes)
            {
                string entityType = "text";
                listOfCodeLines.Add(Exporter.ExportText(tbox, entityType + NumberOfSketchEntities));
                listOfEntityNamesOfOneSketch.Add(entityType + NumberOfSketchEntities);
                NumberOfSketchEntities++;
            }
        } //end of method InterpreteSketch
Ejemplo n.º 2
0
        /// <summary>
        /// Sherlock lets you Read all relevant Information for the jsCad processing from a PartDocument Inventor File
        /// </summary>
        /// <param name="suspect">your PartDocument you want to get information about</param>
        public Sherlock(PartDocument suspect, TransientGeometry transGeometry)
        {
            Partypart = new MasterM(suspect, transGeometry);

#if DEBUG
            //ShowTestDialoges();
            //Partypart.GetExtrudeFeatures();
            //List<RevolveFeature> toReturn = Partypart.GetRevolveFeatures();
#endif
        }
Ejemplo n.º 3
0
        //constructor
        public Shakespeare(MasterM masterModel, string savePathChosenByUser)
        {
            _jscadPath = savePathChosenByUser;

            //clear everything at start
            ListOfParameter.Clear();
            listOfEntityNamesOfOneSketch.Clear();
            listOfCodeLines.Clear();
            listOfObjectNames.Clear();

            //get list of partFeatures (extrudeFeatures & RevolveFeature)
            listOfObjects          = masterModel.GetFeatures();
            NumberOfSketchEntities = 1;
            _numberOfSketches      = 1;
            _numberOfSubtractions  = 0;
            _numberOfIntersections = 0;

            GenerateMainFunction();
            GenerateParameterFunction();
            WriteIntoJsFile();
        } //end of constructor
Ejemplo n.º 4
0
        //static int Main(string[] args)
        //{
        //    exportCircle();
        //    return 0;
        //}

        public Shakespeare(MasterM MM)
        {
            sketchyList = MM.SketchyList;
            outputFile  = new StreamWriter(jscadPath, true);

            using (outputFile)
            {
                outputFile.WriteLine("function main(){");
            }

            int i = 1;

            foreach (Sketch sketch in sketchyList)
            {
                List <SketchEntity> sketchParts = MM.SketchyParts(sketch);
                foreach (SketchEntity part in sketchyList)
                {
                    String var = "";
                    if (part is SketchCircle)
                    {
                        exportCircle((SketchCircle)part, "circle" + i);
                        var = "circle";
                    }
                    else if (part is SketchArc)
                    {
                        exportArc((SketchArc)part, "arc" + i);
                        var = "arc";
                    }
                    else if (part is SketchEllipse)
                    {
                        exportEllipseFull((SketchEllipse)part, "ellipse" + i);
                        var = "ellipse";
                    }
                    else if (part is SketchEllipticalArc)
                    {
                        exportEllipticalArc((SketchEllipticalArc)part, "ellipseArc" + i);
                        var = "ellipseArc";
                    }
                    varList.Add(var + i);
                    i++;
                }
            }
            using (outputFile)
            {
                outputFile.WriteLine("return [ ");
                double len   = varList.Count();
                int    count = 0;
                foreach (String name in varList)
                {
                    if (count == len - 1)
                    {
                        outputFile.WriteLine(name);
                    }
                    else
                    {
                        outputFile.WriteLine(name + ",");
                    }

                    count++;
                }
                outputFile.WriteLine("]; ");
            }
        }
Ejemplo n.º 5
0
        } //end of method IntersectOperation

        private string ExtrudeSketch(ExtrudeFeature extrudeFeature)
        {
            StringBuilder extrusionLine = new StringBuilder();

            MasterM.ExtrudeDirection direction = MasterM.GetDirection(extrudeFeature);
            string objectName = extrudeFeature.Name;
            string name       = "Extrusion" + _numberOfSketches;

            if (direction == MasterM.ExtrudeDirection.Positive)
            {
                if (extrudeFeature.ExtentType == PartFeatureExtentEnum.kDistanceExtent)
                {
                    //get length of extrusion
                    Inventor.Parameter param              = (extrudeFeature.Definition.Extent as DistanceExtent).Distance;
                    double             length             = param._Value * factor;
                    string             paramString        = "params." + name;
                    Parameter          extrusionParameter = new Parameter(name, "Length of " + name, "float", length, 0.1);
                    ListOfParameter.Add(extrusionParameter);

                    //with parameter:
                    extrusionLine.Append("\t" + "var " + objectName + " = sketch" + _numberOfSketches + ".extrude({ offset: [0,0," + paramString + "] });");
                    //without parameter:
                    //extrusionLine.Append("\t" + "var " + objectName + " = sketch" + _numberOfSketches + ".extrude({ offset: [0,0," + height.ToString(myCultureInfo) + "] });");
                }
                else //default: extruding with 10
                {
                    extrusionLine.Append("\t" + "var " + objectName + " = sketch" + _numberOfSketches + ".extrude({ offset: [0,0,10] });");
                }
            }
            else if (direction == MasterM.ExtrudeDirection.Negative)
            {
                if (extrudeFeature.ExtentType == PartFeatureExtentEnum.kDistanceExtent)
                {
                    //because when extruding in openjscad you cant choose a direction
                    //we extrude in the same direction but then translating same length in reversed direction

                    //get length of extrusion
                    Inventor.Parameter param              = (extrudeFeature.Definition.Extent as DistanceExtent).Distance;
                    double             length             = param._Value * factor;
                    string             paramString        = "params." + name;
                    Parameter          extrusionParameter = new Parameter(name, "Length of " + name, "float", length, 0.1);
                    ListOfParameter.Add(extrusionParameter);

                    //with parameter:
                    extrusionLine.Append("\t" + "var " + objectName + " = sketch" + _numberOfSketches + ".extrude({ offset: [0,0," + paramString + "] })");
                    extrusionLine.Append(TranslateObject("z", paramString, true));

                    //without parameter:
                    //extrusionLine.Append("\t" + "var " + objectName + " = sketch" + _numberOfSketches + ".extrude({ offset: [0,0," + height.ToString(myCultureInfo) + "] });");
                    //extrusionLine.Append(TranslateObject("z", height.ToString(myCultureInfo), true));
                }
                else //default: extruding with 10
                {
                    extrusionLine.Append("\t" + "var " + objectName + " = sketch" + _numberOfSketches + ".extrude({ offset: [0,0,10] });");
                }
            }
            else //if(direction == ExtrudeDirection.Symetric)
            {
                //extrude distance
                //translate distance/2
            }

            return(extrusionLine.ToString());
        } //end of method ExtrudeSketch
Ejemplo n.º 6
0
        } //end of method InterpretePartFeatures

        private void InterpretePartFeature(object partFeature)
        {
            switch (Microsoft.VisualBasic.Information.TypeName(partFeature))
            {
            case "ExtrudeFeature":
            {
                ExtrudeFeature extrudeFeature  = (ExtrudeFeature)partFeature;
                string         firstObjectName = extrudeFeature.Name;
                string         secondObjectName;

                //no matter which operation will be executed, object gets created
                listOfCodeLines.Add(ExtrudeSketch(extrudeFeature));

                switch (extrudeFeature.Operation)
                {
                //this is new extrusion or revolve
                case PartFeatureOperationEnum.kNewBodyOperation:
                    listOfObjectNames.Add(firstObjectName);
                    break;

                case PartFeatureOperationEnum.kJoinOperation:
                    listOfObjectNames.Add(firstObjectName);
                    break;

                //this case uses new created object and will cut it with another object
                case PartFeatureOperationEnum.kCutOperation:

                    //TODO get other object name(s), which interfere with object
                    //method kinda works. not returning the name i am using
                    secondObjectName = string.Join(",", MasterM.GetAffectedBodyNames(extrudeFeature));

                    //old object gets deleted, new subtraction gets created which includs both objects
                    _numberOfSubtractions++;
                    listOfObjectNames.Remove(secondObjectName);
                    listOfObjectNames.Add("Subtraction" + _numberOfSubtractions);
                    CutOperation(secondObjectName, firstObjectName);
                    break;

                //this case uses new created object and will intersect it with another object
                case PartFeatureOperationEnum.kIntersectOperation:

                    //method kinda works. not returning the name i am using
                    secondObjectName = string.Join(",", MasterM.GetAffectedBodyNames(extrudeFeature));

                    //old object gets deleted, new intersection gets created which includs both objects
                    _numberOfIntersections++;
                    listOfObjectNames.Remove(secondObjectName);
                    listOfObjectNames.Add("Intersection" + _numberOfIntersections);
                    IntersectOperation(secondObjectName, firstObjectName);
                    break;
                }
            }
            break;

            case "RevolveFeature":
            {
                //revolving is not really working like in inventor. openjscad is always revolving around y-axis
                //so when revolveFeature is used we will create it but it will be at a different spot
                //and maybe interfere with another object
                var    revolveFeature  = (RevolveFeature)partFeature;
                string firstObjectName = revolveFeature.Name;

                //no matter which operation will be executed, object gets created
                listOfCodeLines.Add(RevolveSketch(revolveFeature));

                switch (revolveFeature.Operation)
                {
                case PartFeatureOperationEnum.kNewBodyOperation:
                    listOfObjectNames.Add(firstObjectName);
                    break;

                case PartFeatureOperationEnum.kJoinOperation:
                    listOfObjectNames.Add(firstObjectName);
                    break;

                case PartFeatureOperationEnum.kCutOperation:
                    listOfObjectNames.Add(firstObjectName);
                    break;

                case PartFeatureOperationEnum.kIntersectOperation:
                    listOfObjectNames.Add(firstObjectName);
                    break;
                }
            }
            break;
            }

            /*
             * //TODO
             * //find out in which layer the sketch is orientated, eg. XY, XZ or YZ
             * //then rotate sketch if possible
             *
             * bool needToRotate = true;
             * if (rotationIsNeeded)
             * {
             *  AppendToLastLineOfCode(RotateObject("x"));
             *
             * }
             *
             * //if sketch is not on BasePlane it has to be translated
             * bool needToTranslate = true;
             * if (needToTranslate)
             * {
             *  AppendToLastLineOfCode(TranslateObject("z", value, false));
             * }
             */
        } //end of method InterpretePartFeature