Exemplo n.º 1
0
		public SqlTableSource(ISqlTableSource source, string? alias, IEnumerable<SqlJoinedTable> joins, IEnumerable<ISqlExpression[]>? uniqueKeys)
		{
			Source = source ?? throw new ArgumentNullException(nameof(source));
			_alias = alias;

			if (joins != null)
				Joins.AddRange(joins);

			if (uniqueKeys != null)
				UniqueKeys.AddRange(uniqueKeys);
		}
Exemplo n.º 2
0
        /// <summary>
        /// 构建 Select 语句信息
        /// </summary>
        /// <param name="mainTable">表</param>
        public SelectStatement(ITable mainTable)
        {
            Table = mainTable;

            Columns   = new SelectColumns();
            Joins     = new Joins();
            Where     = new Conditions();
            OrderBies = new OrderBies();
            GroupBies = new GroupBies();
            Having    = new Conditions();
        }
Exemplo n.º 3
0
        public SqlBuilder AddJoin(SqlSourceJoinType type, string source)
        {
            if (Joins == null)
            {
                Joins = new List <SqlSourceJoin>();
            }

            Joins.Add(new SqlSourceJoin(type, source));

            return(this);
        }
Exemplo n.º 4
0
        public SelectStatement Join(string parentColumn, SelectStatement selectStatement, string alias, string column)
        {
            GetJoinAndColumnDef(parentColumn, (parentJoin, parentColumnDef) =>
                                GetSelectColumn(column, selectStatement, selectColumn =>
            {
                Join join = new Join(parentJoin, parentColumnDef, selectColumn.ColumnDef, alias, selectStatement);
                Joins.Add(@join);
            }));

            return(this);
        }
Exemplo n.º 5
0
 public bool IsTrivial()
 {
     return((WhereExpr == null || WhereExpr.Type == ExprType.EMPTY) &&
            (GroupWhereExpr == null || GroupWhereExpr.Type == ExprType.EMPTY) &&
            !Columns.Any() &&
            !OrderByExprs.Any() &&
            !Joins.Any() &&
            RowsLimit == null &&
            RowsOffset == 0 &&
            !DistinctRecords &&
            !GroupByColumns.Any());
 }
Exemplo n.º 6
0
        ToDBCommand Join(string table, Action <ConditionBuilder> where, Join.JoinType joinType)
        {
            ConditionBuilder whereBuilder = new ConditionBuilder();

            where (whereBuilder);
            Joins.Add(new Join {
                Table = new TableItem {
                    Item = table
                }, On = whereBuilder, TypeOfJoin = joinType
            });
            return(this);
        }
