예제 #1
0
 public LevelSetLogger(XModel model, TrackingExteriorCrackLSM lsm, string outputDirectory)
 {
     this.model           = model;
     this.lsm             = lsm;
     this.outputDirectory = outputDirectory;
     this.vtkMesh         = new VtkMesh <XNode>(model.Nodes, model.Elements);
 }
예제 #2
0
 public EnrichmentLogger(XModel model, TrackingExteriorCrackLSM lsm, string outputDirectory)
 {
     this.model           = model;
     this.lsm             = lsm;
     this.outputDirectory = outputDirectory;
     iteration            = 0;
 }
예제 #3
0
        private void CreateCrack(double elementSize, XModel model, BidirectionalMesh2D <XNode, XContinuumElement2D> mesh,
                                 double jIntegralRadiusRatio)
        {
            var propagator = new Propagator(mesh, jIntegralRadiusRatio, new HomogeneousMaterialAuxiliaryStates(material),
                                            new HomogeneousSIFCalculator(material), new MaximumCircumferentialTensileStressCriterion(),
                                            new ConstantIncrement2D(1.5 * jIntegralRadiusRatio * elementSize));
            var crack = new TrackingExteriorCrackLSM(propagator);

            crack.Mesh = mesh;

            // Create enrichments
            crack.CrackBodyEnrichment = new CrackBodyEnrichment2D(crack, new SignFunctionOpposite2D());
            crack.CrackTipEnrichments = new CrackTipEnrichments2D(crack, CrackTipPosition.Single);
            //crackTip = new CrackTip2D(CrackTip2D.TipCurvePosition.CurveStart, polyline, new SingleElementEnrichment(),
            //    2.0, new HomogeneousMaterialAuxiliaryStates(globalHomogeneousMaterial),
            //    new HomogeneousSIFCalculator(globalHomogeneousMaterial));

            // Mesh geometry interaction
            var crackMouth = new CartesianPoint(beamLength, 0.5 * beamHeight);
            var crackTip   = new CartesianPoint(0.5 * beamLength, 0.5 * beamHeight);

            crack.InitializeGeometry(crackMouth, crackTip);
            crack.UpdateEnrichments(); //TODO: elements are not enriched properly.

            this.Crack      = crack;
            this.Propagator = propagator;
        }
        public static void TestJIntegral(int numElemX, int numElemY, double jIntegralRadiusRatio,
                                         double expectedJIntegral, double expectedSifMode1)
        {
            // Analyze the model
            var dcb = new DoubleCantileverBeam();

            dcb.CreateModel(numElemX, numElemY, jIntegralRadiusRatio);
            XModel model = dcb.Model;
            TrackingExteriorCrackLSM crack = dcb.Crack;

            (IVectorView globalU, IMatrixView globalK) = dcb.SolveModel();
            var freeDisplacementsPerSubdomain = new Dictionary <int, Vector>();

            freeDisplacementsPerSubdomain[model.Subdomains.First().Key] = (Vector)globalU;
            (double jIntegral, double sifMode1) = dcb.Propagate(freeDisplacementsPerSubdomain);

            // Check the results. For now, they are allowed to be more accurate.
            double tolerance = 1E-6;

            Assert.InRange(Math.Round(jIntegral, 3), 2.100, expectedJIntegral); // All
            Assert.InRange(Math.Round(sifMode1, 3), 2148.000, expectedSifMode1);

            //TODO: Find out why not all cases satisfy these
            //Assert.Equal(expectedJIntegral, Math.Round(jIntegral, 3));
            //Assert.Equal(expectedSifMode1, Math.Round(sifMode1, 3));
        }
예제 #5
0
 public void InitializeModel()
 {
     Model = new XModel();
     CreateMesh();
     ApplyBoundaryConditions();
     InitializeCrack();
 }
 /// <summary>
 /// Create the current type as class definition.
 /// </summary>
 protected override void CreateClassDefinition(DexTargetPackage targetPackage, ClassDefinition parent, TypeDefinition parentType, XModel.XTypeDefinition parentXType)
 {
     base.CreateClassDefinition(targetPackage, parent, parentType, parentXType);
     Class.IsFinal = true;
     Class.IsAbstract = true;
     Class.IsSynthetic = true;
 }
예제 #7
0
        /// <summary>
        /// Try to close the document without any saving of modifications.
        /// We can try it only! Controller and/or model of this document
        /// can disagree with that. But mostly they doesn't do so.
        /// </summary>
        /// <param name="xDocument">document which should be clcosed</param>
        public static void CloseDocument(XComponent xDocument)
        {
            try
            {
                // Check supported functionality of the document (model or controller).
                XModel xModel = (XModel)xDocument;

                if (xModel != null)
                {
                    // It's a full featured office document.
                    // Reset the modify state of it and close it.
                    // Note: Model can disagree by throwing a veto exception.
                    XModifiable xModify = (XModifiable)xModel;

                    xModify.setModified(false);
                    xDocument.dispose();
                }
                else
                {
                    // It's a document which supports a controller .. or may by a pure
                    // window only. If it's at least a controller - we can try to
                    // suspend him. But - he can disagree with that!
                    XController xController = (XController)xDocument;

                    if (xController != null)
                    {
                        if (xController.suspend(true))
                        {
                            // Note: Don't dispose the controller - destroy the frame
                            // to make it right!
                            XFrame xFrame = xController.getFrame();
                            xFrame.dispose();
                        }
                    }
                }
            }
            catch (PropertyVetoException exVeto)
            {
                // Can be thrown by "setModified()" call on model.
                // He disagree with our request.
                // But there is nothing to do then. Following "dispose()" call wasn't
                // never called (because we catch it before). Closing failed -that's it.
                System.Diagnostics.Debug.WriteLine(exVeto);
            }
            catch (DisposedException exDisposed)
            {
                // If an UNO object was already disposed before - he throw this special
                // runtime exception. Of course every UNO call must be look for that -
                // but it's a question of error handling.
                // For demonstration this exception is handled here.
                System.Diagnostics.Debug.WriteLine(exDisposed);
            }
            catch (RuntimeException exRuntime)
            {
                // Every uno call can throw that.
                // Do nothing - closing failed - that's it.
                System.Diagnostics.Debug.WriteLine(exRuntime);
            }
        }
예제 #8
0
 internal static void Copy(XModel document, Object selection)
 {
     if (document != null)
     {
         //return
         Copy(document.getCurrentController(), selection);
     }
 }
 public IActionResult Post(XModel model)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     // ...
 }
예제 #10
0
        public override void UpdateObjectProperties(object Input, PropertyGrid Properties, ListView Scene)
        {
            XModel model = (XModel)Input;

            //load the model file is we have a filename now
            if (!string.IsNullOrEmpty(model.Filename))
            {
                model.Load(X.Content);
            }

            base.UpdateObjectProperties(Input, Properties, Scene);
        }
