예제 #1
0
파일: CircuitM.cs 프로젝트: 741645596/Lab
    public static void JionCircuit()
    {
        List <NDlabObject> lineList = NDlabObject.SearchLabObject(SearchCicuitType.ELELINE, false);

        foreach (NDlabObject obj in lineList)
        {
            if (obj != null && obj is EleLine)
            {
                EleLine eleLine = obj as EleLine;
                if (eleLine.ConnectLink == true)
                {
                    NDlabObject    start        = eleLine.StartLineLeap.Link.m_Parent;
                    NDlabObject    end          = eleLine.EndLineLeap.Link.m_Parent;
                    CircuitElement myCircuit    = LabObjectDataFactory.GetCircuit(start.LabObjID);
                    CircuitElement OtherCircuit = LabObjectDataFactory.GetCircuit(end.LabObjID);

                    Circuit.Lead startLead = eleLine.StartLineLeap.Link.m_Type == ElementLeapType.leadIn?myCircuit.leadIn:myCircuit.leadOut;
                    Circuit.Lead endLead   = eleLine.EndLineLeap.Link.m_Type == ElementLeapType.leadIn ? OtherCircuit.leadIn : OtherCircuit.leadOut;
                    g_sim.Connect(startLead, endLead);
                }
            }
        }
    }
예제 #2
0
    void SimulationFlow() // tato funkcia zavola objekty so scenky, prepoji ich umelo, zavola algoritmus na zrusenie uzlov, prepoji zoznamy dllconectorov a spusti simulaciu
    {
        foreach (GUICircuitComponent[] network in _listOfNetworks)
        {
            int numOfBatteries = 0;
            foreach (GUICircuitComponent component in network)
            {
                if (component.GetType() == GameObject.Find("Accumulator").GetComponent <GUICircuitComponent>().GetType())
                {
                    numOfBatteries++;
                }
            }

            if ((numOfBatteries < 2) && (network.Length > 1))
            {
                Circuit newSimulation = new Circuit();
                simList.Add(newSimulation);
                foreach (GUICircuitComponent component in network)
                {
                    component.SetSimulationProp(newSimulation);
                }

                GraphAlgorithm           algorithm = new GraphAlgorithm();
                ConnectionsOfComponent[] dllconnectionsOfComponents = algorithm.Untangle(network);

                //Debug.Log(dllconnectionsOfComponents.Length);
                _countOfMadeConnections = 0;

                List <Circuit.Lead[]> alreadyConnected = new List <Circuit.Lead[]>();

                for (int i = 0; i < dllconnectionsOfComponents.Length; i++)
                {
                    for (int a = 0; a < dllconnectionsOfComponents[i].dllconnections.Length; a++)
                    {
                        for (int b = 0; b < dllconnectionsOfComponents[i].dllconnections[a].connectedDllconnectors.Length; b++)
                        {
                            if (dllconnectionsOfComponents[i].dllconnections[a].dllconector != dllconnectionsOfComponents[i].dllconnections[a].connectedDllconnectors[b])
                            {
                                Boolean alreadyThere = false;
                                foreach (Circuit.Lead[] pair in alreadyConnected)
                                {
                                    if ((pair[0] == dllconnectionsOfComponents[i].dllconnections[a].connectedDllconnectors[b]) && (pair[1] == dllconnectionsOfComponents[i].dllconnections[a].dllconector))
                                    {
                                        alreadyThere = true;
                                    }
                                }

                                if (alreadyThere == false)
                                {
                                    Circuit.Lead[] newPair = new Circuit.Lead[2];
                                    newPair[0] = dllconnectionsOfComponents[i].dllconnections[a].dllconector;
                                    newPair[1] = dllconnectionsOfComponents[i].dllconnections[a].connectedDllconnectors[b];
                                    alreadyConnected.Add(newPair);
                                    //Debug.Log("Komponent cislo: " + i + " konektor ku ktoremu sa pripaja: " + a + " pripajany konektor: " + b + " cislo conections: " + _countOfMadeConnections);
                                    newSimulation.Connect(dllconnectionsOfComponents[i].dllconnections[a].dllconector, dllconnectionsOfComponents[i].dllconnections[a].connectedDllconnectors[b]);
                                    _countOfMadeConnections += 1;
                                }
                            }
                        }
                    }
                }

                Debug.Log("Simulation complete with " + _countOfMadeConnections + " connections");
                Debug.Log("Sim Elements count " + newSimulation.elements.Count);
            }
        }
        _listOfNetworks.Clear();
    }