Exemplo n.º 7
0
        private void GetJoinAndColumnDef(string column, Action <Join, ColumnDef> action)
        {
            string alias = null;
            string name;

            if (column.Contains("."))
            {
                alias = column.Split('.')[0];
                name  = column.Split('.')[1];
            }
            else
            {
                name = column;

                var allColumnDefs = _builder.ColumnDefs
                                    .Join(Joins, j => j.ObjectDef, cd => cd.ObjectDef, (cd, j) => new { Join = j, ColumnDef = cd })
                                    .Where(item => item.ColumnDef.Name == name)
                                    .ToList();

                if (allColumnDefs.Count == 1)
                {
                    alias = allColumnDefs[0].Join.Alias;
                }
                else if (allColumnDefs.Count(item => item.ColumnDef.IsPrimaryKey) == 1)
                {
                    alias = allColumnDefs.Single(item => item.ColumnDef.IsPrimaryKey).Join.Alias;
                }
            }

            Join      join      = Joins.Single(item => item.Alias == alias);
            ColumnDef columnDef = null;

            if (join.SelectStatement != null)
            {
                SelectColumn selectColumn = join.SelectStatement.SelectColumns.Single(item => item.Alias == name);

                if (selectColumn.AggregateColumnDef != null)
                {
                    columnDef = selectColumn.AggregateColumnDef;
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            else
            {
                columnDef = _builder.ColumnDefs.Single(item => item.ObjectDef == join.ObjectDef && item.Name == name);
            }

            action(join, columnDef);
        }
        public override IQuery <T> JoinOn <TRightEntity>(System.Linq.Expressions.Expression <Func <T, TRightEntity, bool> > joinExpression, JoinType joinType = JoinType.Inner)
        {
            if (joinExpression == null)
            {
                throw new ArgumentNullException("Join expression can't be null.");
            }

            var sqlServerJoin = new SqlServerJoin <T, TRightEntity>(this, new SqlServerSelectQuery <TRightEntity>());

            Joins.Enqueue(sqlServerJoin);

            return(sqlServerJoin.On(joinExpression));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates a new Join clause statement fot the current query object
        /// </summary>
        protected JoinClause Join(JoinType type, string joinTable)
        {
            // Add clause to list of joins
            var table  = new TableIndentifier(joinTable, null);
            var clause = new JoinClause(this, type, table);

            Joins.Add(clause);

            // Add the table to the tables list, and then reset the LastInsertIndex
            Tables.Add(table);
            NextAliasIndex = 0;
            return(clause);
        }
Exemplo n.º 10
0
        public SqlTable(SqlTable table, IEnumerable <SqlField> fields, IEnumerable <Join> joins)
            : this(table.MappingSchema)
        {
            _alias        = table._alias;
            _database     = table._database;
            _owner        = table._owner;
            _name         = table._name;
            _physicalName = table._physicalName;
            _objectType   = table._objectType;

            Fields.AddRange(fields);
            Joins.AddRange(joins);
        }
Exemplo n.º 11
0
        protected override Expression VisitMember(MemberExpression node)
        {
            _propertyDepth++;
            var result = base.VisitMember(node);

            _currentFieldMetadata = _currentEntityMetadata.Fields.FirstOrDefault(x => x.Name == node.Member.Name || x.Name == $"FK_{node.Member.Name}_ID");
            if (_currentFieldMetadata == null)
            {
                throw new InvalidOperationException("The property is not part of entity.");
            }

            if (_currentFieldMetadata.IsComplexFieldType && !_currentFieldMetadata.Enum && _propertyDepth > 1)
            {
                _currentEntityMetadata = EntityMetadataResolver.EntityMetadata.FirstOrDefault(x => x.Name == _currentFieldMetadata.FieldType);
                _propertyPath          = string.IsNullOrWhiteSpace(_propertyPath) ? node.Member.Name : $"{_propertyPath}.{node.Member.Name}";

                TableJoin tableJoin;

                //check if we already have a join
                if (_propertyJoinMapping.ContainsKey(_propertyPath))
                {
                    tableJoin = _propertyJoinMapping[_propertyPath];
                }
                else
                {
                    tableJoin = new TableJoin(_currentEntityMetadata.Table, GetTableAlias(), _currentAlias, _currentFieldMetadata.Name, !_currentFieldMetadata.Mandatory);
                    _propertyJoinMapping.Add(_propertyPath, tableJoin);

                    Joins.Add(tableJoin);
                }

                _currentAlias = tableJoin.Alias;
                _propertyDepth--;
            }
            else
            {
                if (!_isOrdering)
                {
                    EmitSql($"{_currentAlias}.{_currentFieldMetadata.Name}");
                }
                else
                {
                    _orderProperty = _currentFieldMetadata.Name;
                }

                _propertyPath  = string.Empty;
                _propertyDepth = 0;
            }

            return(result);
        }
Exemplo n.º 12
0
        public QueryDefinition GenerateQuery()
        {
            var query = new QueryDefinition(RecordType);

            query.Distinct = true;
            if (IsQuickFind)
            {
                query.IsQuickFind   = true;
                query.QuickFindText = QuickFindText;
                if (!string.IsNullOrWhiteSpace(QuickFindText))
                {
                    var quickFindFields = RecordService.GetStringQuickfindFields(RecordType);
                    //there was a bug in SDK when querying on queues
                    //which required adding our or filter as a child filter
                    //rather than adding in the root filter
                    var nestedFilter = new Filter();
                    nestedFilter.ConditionOperator = FilterOperator.Or;
                    nestedFilter.Conditions.AddRange(quickFindFields.Select(f => new Condition(f, ConditionType.BeginsWith, QuickFindText)));
                    query.RootFilter.SubFilters.Add(nestedFilter);
                }
            }
            else
            {
                query.RootFilter = FilterConditions.GetAsFilter();
                query.Joins      = Joins.GetAsJoins().ToList();
            }
            var view = DynamicGridViewModel.RecordService.GetView(DynamicGridViewModel.RecordType, DynamicGridViewModel.ViewType);

            query.Sorts = view.Sorts.Where(s => !s.FieldName.Contains(".")).ToList();

            //okay lets add joins for all the columns in referenced types
            if (ExplicitlySelectedColumns != null)
            {
                var linkGroups = ExplicitlySelectedColumns
                                 .Where(c => c.AliasedFieldName != null)
                                 .GroupBy(c => c.AliasedFieldName.Split('.')[0]);
                foreach (var linkGroup in linkGroups)
                {
                    var joinToRecordType = linkGroup.First().AltRecordType;
                    var lookupField      = linkGroup.Key.Substring(0, linkGroup.Key.Length - (joinToRecordType.Length + 1));
                    var join             = new Join(lookupField, joinToRecordType, RecordService.GetPrimaryKey(joinToRecordType));
                    join.JoinType = JoinType.LeftOuter;
                    join.Fields   = linkGroup.Select(lgf => lgf.FieldName);
                    join.Alias    = linkGroup.Key;
                    query.Joins.Add(join);
                }
            }

            return(query);
        }
Exemplo n.º 13
0
    private void SetLine()
    {
        VectorLine.Destroy(ref this.line);
        if (!this.continuous)
        {
            this.fillJoins = false;
        }
        LineType lineType = !this.continuous ? (LineType)1 : (LineType)0;
        Joins    joins    = !this.fillJoins ? (Joins)2 : (Joins)0;

        this.line = new VectorLine("Line", new List <Vector2>(), !this.thickLine ? 2f : 24f, lineType, joins);
        this.line.set_drawTransform(((Component)this).get_transform());
        this.endReached = false;
    }
Exemplo n.º 14
0
        protected virtual void FillJoins(TableKey sourceTable, ColumnInfo column)
        {
            if (!column.Table.Name.Equals(sourceTable, StringComparison.InvariantCultureIgnoreCase) &&
                !column.IsData)
            {
                Joins.AddJoins(sourceTable, column.Table);

                //string joinKey = GetJoinKey ( sourceTable, column.Table.Name ) ;

                //if ( !_joins.ContainsKey ( joinKey ))
                //{
                //    _joins.Add (joinKey, _cachedJoins[joinKey] ) ;
                //}
            }
        }
Exemplo n.º 15
0
        public string ParseCountQueryExpression(Expression expression)
        {
            Visit(expression);
            if (Offset != null && Limit == null)
            {
                Limit = int.MaxValue;
            }

            var command = $"SELECT COUNT({RootTableAlias}.Id) FROM {_sourceEntityMetadata.Table} {RootTableAlias}" + (Joins.Count > 0 ? " " : string.Empty) +
                          string.Join(" ", Joins.Select(x => x.ToString())) + $" {_stringBuilder} {_orderBy}";

            SqlGeneratorManager.SqlEngine.ApplyLimit(ref command, RootTableAlias, Limit, Offset);

            return(command);
        }
Exemplo n.º 16
0
    // Token: 0x06000B04 RID: 2820 RVA: 0x00030FA0 File Offset: 0x0002F3A0
    private void SetLine()
    {
        VectorLine.Destroy(ref this.line);
        if (!this.continuous)
        {
            this.fillJoins = false;
        }
        LineType lineType = (!this.continuous) ? LineType.Discrete : LineType.Continuous;
        Joins    joins    = (!this.fillJoins) ? Joins.None : Joins.Fill;
        int      num      = (!this.thickLine) ? 2 : 24;

        this.line = new VectorLine("Line", new List <Vector2>(), (float)num, lineType, joins);
        this.line.drawTransform = base.transform;
        this.endReached         = false;
    }
Exemplo n.º 17
0
        public Join GetAsJoin()
        {
            var selected = SelectedItem?.Key;

            if (selected == null)
            {
                return(null);
            }
            Join join = new ParsedSelection(selected, RecordType, RecordService).GetAsJoin();

            join.RootFilter = FilterConditions.GetAsFilter();
            var childJoins = Joins != null?Joins.GetAsJoins() : new Join[0];

            join.Joins = childJoins.ToList();
            return(join);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Creates and returns a <see cref="QueryMapDataModel"/> from the current <see cref="QueryMap"/>
        /// </summary>
        /// <returns></returns>
        public QueryMapDataModel ToDataModel() => new QueryMapDataModel()
        {
            Id          = Id,
            DatabaseId  = DatabaseOptions.Id,
            TableNames  = Tables.Select(x => x.TableName).ToArray(),
            Joins       = Joins.Select(x => x.ToDataModel()).ToArray(),
            Color       = Color,
            Description = Description,
            Name        = Name,

            // Set the column maps
            PropertyMaps = PropertyMaps.Select(x => x.ToDataModel()).ToArray(),

            // Set the data grid presenter maps
            DataGridPresenterMaps = DataGridPresenterMaps.Select(x => x.ToDataModel()).ToArray(),
        };
Exemplo n.º 19
0
        public SqlTable(SqlTable table, IEnumerable <SqlField> fields, IEnumerable <Join> joins, ISqlExpression[] tableArguments) : this()
        {
            Alias               = table.Alias;
            Database            = table.Database;
            Owner               = table.Owner;
            Name                = table.Name;
            PhysicalName        = table.PhysicalName;
            ObjectType          = table.ObjectType;
            _sequenceAttributes = table._sequenceAttributes;

            Fields.AddRange(fields);
            Joins.AddRange(joins);

            SqlTableType   = table.SqlTableType;
            TableArguments = tableArguments;
        }
Exemplo n.º 20
0
        ///<inheritdoc/>
        public IJoinQuery <SelectQuery> RightOuterJoin(Table table, IWhereClause clause)
        {
            if (table == null)
            {
                throw new ArgumentNullException(nameof(table), $"{nameof(table)} cannot be null");
            }

            if (clause == null)
            {
                throw new ArgumentNullException(nameof(clause), $"{nameof(clause)} cannot be null");
            }

            Joins.Add(new RightOuterJoin(table, clause));

            return(this);
        }
Exemplo n.º 21
0
        private bool ValidateCurrentSearch()
        {
            var result = true;

            if (!IsQuickFind)
            {
                result = FilterConditions.Validate();
                var joinValidate = Joins.Validate();
                if (!joinValidate)
                {
                    result = false;
                }
            }

            return(result);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Parses Joins property //(1,and);(2,or) and returns Field Id, Join Type list
        /// </summary>
        /// <returns></returns>
        public List <Tuple <int, string> > GetJoins()
        {
            //(1,and);(2,or)
            List <Tuple <int, string> > lst = new List <Tuple <int, string> >();
            var parts = Joins.Split(';');

            foreach (var part in parts)
            {
                var pp = part.Split(',');
                pp[0] = pp[0].Replace("(", "").Trim();
                pp[1] = pp[1].Replace(")", "").Trim();

                lst.Add(Tuple.Create(int.Parse(pp[0]), pp[1]));
            }

            return(lst);
        }
Exemplo n.º 23
0
        private bool IsJoinRequired(Join join)
        {
            //are any of the select query columns for this join Visible or Ordered
            bool selectColumns = SelectColumns
                                 .Any(item => (item.Join == join || (item.DependentOnAliases != null && item.DependentOnAliases.Contains(join.Alias))) &&
                                      (item.IsVisible || item.OrderByIndex != 0));

            bool whereColumns = WhereColumns.Any(item => item.Join == join);


            //are any of the sub joins required
            bool subJoinsRequired = Joins
                                    .Where(item => item.ParentJoin == join)
                                    .Any(IsJoinRequired);

            return(selectColumns || whereColumns || subJoinsRequired);
        }
Exemplo n.º 24
0
        static void Main(string[] args)
        {
            var menuOption = string.Empty;

            while (menuOption != "6")
            {  //Add menu
                Console.WriteLine("Menu");
                Console.WriteLine("1. Insert");
                Console.WriteLine("2. Update");
                Console.WriteLine("3. Read User");
                Console.WriteLine("4. Delete User");
                Console.WriteLine("5. Joins ");
                Console.WriteLine("6. Exit");
                menuOption = Console.ReadLine();
                //navigate menu options
                switch (menuOption)
                {
                case "1":
                    AddUser();
                    break;

                case "2":
                    UpdateUser();
                    break;

                case "3":
                    ReadUser();
                    break;

                case "4":
                    DeleteUser();
                    break;

                case "5":
                    //Calling a method from Join Class
                    Joins j = new Joins();
                    j.Join();
                    break;

                default:
                    break;
                }
            }
            Exit();
        }
Exemplo n.º 25
0
        public SelectStatement Join(string parentAlias, string primaryObject, string alias)
        {
            /*
             * usage: .CreateSelect("core.ProductType", "pt").Join("pt", "core.Product", "p")
             *
             * joins the primary key of pt.ProductTypeId to the foreigh key of core.Product that references core.ProductType
             */
            Join parentJoin = Joins.Single(item => item.Alias == parentAlias);

            ObjectDef objectDef = _builder.ObjectDefs.Single(item => item.FullName == primaryObject);

            ColumnDef columnDef = _builder.ColumnDefs.Single(item => item.ObjectDef == objectDef && item.ReferencedObject == parentJoin.ObjectDef);

            Join join = new Join(parentJoin, parentJoin.ObjectDef.PrimayKeyColumn, columnDef, alias);

            Joins.Add(join);

            return(this);
        }
Exemplo n.º 26
0
        public SelectStatement Join(string foreignKeyColumn, string alias)
        {
            /*
             * usage: .CreateSelect("core.Product", "p").Join("p.ProductTypeId", "pt")
             *
             * joins the foreign key p.ProductTypeId to the referenced object on its primary key
             */
            GetJoinAndColumnDef(foreignKeyColumn, (parentJoin, parentColumnDef) =>
            {
                ObjectDef objectDef = parentColumnDef.ReferencedObject;
                ColumnDef columnDef = objectDef.PrimayKeyColumn;

                Join join = new Join(parentJoin, parentColumnDef, columnDef, alias);

                Joins.Add(join);
            });

            return(this);
        }
Exemplo n.º 27
0
        public virtual string GetQueryText
        (
            TableKey sourceTable,
            IQueryOptions options    = null,
            ISortingStrategy sorting = null
        )
        {
            if ((Returns == null || Returns.Count == 0))
            {
                throw new InvalidOperationException("No columns has been processed.");
            }

            string selectText = string.Join(",", Returns);
            string joinsText  = string.Join(" ", Joins.ToString( ));
            string whereText  = string.Join(" AND ", Conditions);

            if (string.IsNullOrWhiteSpace(joinsText))
            {
                joinsText = "";
            }

            if (string.IsNullOrWhiteSpace(whereText))
            {
                whereText = "";
            }
            else
            {
                whereText = " AND " + whereText;
            }

            StringBuilder queryBuilder = new StringBuilder( );


            queryBuilder.AppendFormat(SqlQueries.Select_Command_Formatted, selectText, sourceTable, joinsText, whereText);

            if (null != sorting && !string.IsNullOrWhiteSpace(sorting.SortBy))
            {
                queryBuilder.Append(" ORDER BY " + sorting.SortBy + " " + ((sorting.Direction == SortingDirection.DESC) ? "DESC" : "ASC"));
            }

            return(queryBuilder.ToString( ));
        }
Exemplo n.º 28
0
        public SqlTable(MappingSchema mappingSchema, SqlTable table)
            : this(mappingSchema)
        {
            _alias        = table._alias;
            _database     = table._database;
            _owner        = table._owner;
            _name         = table._name;
            _physicalName = table._physicalName;
            _objectType   = table._objectType;

            foreach (var field in table.Fields.Values)
            {
                Fields.Add(new SqlField(field));
            }

            foreach (var join in table.Joins)
            {
                Joins.Add(join.Clone());
            }
        }
Exemplo n.º 29
0
        public ActionResult JoinTrip(int pTripId)
        {
            Joins joins = new Joins(ConnectedUser.Id, pTripId);

            string data;

            if (!DbContext.Joins.Any(x => x.UserId == ConnectedUser.Id && x.TripId == pTripId))
            {
                DbContext.Joins.Add(joins);
                DbContext.SaveChanges();

                data = "Joined";
            }
            else
            {
                data = "Already joined";
            }

            return(Json(data, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// Traverses the join path till it reached the join that's the root of the chained joins
        /// that end with the specified <paramref name="joinMap"/>
        /// </summary>
        /// <param name="joinMap">The join map</param>
        /// <returns></returns>
        private IEnumerable <JoinMap> ComputePath(JoinMap joinMap)
        {
            // Declare the result
            var result = new List <JoinMap>();

            // Declare the current map
            var current = joinMap;

            while (current != null)
            {
                result.Add(current);

                current = Joins.FirstOrDefault(x => x.ReferencedTable == current.Table);
            }

            // Invert the list
            result.Reverse();

            // Return the result
            return(result);
        }
Exemplo n.º 31
0
	protected void SetupLine (string lineName, Material useMaterial, float width, LineType lineType, Joins joins, bool use2D, bool usePoints, int count) {	
		m_continuous = (lineType == LineType.Continuous);
		m_is2D = use2D;
		m_isPoints = usePoints;
		if (joins == Joins.Fill && !m_continuous) {
			Debug.LogError ("VectorLine: Must use LineType.Continuous if using Joins.Fill for \"" + lineName + "\"");
			return;
		}
		if ( (m_is2D && m_points2 == null) || (!m_is2D && m_points3 == null) ) {
			Debug.LogError ("VectorLine: the points array is null for \"" + lineName + "\"");
			return;
		}
		m_pointsCount = count;
		name = lineName;
		if (!CheckPointCount (count)) return;
		
		m_maxWeldDistance = (width*2) * (width*2);
		m_joins = joins;
		
		if (useMaterial == null) {
			if (defaultMaterial == null) {
				defaultMaterial = new Material(Shader.Find ("UI/Default"));
			}
			m_material = defaultMaterial;
		}
		else {
			m_material = useMaterial;
		}
		
		if (_canvas == null) {
			SetCanvas();
		}
		m_vectorObject = new GameObject(name);
		m_vectorObject.transform.SetParent (_canvas.transform, false);
		m_on2DCanvas = true;
		m_canvasRenderer = m_vectorObject.AddComponent<CanvasRenderer>();
		m_canvasRenderer.SetMaterial (m_material, null);
		m_rectTransform = m_vectorObject.AddComponent<RectTransform>();
		SetupTransform (m_rectTransform);
		
		if (!SetVertexCount()) return;
		
		m_UIVertices = new UIVertex[m_vertexCount];
		SetUVs (0, MaxSegmentIndex());
		color = Color.white;
		m_lineWidths = new float[1];
		m_lineWidths[0] = width * .5f;
		if (!m_is2D) {
			m_screenPoints = new Vector3[m_vertexCount];
		}
		m_drawStart = 0;
		m_drawEnd = m_pointsCount-1;
		
		if (joins == Joins.Fill) {
			SetupFillObject();
		}
	}
Exemplo n.º 32
0
	public VectorLine (string lineName, List<Vector2> linePoints, Material lineMaterial, float width, LineType lineType, Joins joins) {
		m_points2 = new List<Vector2>(linePoints);
		SetupLine (lineName, lineMaterial, width, lineType, joins, true, false, m_points2.Count);
	}
Exemplo n.º 33
0
	public VectorLine (string lineName, Vector2[] linePoints, Color[] colors, Material lineMaterial, float width, float cap, int depth, LineType lineType, Joins joins) {
		points2 = linePoints;
		SetupMesh (ref lineName, lineMaterial, colors, ref width, cap, depth, lineType, joins, true, false);
	}
Exemplo n.º 34
0
	public VectorLine (string lineName, Vector3[] linePoints, Color color, Material lineMaterial, float width, int depth, LineType lineType, Joins joins) {
		points3 = linePoints;
		Color[] colors = SetColor(color, lineType, linePoints.Length, false);
		SetupMesh (ref lineName, lineMaterial, colors, ref width, 0.0f, depth, lineType, joins, false, false);
	}
Exemplo n.º 35
0
	public VectorLine (string lineName, Vector3[] linePoints, Material lineMaterial, float width, int depth, LineType lineType, Joins joins) {
		points3 = linePoints;
		SetupMesh (ref lineName, lineMaterial, null, ref width, 0.0f, depth, lineType, joins, false, false);
	}
Exemplo n.º 36
0
	protected void SetupMesh (ref string lineName, Material useMaterial, Color[] colors, ref float width, float cap, int depth, LineType lineType, Joins joins, bool use2Dlines, bool usePoints) {
		m_fillJoins = (joins == Joins.Fill? true : false);
		m_continuousLine = (lineType == LineType.Continuous? true : false);
		if (m_fillJoins && !continuousLine) {
			Debug.LogError("VectorLine: Must use LineType.Continuous if using Joins.Fill for \"" + lineName + "\"");
			return;
		}
		
		int pointsLength = use2Dlines? points2.Length : points3.Length;
		if ( (use2Dlines && points2 == null) || (!use2Dlines && points3 == null) ) {
			Debug.LogError("VectorLine: the points array is null for \"" + lineName + "\"");
			return;
		}
		if (!usePoints && pointsLength < 2) {
			Debug.LogError("The points array must contain at least two points");
			return;
		}
		if (!continuousLine && pointsLength%2 != 0) {
			Debug.LogError("VectorLine: Must have an even points array length for \"" + lineName + "\" when using LineType.Discrete");
			return;
		}
		
		
		lineWidth = width;
		lineWidths = new float[1];
		lineWidths[0] = lineWidth * .5f;
		lineDepth = Mathf.Clamp(depth, 0, 100);
		capLength = cap;
		m_isPoints = usePoints;
		bool useSegmentColors = (colors != null? true : false);
		
		if (!usePoints) {
			if (continuousLine) {
				if (useSegmentColors && colors.Length != pointsLength-1) {
					Debug.LogWarning("VectorLine: Length of color array for \"" + lineName + "\" must be length of points array minus one...disabling segment colors");
					useSegmentColors = false;
				}
			}
			else {
				if (useSegmentColors && colors.Length != pointsLength/2) {
					Debug.LogWarning("VectorLine: Length of color array for \"" + lineName + "\" must be exactly half the length of points array...disabling segment colors");
					useSegmentColors = false;
				}
			}
		}
		else {
			if (useSegmentColors && colors.Length != pointsLength) {
				Debug.LogWarning("VectorLine: Length of color array for \"" + lineName + "\" must be the same length as the points array...disabling segment colors");
				useSegmentColors = false;
			}
		}
		
		if (useMaterial == null) {
			if (VectorMaterial.defaultLineMaterial == null) {
				VectorMaterial.defaultLineMaterial = new Material("Shader \"Vertex Colors/Alpha\" {SubShader {Cull Off ZWrite On Blend SrcAlpha OneMinusSrcAlpha Pass {BindChannels {Bind \"Color\", color Bind \"Vertex\", vertex}}}}");
			}
			useMaterial = VectorMaterial.defaultLineMaterial;
		}
	
		mesh = new Mesh();
		mesh.name = lineName;
		vectorObject = new GameObject("Vector "+lineName, typeof(MeshRenderer));
		vectorObject.layer = Vector.vectorLayer;
		meshFilter = (MeshFilter)vectorObject.AddComponent(typeof(MeshFilter));
		vectorObject.renderer.material = useMaterial;
		meshFilter.mesh = mesh;		
		BuildMesh (pointsLength, use2Dlines, useSegmentColors, colors);
	}
Exemplo n.º 37
0
	protected void SetupMesh (ref string lineName, Material useMaterial, Color[] colors, ref float width, LineType lineType, Joins joins, bool use2Dlines, bool usePoints) {
		m_continuous = (lineType == LineType.Continuous);
		m_is2D = use2Dlines;
		if (joins == Joins.Fill && !m_continuous) {
			LogError ("VectorLine: Must use LineType.Continuous if using Joins.Fill for \"" + lineName + "\"");
			return;
		}
		if ( (m_is2D && points2 == null) || (!m_is2D && points3 == null) ) {
			LogError ("VectorLine: the points array is null for \"" + lineName + "\"");
			return;
		}
		if (colors == null) {
			LogError ("Vectorline: the colors array is null for \"" + lineName + "\"");
			return;
		}
		m_pointsLength = m_is2D? points2.Length : points3.Length;
		if (!usePoints && m_pointsLength < 2) {
			LogError ("The points array must contain at least two points");
			return;
		}
		if (!m_continuous && m_pointsLength%2 != 0) {
			LogError ("VectorLine: Must have an even points array length for \"" + lineName + "\" when using LineType.Discrete");
			return;
		}
		
		m_maxWeldDistance = (width*2) * (width*2);
		m_drawEnd = m_pointsLength;
		m_lineWidths = new float[1];
		m_lineWidths[0] = width * .5f;
		m_isPoints = usePoints;
		m_joins = joins;
		bool useSegmentColors = true;
		int colorsLength = 0;
		if (width == 1.0f && ( (m_isPoints && m_useMeshPoints) || (!m_isPoints && m_useMeshLines) ) ) {
			m_1pixelLine = true;
		}
		
		if (!usePoints) {
			if (m_continuous) {
				if (colors.Length != m_pointsLength-1) {
					Debug.LogWarning ("VectorLine: Length of color array for \"" + lineName + "\" must be length of points array minus one");
					useSegmentColors = false;
					colorsLength = m_pointsLength-1;
				}
			}
			else {
				if (colors.Length != m_pointsLength/2) {
					Debug.LogWarning ("VectorLine: Length of color array for \"" + lineName + "\" must be exactly half the length of points array");
					useSegmentColors = false;
					colorsLength = m_pointsLength/2;
				}
			}
		}
		else {
			if (colors.Length != m_pointsLength) {
				Debug.LogWarning ("VectorLine: Length of color array for \"" + lineName + "\" must be the same length as the points array");
				useSegmentColors = false;
				colorsLength = m_pointsLength;
			}
		}
		if (!useSegmentColors) {
			colors = new Color[colorsLength];
			for (int i = 0; i < colorsLength; i++) {
				colors[i] = Color.white;
			}
		}
		
		if (useMaterial == null) {
			if (defaultMaterial == null) {
				defaultMaterial = new Material("Shader \"Vertex Colors/Alpha\" {Category{Tags {\"Queue\"=\"Transparent\" \"IgnoreProjector\"=\"True\" \"RenderType\"=\"Transparent\"}SubShader {Cull Off ZWrite On Blend SrcAlpha OneMinusSrcAlpha Pass {BindChannels {Bind \"Color\", color Bind \"Vertex\", vertex}}}}}");
			}
			m_material = defaultMaterial;
		}
		else {
			m_material = useMaterial;
		}
	
		m_vectorObject = new GameObject("Vector "+lineName, typeof(MeshRenderer));
		m_vectorObject.layer = vectorLayer;
		m_vectorObject.renderer.material = m_material;
		m_mesh = new Mesh();
		m_mesh.name = lineName;
		m_meshFilter = (MeshFilter)m_vectorObject.AddComponent(typeof(MeshFilter));
		m_meshFilter.mesh = m_mesh;		
		name = lineName;
		m_meshRenderMethodSet = true;
		BuildMesh (colors);
	}
Exemplo n.º 38
0
	public VectorLine (string lineName, Vector2[] linePoints, Material lineMaterial, float width, LineType lineType, Joins joins) {
		points2 = linePoints;
		Color[] colors = SetColor(Color.white, lineType, linePoints.Length, false);
		SetupMesh (ref lineName, lineMaterial, colors, ref width, lineType, joins, true, false);
	}
Exemplo n.º 39
0
	public VectorLine (string lineName, Vector3[] linePoints, Color[] colors, Material lineMaterial, float width, LineType lineType, Joins joins) {
		points3 = linePoints;
		SetupMesh (ref lineName, lineMaterial, colors, ref width, lineType, joins, false, false);
	}
Exemplo n.º 40
0
	public static void SetLineParameters (Color color, Material material, float width, float capLength, int depth, LineType lineType, Joins joins) {
		defaultLineColor = color;
		defaultLineMaterial = material;
		defaultLineWidth = width;
		defaultLineDepth = depth;
		defaultCapLength = capLength;
		defaultLineType = lineType;
		defaultJoins = joins;
		defaultsSet = true;
	}
Exemplo n.º 41
0
 public VectorLine(string lineName, List<Vector3> linePoints, Material lineMaterial, float width, LineType lineType, Joins joins)
 {
     m_points3 = linePoints;
     SetupLine (lineName, lineMaterial, width, lineType, joins, false, false, m_points3.Count);
 }
Exemplo n.º 42
0
	public VectorLine (string lineName, Vector2[] linePoints, Material lineMaterial, float width, LineType lineType, Joins joins) {
		points2 = linePoints;
		SetupMesh (ref lineName, lineMaterial, null, ref width, lineType, joins, true, false);
	}
Exemplo n.º 43
0
 public static void SetLineParameters(Color color, Material mat, float width, float cap, int depth, LineType thisLineType, Joins thisJoins)
 {
     lineColor = color;
     lineMaterial = mat;
     lineWidth = width;
     lineDepth = depth;
     capLength = cap;
     lineType = thisLineType;
     joins = thisJoins;
     set = true;
 }
Exemplo n.º 44
0
 public VectorLine(string lineName, List<Vector2> linePoints, float width, LineType lineType, Joins joins, Transform parent)
 {
     m_points2 = new List<Vector2>(linePoints);
     SetupLine(lineName, null, width, lineType, joins, true, false, m_points2.Count, parent);
 }