예제 #11
0
        public override void WriteToXML(System.Xml.XmlWriter writer, object obj)
        {
            XModel model = (XModel)obj;

            writer.WriteStartElement("sceneitem");
            writer.WriteAttributeString("Type", model.GetType().ToString());
            writer.WriteAttributeString("AutoDraw", model.AutoDraw.ToString());
            writer.WriteAttributeString("ComponentID", model.ComponentID.ToString());
            writer.WriteAttributeString("DrawOrder", model.DrawOrder.ToString());
            writer.WriteAttributeString("Filename_editor", model.Filename_editor);
            writer.WriteAttributeString("Name", model.Name);
            writer.WriteEndElement();
        }
        /// <summary>
        /// Gets the frame from document.
        /// </summary>
        /// <param name="doc">The doc.</param>
        /// <returns></returns>
        public static XFrame GetFrameFromDocument(XModel doc)
        {
            try
            {
                return(doc.getCurrentController().getFrame());
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Can't get Frame form doc: " + ex);
            }

            return(null);
        }
예제 #13
0
 public override void AssignChildComponents(XComponent parent, ref List <uint> children)
 {
     if (children.Count == 1)
     {
         XActor xparent = (XActor)parent;
         XModel child   = (XModel)X.Tools.GetXComponentByID(children[0]);
         if (child.GetType() == typeof(XModel))
         {
             xparent.model_editor = child;
             xparent.RebuildCollisionSkin();
         }
     }
 }
        public QuasiStaticCrackPropagationAnalyzer(XModel model, ISolver solver, /*IStaticProvider problem,*/
                                                   ICrackDescription crack, double fractureToughness, int maxIterations)
        {
            this.model         = model;
            this.solver        = solver;
            this.linearSystems = solver.LinearSystems;
            //this.problem = problem;
            this.crack             = crack;
            this.fractureToughness = fractureToughness;
            this.maxIterations     = maxIterations;

            //TODO: Refactor problem structural and remove the next
            problem        = new ElementStructuralStiffnessProvider();
            loadsAssembler = new DirichletEquivalentLoadsStructural(problem);;
        }
        public static void TestDisplacements3x1()
        {
            // Expected solution
            double expectedStdUx5 = -8.17E-3;
            double expectedStdUx6 = -8.17E-3;

            double[] expectedEnrDisplNode5 = { 15.69E-3, 49.88E-3 };
            double[] expectedEnrDisplNode6 = { -15.69E-3, 49.88E-3 };

            // Analyze the model
            var dcb = new DoubleCantileverBeam();

            dcb.Create3x1Model();
            XModel model = dcb.Model;
            TrackingExteriorCrackLSM crack = dcb.Crack;

            (IVectorView globalU, IMatrixView globalK) = dcb.SolveModel();

            // Extract displacements of standard dofs
            DofTable freeDofs = model.Subdomains[DoubleCantileverBeam.subdomainID].FreeDofOrdering.FreeDofs;
            double   ux5      = globalU[freeDofs[model.Nodes[5], StructuralDof.TranslationX]];
            double   ux6      = globalU[freeDofs[model.Nodes[6], StructuralDof.TranslationX]];

            // Enriched dofs
            int numDofsPerNode = 2;
            IReadOnlyList <EnrichedDof> enrichedDofs = crack.CrackBodyEnrichment.Dofs;

            Assert.True(enrichedDofs.Count == numDofsPerNode);
            var enrDisplNode5 = new double[2];
            var enrDisplNode6 = new double[2];

            for (int i = 0; i < numDofsPerNode; ++i)
            {
                enrDisplNode5[i] = globalU[freeDofs[model.Nodes[5], enrichedDofs[i]]];
                enrDisplNode6[i] = globalU[freeDofs[model.Nodes[6], enrichedDofs[i]]];
            }

            // Check
            Func <double, double> round = x => 1E-3 * Math.Round(x * 1E3, 2);

            Assert.Equal(expectedStdUx5, round(ux5));
            Assert.Equal(expectedStdUx6, round(ux6));
            for (int i = 0; i < numDofsPerNode; ++i)
            {
                Assert.Equal(expectedEnrDisplNode5[i], round(enrDisplNode5[i]));
                Assert.Equal(expectedEnrDisplNode6[i], round(enrDisplNode6[i]));
            }
        }
예제 #16
0
        public override void LoadFromXML(System.Xml.XmlNode node, System.Windows.Forms.ListView scene, ref Dictionary <uint, List <uint> > Depends)
        {
            XModel model = new XModel(ref X, node.Attributes["Filename_editor"].InnerText);

            model.AutoDraw    = bool.Parse(node.Attributes["AutoDraw"].InnerText);
            model.ComponentID = uint.Parse(node.Attributes["ComponentID"].InnerText);
            model.DrawOrder   = int.Parse(node.Attributes["DrawOrder"].InnerText);
            model.Name        = node.Attributes["Name"].InnerText;

            if (!string.IsNullOrEmpty(model.Filename))
            {
                model.Load(X.Content);
            }

            X_Editor.Tools.AddXComponentToSceneList(scene, model, group);
        }
        public static void TestDisplacements135x45()
        {
            double[] expectedDisplacements = { 9.12E-3, -48.17E-3, 9.12E-3, 48.17E-3, 0.43E-3, 48.17E-3, -0.43E-3, 48.17E-3 };

            // Analyze the model
            var dcb = new DoubleCantileverBeam();

            dcb.CreateModel(135, 45, 2.0);
            XModel model = dcb.Model;
            TrackingExteriorCrackLSM crack = dcb.Crack;

            (IVectorView globalU, IMatrixView globalK) = dcb.SolveModel();

            // Locate nodes
            double tol = 1E-6;
            double L   = DoubleCantileverBeam.beamLength;
            IEnumerable <XNode> rightNodes = model.Nodes.Where(n => Math.Abs(n.X - L) <= tol);

            XNode[] crackMouthNodes = rightNodes.Where(n => n.EnrichmentItems.Count > 0).ToArray();
            Assert.Equal(2, crackMouthNodes.Length);

            XNode crackMouthBottom = crackMouthNodes.OrderBy(n => n.Y).First();
            XNode crackMouthTop    = crackMouthNodes.OrderBy(n => n.Y).Last();

            // Extract displacements of standard dofs
            var      displacements = Vector.CreateZero(8);
            DofTable freeDofs      = model.Subdomains[DoubleCantileverBeam.subdomainID].FreeDofOrdering.FreeDofs;

            displacements[0] = globalU[freeDofs[crackMouthBottom, StructuralDof.TranslationX]];
            displacements[1] = globalU[freeDofs[crackMouthBottom, StructuralDof.TranslationY]];
            displacements[2] = globalU[freeDofs[crackMouthTop, StructuralDof.TranslationX]];
            displacements[3] = globalU[freeDofs[crackMouthTop, StructuralDof.TranslationY]];

            // Enriched dofs
            IReadOnlyList <EnrichedDof> enrichedDofs = crack.CrackBodyEnrichment.Dofs;

            displacements[4] = globalU[freeDofs[crackMouthBottom, enrichedDofs[0]]];
            displacements[5] = globalU[freeDofs[crackMouthBottom, enrichedDofs[1]]];
            displacements[6] = globalU[freeDofs[crackMouthTop, enrichedDofs[0]]];
            displacements[7] = globalU[freeDofs[crackMouthTop, enrichedDofs[1]]];

            // Check
            double tolerance            = 1E-13;
            Func <double, double> round = x => 1E-3 * Math.Round(x * 1E3, 2);

            Assert.True(Vector.CreateFromArray(expectedDisplacements).Equals(displacements.DoToAllEntries(round), tolerance));
        }
예제 #18
0
        private static (XModel model, IMesh2D <XNode, XContinuumElement2D> mesh) CreateModel(string meshPath)
        {
            // Mesh generation
            var reader = new GmshReader <XNode>(meshPath);

            (IReadOnlyList <XNode> nodes, IReadOnlyList <CellConnectivity <XNode> > elementConnectivities) = reader.CreateMesh(
                (id, x, y, z) => new XNode(id, x, y, z));

            // Nodes
            var model = new XModel();

            foreach (XNode node in nodes)
            {
                model.Nodes.Add(node);
            }

            // Integration rules
            var integration = new IntegrationForCrackPropagation2D(
                new RectangularSubgridIntegration2D <XContinuumElement2D>(8, GaussLegendre2D.GetQuadratureWithOrder(2, 2)),
                new RectangularSubgridIntegration2D <XContinuumElement2D>(8, GaussLegendre2D.GetQuadratureWithOrder(2, 2)));
            var jIntegration =
                new RectangularSubgridIntegration2D <XContinuumElement2D>(8, GaussLegendre2D.GetQuadratureWithOrder(4, 4));

            // Elements
            var material = HomogeneousElasticMaterial2D.CreateMaterialForPlaneStrain(2.1E7, 0.3);
            var factory  = new XContinuumElement2DFactory(integration, jIntegration, material);
            var cells    = new XContinuumElement2D[elementConnectivities.Count];

            for (int e = 0; e < cells.Length; ++e)
            {
                XContinuumElement2D element = factory.CreateElement(e, CellType.Quad4, elementConnectivities[e].Vertices);
                cells[e] = element;
                model.Elements.Add(element);
            }

            // Mesh usable for crack-mesh interaction
            //var boundary = new FilletBoundary();
            IDomain2DBoundary boundary = null;

            model.Boundary = boundary;
            var mesh = new BidirectionalMesh2D <XNode, XContinuumElement2D>(model.Nodes, cells, boundary);

            return(model, mesh);
        }
예제 #19
0
        private static void BuildRootTree(Bone Parent, ref List <Bone> RootTree, ref XModel Model)
        {
            // Find bones with this joint as a parent and add
            var ThisBoneIndex = Model.Bones.IndexOf(Parent);

            var JointsWithThis   = Model.Bones.Where(x => x.ParentIndex == ThisBoneIndex);
            var ThisBoneNewIndex = RootTree.Count - 1;

            foreach (var Joint in JointsWithThis)
            {
                // Assign
                var Sorted = Joint.ShallowCopy();
                Sorted.ParentIndex = ThisBoneNewIndex;
                RootTree.Add(Sorted);

                // Recursive
                BuildRootTree(Joint, ref RootTree, ref Model);
            }
        }
예제 #20
0
        void PerformLoad()
        {
            // Start LibreOffice and load file
            unoidl.com.sun.star.uno.XComponentContext     localContext        = uno.util.Bootstrap.bootstrap();
            unoidl.com.sun.star.lang.XMultiServiceFactory multiServiceFactory = (unoidl.com.sun.star.lang.XMultiServiceFactory)localContext.getServiceManager();
            desktop = (XDesktop)multiServiceFactory.createInstance("com.sun.star.frame.Desktop");
            var componentLoader = (XComponentLoader)desktop;

            component = componentLoader.loadComponentFromURL(CreateFileUrl(file.FullName), "_blank", 0, new PropertyValue[] { });

            // TODO: while/before loading, set the viewsettings ViewId:=view1, PageKind:=0 to reset to the default view
            // (instead of notes or outline view). Unfortunately these settings aren't accesible in the API ...

            // Get the main window's handle and hide the window
            document = (XModel)component;
            XWindow window = document.getCurrentController().getFrame().getContainerWindow();

            window.setVisible(false);
            XSystemDependentWindowPeer xWindowPeer = (XSystemDependentWindowPeer)(window);

            mainHandle = new IntPtr((int)xWindowPeer.getWindowHandle(new byte[] { }, SystemDependent.SYSTEM_WIN32).Value);
            //ShowWindow(mainHandle, 0);

            presentation = (XPresentation2)((XPresentationSupplier)component).getPresentation();

            CreateThumbnails();

            listener.SlideTransitionStarted += (sender, args) =>
            {
                OnSlideIndexChanged();
            };

            Start();
            controller.gotoSlideIndex(0);

            LoadPreviewProvider();

            base.OnLoaded(true);
        }
        /// <summary>
        /// Registers the listener to the given object.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns></returns>
        public bool RegisterListenerToElement(Object element)
        {
            XSelectionSupplier supl = element as XSelectionSupplier;

            //TODO: maybe extend this
            if (supl == null && element is XModel)
            {
                XModel model      = element as XModel;
                var    controller = model.getCurrentController();
                if (controller != null && controller is XSelectionSupplier)
                {
                    supl = controller as XSelectionSupplier;
                }
            }

            if (supl != null)
            {
                try { supl.removeSelectionChangeListener(Instance.eventForwarder); }
                catch { }
                try
                {
                    supl.addSelectionChangeListener(Instance.eventForwarder);
                    return(true);
                }
                catch
                {
                    System.Threading.Thread.Sleep(5);
                    try
                    {
                        supl.addSelectionChangeListener(Instance.eventForwarder);
                        return(true);
                    }
                    catch { }
                }
            }

            return(false);
        }
예제 #22
0
        public void InsertGraphic(string imgpath)
        {
            Object            dispatchHelper    = mxMSFactory.createInstance("com.sun.star.frame.DispatchHelper");
            XDispatchHelper   dispatcher        = dispatchHelper as XDispatchHelper;
            XModel            xModel            = mxDocument as XModel;
            XFrame            xFrame            = xModel.getCurrentController().getFrame();
            XDispatchProvider xDispatchProvider = xFrame as XDispatchProvider;

            unoidl.com.sun.star.beans.PropertyValue[] MyProp = new unoidl.com.sun.star.beans.PropertyValue[4];
            MyProp[0]       = new unoidl.com.sun.star.beans.PropertyValue();
            MyProp[0].Name  = "FileName";
            MyProp[0].Value = new uno.Any(PathConverter(imgpath));
            MyProp[1]       = new unoidl.com.sun.star.beans.PropertyValue();
            MyProp[1].Name  = "FilterName";
            MyProp[1].Value = new uno.Any("<Tous les formats>");
            MyProp[2]       = new unoidl.com.sun.star.beans.PropertyValue();
            MyProp[2].Name  = "AsLink";
            MyProp[2].Value = new uno.Any(false);
            MyProp[3]       = new unoidl.com.sun.star.beans.PropertyValue();
            MyProp[3].Name  = "Style";
            MyProp[3].Value = new uno.Any("Image");
            dispatcher.executeDispatch(xDispatchProvider, ".uno:InsertGraphic", "", 0, MyProp);
        }
        internal static void Copy(XModel document, Object selection)
        {

            if (document != null)
            {
                //return 
                Copy(document.getCurrentController(), selection);
            }

        }
예제 #24
0
        public override System.Windows.Forms.ListViewItem SetupListViewItem(ListViewItem item, XComponent component)
        {
            XModel model = new XModel(ref X, null);

            return(base.SetupListViewItem(item, model));
        }
        public static void TestStiffnesses3x1()
        {
            Matrix node6StiffnessExpected = 1E6 * Matrix.CreateFromArray(new double[, ]
            {
                { 1.154, 0.481, -0.481, -0.240 },
                { 0.481, 1.154, -0.240, -0.962 },
                { -0.481, -0.240, 0.962, 0.481 },
                { -0.240, -0.962, 0.481, 1.923 }
            });

            Matrix node7Elem1StiffnessExpected = 1E6 * Matrix.CreateFromArray(new double[, ]
            {
                { 1.154, 0.481, 1.568, 0.544, -0.444, 0.12, -0.847, 0.016, 0.378, -0.337 },
                { 0.481, 1.154, 0.575, 2.668, -0.114, 0.175, -0.165, -0.271, -0.055, -0.358 },
                { 1.568, 0.575, 12.432, 4.896, -0.824, -1.69, -3.114, -3.125, 0.134, 0.537 },
                { 0.544, 2.668, 4.896, 17.018, -1.359, -3.322, -2.444, -6.366, 0.465, 3.07 },
                { -0.444, -0.114, -0.824, -1.359, 2.639, -0.459, 1.648, -0.253, -1.869, 0.939 },
                { 0.12, 0.175, -1.69, -3.322, -0.459, 3.921, -0.214, 4.699, 0.909, -2.729 },
                { -0.847, -0.165, -3.114, -2.444, 1.648, -0.214, 4.063, -0.01, -1.386, 0.645 },
                { 0.016, -0.271, -3.125, -6.366, -0.253, 4.699, -0.01, 7.896, 0.685, -2.804 },
                { 0.378, -0.055, 0.134, 0.465, -1.869, 0.909, -1.386, 0.685, 3.081, -0.859 },
                { -0.337, -0.358, 0.537, 3.07, 0.939, -2.729, 0.645, -2.804, -0.859, 4.694 }
            });

            Matrix node7Elem2StiffnessExpected = 1E6 * Matrix.CreateFromArray(new double[, ]
            {
                { 1.154, -0.481, 1.715, -0.752, -0.586, 0.006, -0.886, -0.052, 0.600, -0.087 },
                { -0.481, 1.154, -0.856, 3.184, 0.092, -0.325, 0.106, -0.417, -0.156, 0.417 },
                { 1.715, -0.856, 13.871, -5.198, -2.050, 0.718, -3.537, 1.216, 1.561, -0.610 },
                { -0.752, 3.184, -5.198, 26.465, 0.679, -5.280, 1.135, -9.091, -0.753, 3.713 },
                { -0.586, 0.092, -2.050, 0.679, 1.098, -0.169, 1.822, -0.235, -0.843, 0.223 },
                { 0.006, -0.325, 0.718, -5.280, -0.169, 2.052, -0.246, 3.583, 0.234, -1.222 },
                { -0.886, 0.106, -3.537, 1.135, 1.822, -0.246, 3.075, -0.350, -1.317, 0.322 },
                { -0.052, -0.417, 1.216, -9.091, -0.235, 3.583, -0.350, 6.348, 0.330, -1.973 },
                { 0.600, -0.156, 1.561, -0.753, -0.843, 0.234, -1.317, 0.330, 0.869, -0.282 },
                { -0.087, 0.417, -0.610, 3.713, 0.223, -1.222, 0.322, -1.973, -0.282, 1.180 }
            });

            Matrix node7GlobalStiffnessExpected = 1E6 * Matrix.CreateFromArray(new double[, ]
            {
                { 2.308, 0.000, 3.283, -0.208, -1.030, 0.126, -1.733, -0.036, 0.979, -0.424 },
                { 0.000, 2.308, -0.282, 5.852, -0.022, -0.150, -0.060, -0.687, -0.211, 0.059 },
                { 3.283, -0.282, 26.303, -0.302, -2.874, -0.972, -6.651, -1.910, 1.695, -0.073 },
                { -0.208, 5.852, -0.302, 43.483, -0.680, -8.601, -1.310, -15.456, -0.289, 6.783 },
                { -1.030, -0.022, -2.874, -0.680, 3.736, -0.628, 3.470, -0.488, -2.712, 1.162 },
                { 0.126, -0.150, -0.972, -8.601, -0.628, 5.973, -0.460, 8.282, 1.142, -3.951 },
                { -1.733, -0.060, -6.651, -1.310, 3.470, -0.460, 7.139, -0.360, -2.703, 0.966 },
                { -0.036, -0.687, -1.910, -15.456, -0.488, 8.282, -0.360, 14.244, 1.015, -4.777 },
                { 0.979, -0.211, 1.695, -0.289, -2.712, 1.142, -2.703, 1.015, 3.950, -1.141 },
                { -0.424, 0.059, -0.073, 6.783, 1.162, -3.951, 0.966, -4.777, -1.141, 5.874 }
            });

            // Create and analyze model, in order to get the global stiffness
            var dcb = new DoubleCantileverBeam();

            dcb.Create3x1Model();
            XModel model = dcb.Model;
            TrackingExteriorCrackLSM crack = dcb.Crack;

            (IVectorView globalU, IMatrixView globalK) = dcb.SolveModel();

            // Print matrix
//            var writer = new FullMatrixWriter();
            //writer.NumericFormat = new FixedPointFormat() { NumDecimalDigits = 2 };
//            writer.ArrayFormat = new Array2DFormat("", "", "", "\n", ",");
//            writer.WriteToFile(globalK/*.DoToAllEntries(x => Math.Round(x * 1E-6, 3))*/, @"C:\Users\Serafeim\Desktop\xfem.txt");

            // Calculate relevant stiffness submatrix global
            XNode    node7           = model.Nodes[7];
            var      node7GlobalDofs = new int[10];
            DofTable freeDofs        = model.Subdomains[DoubleCantileverBeam.subdomainID].FreeDofOrdering.FreeDofs;

            node7GlobalDofs[0] = freeDofs[node7, StructuralDof.TranslationX];
            node7GlobalDofs[1] = freeDofs[node7, StructuralDof.TranslationY];
            for (int i = 0; i < 8; ++i)
            {
                node7GlobalDofs[2 + i] = freeDofs[node7, crack.CrackTipEnrichments.Dofs[i]];
            }
            IMatrix node7GlobalStiffness = globalK.GetSubmatrix(node7GlobalDofs, node7GlobalDofs);

            // Element 1 dofs (std first):
            // (N1,ux,0) (N1,uy,1) (N4,ux,2) (N4,uy,3) (N7,ux,4) (N7,uy,5) (N2,ux,6) (N2,uy,7)
            // (N1,tip0x, 8) (N1,tip0y,9) (N1,tip1x,10) (N1,tip1y,11) (N1,tip2x,12) (N1,tip2y,13) (N1,tip3x,14) (N1,tip3y,15)
            // (N4,tip0x,16) (N4,tip0y,17) (N4,tip1x,18) (N4,tip1y,19) (N4,tip2x,20) (N4,tip2y,21) (N4,tip3x,22) (N4,tip3y,23)
            // (N7,tip0x,24) (N7,tip0y,25) (N7,tip1x,26) (N7,tip1y,27) (N7,tip2x,28) (N7,tip2y,29) (N7,tip3x,30) (N7,tip3y,31)
            // (N2,tip0x,32) (N2,tip0y,33) (N2,tip1x,34) (N2,tip1y,35) (N2,tip2x,36) (N2,tip2y,37) (N2,tip3x,38) (N2,tip3y,39)

            // Element 2 dofs (std first):
            // (N4,ux,0) (N4,uy,1) (N5,ux,2) (N5,uy,3) (N6,ux,4) (N6,uy,5) (N7,ux,6) (N7,uy,7)
            // (N4,tip0x,8) (N4,tip0y,9) (N4,tip1x,10) (N4,tip1y,11) (N4,tip2x,12) (N4,tip2y,13) (N4,tip3x,14) (N4,tip3y,15)
            // (N5,bodyX,16) (N5,bodyY,17)
            // (N6,bodyX,18) (N6,bodyY,19)
            // (N7,tip0x,20) (N7,tip0y,21) (N7,tip1x,22) (N7,tip1y,23) (N7,tip2x,24) (N7,tip2y,25) (N7,tip3x,26) (N7,tip3y,27)

            // Calculate relevant stiffness submatrices from elements
            IMatrix elem1Stiffness = ((XContinuumElement2D)model.Elements[1].ElementType).JoinStiffnessesStandardFirst();
            IMatrix elem2Stiffness = ((XContinuumElement2D)model.Elements[2].ElementType).JoinStiffnessesStandardFirst();

            int[]   elem2Node6Dofs = { 4, 5, 18, 19 };
            IMatrix node6Stiffness = elem2Stiffness.GetSubmatrix(elem2Node6Dofs, elem2Node6Dofs);

            int[]   elem1Node7Dofs      = { 4, 5, 24, 25, 26, 27, 28, 29, 30, 31 };
            IMatrix node7Elem1Stiffness = elem1Stiffness.GetSubmatrix(elem1Node7Dofs, elem1Node7Dofs);

            int[]   elem2Node7Dofs      = { 6, 7, 20, 21, 22, 23, 24, 25, 26, 27 };
            IMatrix node7Elem2Stiffness = elem2Stiffness.GetSubmatrix(elem2Node7Dofs, elem2Node7Dofs);

            // Check matrices
            double equalityTolerance    = 1E-13;
            Func <double, double> round = x => 1E6 * Math.Round(x * 1E-6, 3);

            Assert.True(node6StiffnessExpected.Equals(node6Stiffness.DoToAllEntries(round), equalityTolerance));
            Assert.True(node7Elem1StiffnessExpected.Equals(node7Elem1Stiffness.DoToAllEntries(round), equalityTolerance));
            Assert.True(node7Elem2StiffnessExpected.Equals(node7Elem2Stiffness.DoToAllEntries(round), equalityTolerance));
            Assert.True(node7GlobalStiffnessExpected.Equals(node7GlobalStiffness.DoToAllEntries(round), equalityTolerance));
        }
 /// <summary>
 /// Registers the context menu controler.
 /// </summary>
 /// <param name="xModel">The x model.</param>
 public void RegisterContextMenuControler(XModel xModel)
 {
     _xFrame = xModel.getCurrentController().getFrame();
     RegisterContextMenuControler(_xFrame);
 }
예제 #27
0
        public void Create3x1Model()
        {
            double elementSize = 20.0;
            var    model       = new XModel();

            model.Subdomains[subdomainID] = new XSubdomain(subdomainID);
            this.Model = model;

            //Nodes
            model.Nodes.Add(new XNode(0, 0.0, 0.0));
            model.Nodes.Add(new XNode(1, elementSize, 0.0));
            model.Nodes.Add(new XNode(2, elementSize, elementSize));
            model.Nodes.Add(new XNode(3, 0.0, elementSize));
            model.Nodes.Add(new XNode(4, 2 * elementSize, 0.0));
            model.Nodes.Add(new XNode(5, 3 * elementSize, 0.0));
            model.Nodes.Add(new XNode(6, 3 * elementSize, elementSize));
            model.Nodes.Add(new XNode(7, 2 * elementSize, elementSize));

            // Elements
            XNode[][] connectivity = new XNode[3][];
            connectivity[0] = new XNode[] { model.Nodes[0], model.Nodes[1], model.Nodes[2], model.Nodes[3] };
            connectivity[1] = new XNode[] { model.Nodes[1], model.Nodes[4], model.Nodes[7], model.Nodes[2] };
            connectivity[2] = new XNode[] { model.Nodes[4], model.Nodes[5], model.Nodes[6], model.Nodes[7] };

            var factory = new XContinuumElement2DFactory(integration, jIntegration, material);
            var cells   = new XContinuumElement2D[3];

            for (int e = 0; e < 3; ++e)
            {
                XContinuumElement2D element = factory.CreateElement(e, CellType.Quad4, connectivity[e]);
                cells[e] = element;
                model.Elements.Add(element);
                model.Subdomains[subdomainID].Elements.Add(model.Elements[e]);
            }

            // Mesh
            var mesh = new BidirectionalMesh2D <XNode, XContinuumElement2D>(model.Nodes,
                                                                            model.Elements.Select(e => (XContinuumElement2D)e).ToArray(), beamBoundary);

            // Boundary conditions
            model.Nodes[0].Constraints.Add(new Constraint()
            {
                DOF = StructuralDof.TranslationX, Amount = 0.0
            });
            model.Nodes[0].Constraints.Add(new Constraint()
            {
                DOF = StructuralDof.TranslationY, Amount = 0.0
            });
            model.Nodes[3].Constraints.Add(new Constraint()
            {
                DOF = StructuralDof.TranslationX, Amount = 0.0
            });
            model.Nodes[3].Constraints.Add(new Constraint()
            {
                DOF = StructuralDof.TranslationY, Amount = 0.0
            });
            model.Nodes[5].Constraints.Add(new Constraint()
            {
                DOF = StructuralDof.TranslationY, Amount = -0.05
            });
            model.Nodes[6].Constraints.Add(new Constraint()
            {
                DOF = StructuralDof.TranslationY, Amount = +0.05
            });

            // Create crack
            CreateCrack(elementSize, model, mesh, 2.0);
        }
예제 #28
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            //Load engine base content
            X.LoadContent();

            //Game base elements
            menus.Load(Content);


            // load scene objects/content
            //sky = new XDynamicSky(ref X,X.Environment);
            //XSkyBox sky = new XSkyBox(ref X, @"Content\XEngine\Textures\Sky\front", @"Content\XEngine\Textures\Sky\back", @"Content\XEngine\Textures\Sky\left", @"Content\XEngine\Textures\Sky\right", @"Content\XEngine\Textures\Sky\top", @"Content\XEngine\Textures\Sky\bottom");
            XSkyBox sky = new XSkyBox(ref X, @"Content\XEngine\Textures\Sky\GreenWaterSky");

            heightmap = new XHeightMap(ref X, @"Content\Images\Heightmaps\Level2", X.Environment, @"Content\Textures\Grass", @"Content\Textures\Sand", null, @"Content\Images\Terrainmaps\Island1");

            //resources.AddComponent(environment);
            resources.AddComponent(heightmap);
            resources.AddComponent(sky);

            model = new XModel(ref X, @"Content\Models\cube");
            resources.AddComponent(model);

            Chassis = new XModel(ref X, @"Content\Models\chassis");
            Wheel   = new XModel(ref X, @"Content\Models\wheel");

            resources.AddComponent(Chassis);
            resources.AddComponent(Wheel);

            housemodel = new XModel(ref X, @"Content\Models\spider");
            resources.AddComponent(housemodel);

            resources.Load();

            //Car = new XCar(ref X, Chassis, Wheel, true, true, 30.0f, 5.0f, 4.7f, 5.0f, 0.20f, 0.4f, 0.05f, 0.45f, 0.3f, 1, 520.0f, Math.Abs(X.Gravity.Y), new Vector3(-10, heightmap.Heights.GetHeight(new Vector3(-10, 3, 0))+5, 0));

            Car = new XCar(ref X, Chassis, Wheel,
                           true,                       // front wheel drive
                           true,                       // rear wheel drive
                           35.0f,                      // max steering angle
                           5f,                         // steering rate
                           3.6f,                       // front lateral traction
                           3.1f,                       // rear lateral traction
                           1f,                         // front longintudinal traction
                           2f,                         // rear longitudinal traction
                           2.5f,                       // handbrake rear lateral traction
                           .75f,                       // handbrake rear longitudinal traction
                           6f,                         // starting slide factor
                           15f,                        // threshold 1 slide factor
                           30f,                        // threshold 2 slide factor
                           .7f,                        // slip threshold 1
                           10.0f,                      // slip threshold 2
                           2.0f,                       // slide speed factor
                           1.7f,                       // traction loss factor on slip
                           0.3f,                       // suspension travel
                           0.45f,                      // wheel radius
                           -0.10f,                     // wheel mounting point
                           0.6f,                       // spring rate
                           0.6f,                       // shock dampening
                           2,                          // wheel rays
                           2.5f,                       // roll resistance
                           300.0f,                     // top speed
                           1200.0f,                    // torque
                           X.Physics.Gravity.Length(), // gravity
                           new Vector3(-10, heightmap.Heights.GetHeight(new Vector3(-10, 3, 0)) + 5, 0)
                           );

            Car.Load(X.Content);

            trees = new XTreeSystem(ref X, @"Content\Images\Treemaps\Level1", heightmap);
            trees.Load(Content);
            trees.GenerateTrees(freeCamera);

            input.Load();
            base.LoadContent();
        }
 /// <summary>
 /// Gets the current controller of the given model.
 /// </summary>
 /// <param name="xModel">The x model.</param>
 /// <returns>Current controller or <code>null</code></returns>
 public XController GetController(XModel xModel)
 {
     return xModel != null ? xModel.getCurrentController() : null;
 }
예제 #30
0
        public void CreateModel(int numElementsX, int numElementsY, double jIntegralRadiusRatio)
        {
            var model = new XModel();

            model.Subdomains[subdomainID] = new XSubdomain(subdomainID);
            this.Model = model;

            // Mesh generation
            var meshGenerator = new UniformMeshGenerator2D <XNode>(0.0, 0.0, beamLength, beamHeight, numElementsX, numElementsY);

            (IReadOnlyList <XNode> nodes, IReadOnlyList <CellConnectivity <XNode> > elementConnectivities) =
                meshGenerator.CreateMesh((id, x, y, z) => new XNode(id, x, y, z));

            // Nodes
            foreach (XNode node in nodes)
            {
                model.Nodes.Add(node);
            }

            // Elements
            var factory = new XContinuumElement2DFactory(integration, jIntegration, material);
            var cells   = new XContinuumElement2D[elementConnectivities.Count];

            for (int e = 0; e < elementConnectivities.Count; ++e)
            {
                XContinuumElement2D element = factory.CreateElement(e, CellType.Quad4, elementConnectivities[e].Vertices);
                cells[e] = element;
                model.Elements.Add(element);
                model.Subdomains[subdomainID].Elements.Add(model.Elements[e]);
            }

            // Mesh
            var mesh = new BidirectionalMesh2D <XNode, XContinuumElement2D>(model.Nodes,
                                                                            model.Elements.Select(e => (XContinuumElement2D)e).ToArray(), beamBoundary);

            // Boundary conditions
            double tol         = 1E-6;
            double L           = DoubleCantileverBeam.beamLength;
            double H           = DoubleCantileverBeam.beamHeight;
            XNode  topRight    = model.Nodes.Where(n => Math.Abs(n.X - L) <= tol && Math.Abs(n.Y - H) <= tol).First();
            XNode  bottomRight = model.Nodes.Where(n => Math.Abs(n.X - L) <= tol && Math.Abs(n.Y) <= tol).First();

            topRight.Constraints.Add(new Constraint()
            {
                DOF = StructuralDof.TranslationY, Amount = +0.05
            });
            bottomRight.Constraints.Add(new Constraint()
            {
                DOF = StructuralDof.TranslationY, Amount = -0.05
            });
            foreach (XNode node in model.Nodes.Where(n => Math.Abs(n.X) <= tol))
            {
                node.Constraints.Add(new Constraint()
                {
                    DOF = StructuralDof.TranslationX, Amount = 0.0
                });
                node.Constraints.Add(new Constraint()
                {
                    DOF = StructuralDof.TranslationY, Amount = 0.0
                });
            }

            // Create crack
            double elementSizeX = beamLength / numElementsX;
            double elementSizeY = beamHeight / numElementsY;

            CreateCrack(Math.Max(elementSizeX, elementSizeY), model, mesh, jIntegralRadiusRatio);
        }
예제 #31
0
        private static void SortJoints(ref XModel Model, List <string> ParentStack, string CosmeticRoot = "")
        {
            // Handle no bones
            if (Model.Bones.Count == 0)
            {
                Model.Bones.Add(new Bone("tag_origin"));
            }

            // Prepare to sort, first, assign parent index, if any
            for (int i = 0; i < ParentStack.Count; i++)
            {
                // Assign parent
                Model.Bones[i].ParentIndex = Model.Bones.FindIndex(x => x.TagName == ParentStack[i]);
            }

            // Build root tree
            var RootJointList = Model.Bones.Where(x => x.ParentIndex == -1);

            if (RootJointList.Count() == 0)
            {
                MGlobal.displayError("[CODTools] No root joint was found...");
                return;
            }
            else if (RootJointList.Count() > 1)
            {
                MGlobal.displayError("[CODTools] Multiple root joints not supported in Call of Duty...");
                return;
            }
            var RootJoint = RootJointList.FirstOrDefault();

            // Prepare root tree
            var RootTree = new List <Bone>()
            {
                RootJoint
            };

            BuildRootTree(RootJoint, ref RootTree, ref Model);

            // Mark cosmetic bones using the root
            if (CosmeticRoot != string.Empty)
            {
                // Fetch it if it's in the list
                var CosmeticBone = RootTree.Find(x => x.TagName == CosmeticRoot.Trim());
                if (CosmeticBone != null)
                {
                    // Recursive iterate through children until marked
                    MarkCosmetic(ref RootTree, RootTree.IndexOf(CosmeticBone));
                }
            }

            // Ensure cosmetics are at the end of the tree
            var SortedCosmetic = RootTree.OrderBy(x => x.isCosmetic).ToList();
            var SortedDict     = new Dictionary <int, int>();

            // Iterate and resort
            foreach (var Sorted in SortedCosmetic)
            {
                if (Sorted.ParentIndex == -1)
                {
                    continue;
                }

                Sorted.ParentIndex = SortedCosmetic.FindIndex(x => x.TagName == RootTree[Sorted.ParentIndex].TagName);
            }

            // Assign final sorted indicies
            Model.Bones = SortedCosmetic;
        }
예제 #32
0
        public static void ExportXModel(string FilePath, XModelType FileType, bool Siege = false, string Cosmetic = "")
        {
            // Configure scene
            using (var MayaCfg = new MayaSceneConfigure())
            {
                // First, get the current selection
                var ExportObjectList = new MSelectionList();
                MGlobal.getActiveSelectionList(ExportObjectList);

                // If empty, select all joints and meshes
                if (ExportObjectList.length == 0)
                {
                    // Select all joints and meshes
                    MGlobal.executeCommand("string $selected[] = `ls -type joint`; select -r $selected;");
                    MGlobal.executeCommand("string $transforms[] = `ls -tr`;string $polyMeshes[] = `filterExpand -sm 12 $transforms`;select -add $polyMeshes;");

                    // Get it again
                    MGlobal.getActiveSelectionList(ExportObjectList);
                }

                // If still empty, error blank scene
                if (ExportObjectList.length == 0)
                {
                    MGlobal.displayError("[CODTools] The current scene is empty...");
                    return;
                }

                // Progress
                MayaCfg.StartProgress("Exporting XModel...", (int)ExportObjectList.length);

                // Create new model
                var Result = new XModel(System.IO.Path.GetFileNameWithoutExtension(FilePath));
                // Assign siege model flag (Default: false)
                Result.SiegeModel = Siege;

                // Metadata
                var SceneName = string.Empty;
                MGlobal.executeCommand("file -q -sceneName", out SceneName);

                Result.Comments.Add(string.Format("Export filename: '{0}'", FilePath));
                Result.Comments.Add(string.Format("Source filename: '{0}'", SceneName));
                Result.Comments.Add(string.Format("Export time: {0}", DateTime.Now.ToString()));

                // Iterate and add joints
                var ParentStack = new List <string>();
                var UniqueBones = new HashSet <string>();

                foreach (var Joint in ExportObjectList.DependNodes(MFn.Type.kJoint))
                {
                    // Step
                    MayaCfg.StepProgress();

                    // Grab the controller
                    var Path       = GetObjectDagPath(Joint);
                    var Controller = new MFnIkJoint(Path);

                    // Create a new bone
                    var TagName = CleanNodeName(Controller.name);

                    if (UniqueBones.Contains(TagName))
                    {
                        continue;
                    }
                    UniqueBones.Add(TagName);

                    var NewBone = new Bone(TagName);
                    // Add parent
                    ParentStack.Add(GetParentName(Controller));

                    // Fetch the world-space position and rotation
                    var WorldPosition = Controller.getTranslation(MSpace.Space.kWorld);

                    var WorldRotation = new MQuaternion(MQuaternion.identity);
                    Controller.getRotation(WorldRotation, MSpace.Space.kWorld);

                    var WorldScale = new double[3] {
                        1, 1, 1
                    };
                    Controller.getScale(WorldScale);

                    // Create the matrix
                    NewBone.Translation    = WorldPosition * (1 / 2.54);
                    NewBone.Scale          = new MVector(WorldScale[0], WorldScale[1], WorldScale[2]);
                    NewBone.RotationMatrix = WorldRotation.asMatrix;

                    // Add it
                    Result.Bones.Add(NewBone);
                }
                // Sort joints
                SortJoints(ref Result, ParentStack, Cosmetic);

                // Pre-fetch skins
                var SkinClusters = GetSkinClusters();
                var BoneMapping  = Result.GetBoneMapping();

                // A list of used materials
                int MaterialIndex = 0;
                var UsedMaterials = new Dictionary <string, int>();
                var UsedMeshes    = new HashSet <string>();

                // Iterate and add meshes
                foreach (var Mesh in ExportObjectList.DependNodes(MFn.Type.kMesh))
                {
                    // Step
                    MayaCfg.StepProgress();

                    // Grab the controller
                    var Path = GetObjectDagPath(Mesh);
                    Path.extendToShape();
                    var Controller = new MFnMesh(Path);

                    // Ignore duplicates
                    if (UsedMeshes.Contains(Path.partialPathName))
                    {
                        continue;
                    }
                    UsedMeshes.Add(Path.partialPathName);

                    // Pre-fetch materials
                    var MeshMaterials = GetMaterialsMesh(ref Controller, ref Path);
                    foreach (var Mat in MeshMaterials)
                    {
                        if (!UsedMaterials.ContainsKey(Mat.Name))
                        {
                            UsedMaterials.Add(Mat.Name, MaterialIndex++);
                            Result.Materials.Add(Mat);
                        }
                    }

                    // New mesh
                    var NewMesh = new Mesh();

                    // Grab iterators
                    var VertexIterator = new MItMeshVertex(Path);
                    var FaceIterator   = new MItMeshPolygon(Path);

                    // Get the cluster for this
                    var SkinCluster = FindSkinCluster(ref SkinClusters, Controller);
                    var SkinJoints  = new MDagPathArray();

                    if (SkinCluster != null)
                    {
                        SkinCluster.influenceObjects(SkinJoints);
                    }

                    // Build vertex array
                    for (; !VertexIterator.isDone; VertexIterator.next())
                    {
                        // Prepare
                        var NewVert = new Vertex();

                        // Grab data
                        NewVert.Position = VertexIterator.position(MSpace.Space.kWorld) * (1 / 2.54);

                        // Weights if valid
                        if (SkinCluster != null)
                        {
                            var WeightValues = new MDoubleArray();

                            uint Influence = 0;
                            SkinCluster.getWeights(Path, VertexIterator.currentItem(), WeightValues, ref Influence);

                            for (int i = 0; i < (int)WeightValues.length; i++)
                            {
                                if (WeightValues[i] < 0.000001)
                                {
                                    continue;
                                }
                                var WeightTagName = CleanNodeName(SkinJoints[i].partialPathName);
                                var WeightID      = (BoneMapping.ContainsKey(WeightTagName)) ? BoneMapping[WeightTagName] : 0;

                                NewVert.Weights.Add(new Tuple <int, float>(WeightID, (float)WeightValues[i]));
                            }
                        }
                        if (NewVert.Weights.Count == 0)
                        {
                            NewVert.Weights.Add(new Tuple <int, float>(0, 1.0f));
                        }

                        // Add it
                        NewMesh.Vertices.Add(NewVert);
                    }

                    // Build face array
                    for (; !FaceIterator.isDone; FaceIterator.next())
                    {
                        var Indices = new MIntArray();
                        var Normals = new MVectorArray();
                        var UVUs    = new MFloatArray();
                        var UVVs    = new MFloatArray();

                        FaceIterator.getVertices(Indices);
                        FaceIterator.getNormals(Normals, MSpace.Space.kWorld);
                        FaceIterator.getUVs(UVUs, UVVs);

                        // Only support TRIS/QUAD
                        if (Indices.Count < 3)
                        {
                            continue;
                        }

                        if (Indices.Count == 3)
                        {
                            // Create new face
                            var NewFace = new FaceVertex();
                            // Setup
                            NewFace.Indices[0] = Indices[0];
                            NewFace.Indices[2] = Indices[1];
                            NewFace.Indices[1] = Indices[2];

                            // Normals
                            NewFace.Normals[0] = new MVector(Normals[0][0], Normals[0][1], Normals[0][2]);
                            NewFace.Normals[2] = new MVector(Normals[1][0], Normals[1][1], Normals[1][2]);
                            NewFace.Normals[1] = new MVector(Normals[2][0], Normals[2][1], Normals[2][2]);

                            // Colors
                            FaceIterator.getColor(NewFace.Colors[0], 0);
                            FaceIterator.getColor(NewFace.Colors[2], 1);
                            FaceIterator.getColor(NewFace.Colors[1], 2);

                            // Append UV Layers
                            NewFace.UVs[0] = new Tuple <float, float>(UVUs[0], 1 - UVVs[0]);
                            NewFace.UVs[2] = new Tuple <float, float>(UVUs[1], 1 - UVVs[1]);
                            NewFace.UVs[1] = new Tuple <float, float>(UVUs[2], 1 - UVVs[2]);

                            // Set material index
                            if (MeshMaterials.Count > 0)
                            {
                                NewFace.MaterialIndex = UsedMaterials[MeshMaterials[0].Name];
                            }

                            // Add it
                            NewMesh.Faces.Add(NewFace);
                        }
                        else
                        {
                            // Create new faces
                            FaceVertex NewFace = new FaceVertex(), NewFace2 = new FaceVertex();
                            // Setup
                            NewFace.Indices[0]  = Indices[0];
                            NewFace.Indices[2]  = Indices[1];
                            NewFace.Indices[1]  = Indices[2];
                            NewFace2.Indices[0] = Indices[0];
                            NewFace2.Indices[2] = Indices[2];
                            NewFace2.Indices[1] = Indices[3];

                            // Normals
                            NewFace.Normals[0]  = new MVector(Normals[0][0], Normals[0][1], Normals[0][2]);
                            NewFace.Normals[2]  = new MVector(Normals[1][0], Normals[1][1], Normals[1][2]);
                            NewFace.Normals[1]  = new MVector(Normals[2][0], Normals[2][1], Normals[2][2]);
                            NewFace2.Normals[0] = new MVector(Normals[0][0], Normals[0][1], Normals[0][2]);
                            NewFace2.Normals[2] = new MVector(Normals[2][0], Normals[2][1], Normals[2][2]);
                            NewFace2.Normals[1] = new MVector(Normals[3][0], Normals[3][1], Normals[3][2]);

                            // Colors
                            FaceIterator.getColor(NewFace.Colors[0], 0);
                            FaceIterator.getColor(NewFace.Colors[2], 1);
                            FaceIterator.getColor(NewFace.Colors[1], 2);
                            FaceIterator.getColor(NewFace2.Colors[0], 0);
                            FaceIterator.getColor(NewFace2.Colors[2], 2);
                            FaceIterator.getColor(NewFace2.Colors[1], 3);

                            // Append UV Layers
                            NewFace.UVs[0]  = new Tuple <float, float>(UVUs[0], 1 - UVVs[0]);
                            NewFace.UVs[2]  = new Tuple <float, float>(UVUs[1], 1 - UVVs[1]);
                            NewFace.UVs[1]  = new Tuple <float, float>(UVUs[2], 1 - UVVs[2]);
                            NewFace2.UVs[0] = new Tuple <float, float>(UVUs[0], 1 - UVVs[0]);
                            NewFace2.UVs[2] = new Tuple <float, float>(UVUs[2], 1 - UVVs[2]);
                            NewFace2.UVs[1] = new Tuple <float, float>(UVUs[3], 1 - UVVs[3]);

                            // Set material index
                            if (MeshMaterials.Count > 0)
                            {
                                NewFace.MaterialIndex  = UsedMaterials[MeshMaterials[0].Name];
                                NewFace2.MaterialIndex = UsedMaterials[MeshMaterials[0].Name];
                            }

                            // Add it
                            NewMesh.Faces.Add(NewFace);
                            NewMesh.Faces.Add(NewFace2);
                        }
                    }

                    // Add it
                    Result.Meshes.Add(NewMesh);
                }

                // Write
                switch (FileType)
                {
                case XModelType.Export:
                    Result.WriteExport(FilePath);
                    break;

                case XModelType.Bin:
                    Result.WriteBin(FilePath);
                    break;
                }
            }

            // Log complete
            MGlobal.displayInfo(string.Format("[CODTools] Exported {0}", System.IO.Path.GetFileName(FilePath)));
        }
예제 #33
0
 /// <summary>
 /// Конструктор класса
 /// </summary>
 /// <param name="xmlList">xml-описание списка</param>
 /// <param name="nsManager">XmlNamespaceManager</param>
 /// <param name="model">описание метаданных</param>
 public ListInfoWithAccessCheck(XmlElement xmlList, XmlNamespaceManager nsManager, XModel model)
     : base(xmlList, nsManager, model)
 {
 }
예제 #34
0
 /// <summary>
 /// Create the name of the class.
 /// </summary>
 protected override string CreateClassName(XModel.XTypeDefinition xType)
 {
     return ClassName;
 }
 /// <summary>
 /// Registers the context menu controler.
 /// </summary>
 /// <param name="xModel">The x model.</param>
 public void RegisterContextMenuControler(XModel xModel)
 {
     _xFrame = xModel.getCurrentController().getFrame();
     RegisterContextMenuControler(_xFrame);
 }
예제 #36
0
        void PerformLoad()
        {
            // Start LibreOffice and load file
            unoidl.com.sun.star.uno.XComponentContext localContext = uno.util.Bootstrap.bootstrap();
            unoidl.com.sun.star.lang.XMultiServiceFactory multiServiceFactory = (unoidl.com.sun.star.lang.XMultiServiceFactory)localContext.getServiceManager();
            desktop = (XDesktop)multiServiceFactory.createInstance("com.sun.star.frame.Desktop");
            var componentLoader = (XComponentLoader)desktop;
            component = componentLoader.loadComponentFromURL(CreateFileUrl(file.FullName), "_blank", 0, new PropertyValue[] { });

            // TODO: while/before loading, set the viewsettings ViewId:=view1, PageKind:=0 to reset to the default view
            // (instead of notes or outline view). Unfortunately these settings aren't accesible in the API ...

            // Get the main window's handle and hide the window
            document = (XModel)component;
            XWindow window = document.getCurrentController().getFrame().getContainerWindow();
            window.setVisible(false);
            XSystemDependentWindowPeer xWindowPeer = (XSystemDependentWindowPeer)(window);
            mainHandle = new IntPtr((int)xWindowPeer.getWindowHandle(new byte[] { }, SystemDependent.SYSTEM_WIN32).Value);
            //ShowWindow(mainHandle, 0);

            presentation = (XPresentation2)((XPresentationSupplier)component).getPresentation();

            CreateThumbnails();

            listener.SlideTransitionStarted += (sender, args) =>
            {
                OnSlideIndexChanged();
            };

            Start();
            controller.gotoSlideIndex(0);

            LoadPreviewProvider();

            base.OnLoaded(true);
        }